mirror of
https://github.com/brl/mutter.git
synced 2025-03-03 11:58:09 +00:00
Removes Cogl from the repository
Cogl has now been split out into a standalone project with a separate repository at git://git.gnome.org/cogl. From now on the Clutter build will now simply look for a cogl-1.0 pkg-config file to find a suitable Cogl library to link against at build time.
This commit is contained in:
parent
00f2a39ac5
commit
223e14811c
46
.gitignore
vendored
46
.gitignore
vendored
@ -22,15 +22,8 @@ stamp-marshal
|
||||
/clutter/clutter-version.h
|
||||
/clutter/gcov-report.txt
|
||||
/clutter/clutter-json.h
|
||||
/clutter/cogl/cogl/cogl-defines.h
|
||||
/clutter/cogl/cogl/cogl-enum-types.[ch]
|
||||
/clutter/cogl/cogl/driver/gl/cogl-defines.h
|
||||
/clutter/cogl/cogl/driver/gles/cogl-defines.h
|
||||
/clutter/cogl/cogl/cogl-fixed-vertex-shader.[ch]
|
||||
/clutter/cogl/cogl/cogl-fixed-fragment-shader.[ch]
|
||||
/clutter/egl/clutter-cex100.h
|
||||
/build/autotools/*.m4
|
||||
/clutter/cogl/build/autotools/*.m4
|
||||
!/build/autotools/introspection.m4
|
||||
!/build/autotools/as-linguas.m4
|
||||
!/build/autotools/as-compiler-flag.m4
|
||||
@ -61,32 +54,6 @@ doc/reference/clutter/clutter.signals
|
||||
doc/reference/clutter/clutter-docs.xml
|
||||
doc/reference/clutter/*.stamp
|
||||
doc/reference/clutter/*.bak
|
||||
doc/reference/cogl/cogl-*.txt
|
||||
!/doc/reference/cogl/cogl-sections.txt
|
||||
doc/reference/cogl/html
|
||||
doc/reference/cogl/tmpl
|
||||
doc/reference/cogl/xml
|
||||
doc/reference/cogl/cogl.args
|
||||
doc/reference/cogl/cogl.hierarchy
|
||||
doc/reference/cogl/cogl.interfaces
|
||||
doc/reference/cogl/cogl.prerequisites
|
||||
doc/reference/cogl/cogl.signals
|
||||
doc/reference/cogl/cogl-docs.xml
|
||||
doc/reference/cogl/*.stamp
|
||||
doc/reference/cogl/*.bak
|
||||
doc/reference/cogl-2.0/cogl-*.txt
|
||||
!/doc/reference/cogl-2.0/cogl-sections.txt
|
||||
doc/reference/cogl-2.0/html
|
||||
doc/reference/cogl-2.0/tmpl
|
||||
doc/reference/cogl-2.0/xml
|
||||
doc/reference/cogl-2.0/cogl.args
|
||||
doc/reference/cogl-2.0/cogl.hierarchy
|
||||
doc/reference/cogl-2.0/cogl.interfaces
|
||||
doc/reference/cogl-2.0/cogl.prerequisites
|
||||
doc/reference/cogl-2.0/cogl.signals
|
||||
doc/reference/cogl-2.0/cogl-docs.xml
|
||||
doc/reference/cogl-2.0/*.stamp
|
||||
doc/reference/cogl-2.0/*.bak
|
||||
doc/reference/cally/cally-*.txt
|
||||
!/doc/reference/cally/cally-sections.txt
|
||||
doc/reference/cally/html
|
||||
@ -124,19 +91,6 @@ TAGS
|
||||
/po/remove-potcdate.sin
|
||||
/po/remove-potcdate.sed
|
||||
/po/stamp-po
|
||||
/clutter/cogl/po/POTFILES
|
||||
/clutter/cogl/po/*.gmo
|
||||
/clutter/cogl/po/Makefile.in.in
|
||||
/clutter/cogl/po/Makevars.template
|
||||
/clutter/cogl/po/Rules-quot
|
||||
/clutter/cogl/po/boldquot.sed
|
||||
/clutter/cogl/po/en@boldquot.header
|
||||
/clutter/cogl/po/en@quot.header
|
||||
/clutter/cogl/po/insert-header.sin
|
||||
/clutter/cogl/po/quot.sed
|
||||
/clutter/cogl/po/remove-potcdate.sin
|
||||
/clutter/cogl/po/remove-potcdate.sed
|
||||
/clutter/cogl/po/stamp-po
|
||||
*.swn
|
||||
*.swo
|
||||
*.swp
|
||||
|
35
README.in
35
README.in
@ -10,12 +10,11 @@ REQUIREMENTS
|
||||
Clutter currently requires:
|
||||
|
||||
• GLib ≥ @GLIB_REQ_VERSION@
|
||||
• Cogl ≥ @COGL_REQ_VERSION@
|
||||
• JSON-GLib ≥ @JSON_GLIB_REQ_VERSION@
|
||||
• Atk ≥ @ATK_REQ_VERSION@
|
||||
• Cairo ≥ @CAIRO_REQ_VERSION@
|
||||
• PangoCairo ≥ @PANGO_REQ_VERSION@
|
||||
• OpenGL ≥ 1.3 (or 1.2 + multitexturing), or OpenGL ES 2.0 (or 1.1)
|
||||
• GLX, AGL, WGL or an EGL implementation
|
||||
|
||||
Clutter also has optional dependencies:
|
||||
|
||||
@ -137,21 +136,6 @@ Clutter has additional command line options for the configure script:
|
||||
debugging notes. Only use in extreme performance and/or size
|
||||
optimization cases, though it is strongly discouraged.
|
||||
|
||||
--enable-cogl-debug=[no/minimum/yes]
|
||||
Controls COGL debugging level (default=minimum):
|
||||
|
||||
yes:
|
||||
Support for COGL debugging notes through COGL_DEBUG and
|
||||
error checking for each GL primitive. This is useful mostly
|
||||
to debug COGL itself.
|
||||
|
||||
minimum:
|
||||
Support for COGL debugging notes through COGL_DEBUG. This is
|
||||
the default for developers snapshots.
|
||||
|
||||
no:
|
||||
Disable support for COGL runtime debugging notes.
|
||||
|
||||
--enable-maintainer-flags=[no/yes/error]
|
||||
Use strict compiler flags. This defaults to 'yes' for building from
|
||||
Git to 'no' for tarball releases. If 'error' is used, then -Werror
|
||||
@ -209,23 +193,6 @@ Clutter has additional command line options for the configure script:
|
||||
win32:
|
||||
Microsoft Windows(tm) WGL backend.
|
||||
|
||||
--with-imagebackend=[gdk-pixbuf/quartz/internal]
|
||||
Select the image loading backend used by COGL
|
||||
|
||||
gdk-pixbuf:
|
||||
Depend on gdk-pixbuf-2.0 (default for the glx, eglx,
|
||||
eglnative, win32 flavours and recommended).
|
||||
|
||||
quartz:
|
||||
Depend on CoreGraphics (default for the osx flavour).
|
||||
|
||||
internal:
|
||||
Internal JPEG and PNG loader. Should only be used
|
||||
for testing on new platforms
|
||||
|
||||
--with-gles=[1.1/2.0]
|
||||
Select the GLES version (for EGL backends) (default=1.1)
|
||||
|
||||
See also the INSTALL file generated by autotools for further information.
|
||||
|
||||
VERSIONING
|
||||
|
@ -3,11 +3,6 @@ include $(top_srcdir)/build/autotools/Makefile.am.silent
|
||||
# preamble
|
||||
NULL =
|
||||
|
||||
# we recurse only into Cogl
|
||||
if !USE_SYSTEM_COGL
|
||||
SUBDIRS = cogl
|
||||
endif
|
||||
|
||||
# common definitions
|
||||
CLEANFILES =
|
||||
DISTCLEANFILES =
|
||||
@ -27,14 +22,6 @@ INCLUDES = \
|
||||
-I$(top_builddir)/clutter \
|
||||
$(NULL)
|
||||
|
||||
if !USE_SYSTEM_COGL
|
||||
INCLUDES += \
|
||||
-I$(top_srcdir)/clutter/cogl \
|
||||
-I$(top_srcdir)/clutter/cogl/pango \
|
||||
-I$(top_builddir)/clutter/cogl \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-DCLUTTER_PREFIX=\""$(prefix)"\" \
|
||||
-DCLUTTER_LIBDIR=\""$(libdir)"\" \
|
||||
@ -633,15 +620,6 @@ libclutter_@CLUTTER_SONAME_INFIX@_@CLUTTER_API_VERSION@_la_LIBADD = \
|
||||
libclutter_@CLUTTER_SONAME_INFIX@_@CLUTTER_API_VERSION@_la_DEPENDENCIES = \
|
||||
$(win32_resources)
|
||||
|
||||
if !USE_SYSTEM_COGL
|
||||
libclutter_@CLUTTER_SONAME_INFIX@_@CLUTTER_API_VERSION@_la_LIBADD += \
|
||||
$(top_builddir)/clutter/cogl/cogl/libcogl.la \
|
||||
$(top_builddir)/clutter/cogl/pango/libcoglpango.la
|
||||
libclutter_@CLUTTER_SONAME_INFIX@_@CLUTTER_API_VERSION@_la_DEPENDENCIES += \
|
||||
$(top_builddir)/clutter/cogl/cogl/libcogl.la \
|
||||
$(top_builddir)/clutter/cogl/pango/libcoglpango.la
|
||||
endif
|
||||
|
||||
libclutter_@CLUTTER_SONAME_INFIX@_@CLUTTER_API_VERSION@_la_SOURCES = \
|
||||
$(backend_source_c) \
|
||||
$(backend_source_h) \
|
||||
@ -666,7 +644,7 @@ libclutter_@CLUTTER_SONAME_INFIX@_@CLUTTER_API_VERSION@_la_LDFLAGS = \
|
||||
$(CLUTTER_LT_LDFLAGS) \
|
||||
$(GCOV_LDFLAGS) \
|
||||
-export-dynamic \
|
||||
-export-symbols-regex "^(clutter|cogl|cally).*" \
|
||||
-export-symbols-regex "^(clutter|cally).*" \
|
||||
-rpath $(libdir) \
|
||||
$(win32_resources_ldflag) \
|
||||
$(NULL)
|
||||
@ -689,36 +667,9 @@ Clutter_@CLUTTER_API_VERSION_AM@_gir_SCANNERFLAGS = \
|
||||
--warn-all \
|
||||
--c-include='clutter/clutter.h' \
|
||||
--pkg-export=clutter-@CLUTTER_API_VERSION@
|
||||
if USE_SYSTEM_COGL
|
||||
Clutter_@CLUTTER_API_VERSION_AM@_gir_INCLUDES += Cogl-1.0
|
||||
else
|
||||
Clutter_@CLUTTER_API_VERSION_AM@_gir_LIBS += \
|
||||
$(top_builddir)/clutter/cogl/cogl/libcogl.la \
|
||||
$(top_builddir)/clutter/cogl/pango/libcoglpango.la
|
||||
Clutter_@CLUTTER_API_VERSION_AM@_gir_SCANNERFLAGS += \
|
||||
--include-uninstalled=$(top_builddir)/clutter/cogl/cogl/Cogl-1.0.gir
|
||||
COGL_GIR_DEP=Cogl-1.0.gir
|
||||
endif
|
||||
|
||||
if !USE_SYSTEM_COGL
|
||||
# Cogl.gir is used included into Clutter.gir, so it needs to be built
|
||||
# before the typelib is generated
|
||||
Clutter-@CLUTTER_API_VERSION@.typelib: Cogl-1.0.gir
|
||||
|
||||
# We build Cogl.gir in the cogl/ subdir, but it needs to reference the shared
|
||||
# library that it's built into, so we delay compiling the gir into typelib
|
||||
# until after we've built the shared library. To create the final Cogl.gir
|
||||
# that we compile and install, we transfer the shared-library="" line from
|
||||
# Clutter.gir to Cogl.gir
|
||||
Cogl-1.0.gir: Makefile Clutter-@CLUTTER_API_VERSION@.gir cogl/cogl/Cogl-1.0.gir
|
||||
$(QUIET_GEN) \
|
||||
shlib=`sed -n 's/.*shared-library="\([^"]*\)".*/\1/p' < Clutter-@CLUTTER_API_VERSION@.gir` ; \
|
||||
sed "s/shared-library=\"[^\"]*\"/shared-library=\"$$shlib\"/"< $(top_builddir)/clutter/cogl/cogl/Cogl-1.0.gir > $@
|
||||
|
||||
BUILT_GIRSOURCES += Cogl-1.0.gir
|
||||
endif
|
||||
|
||||
Cally-@CLUTTER_API_VERSION@.gir: Makefile Clutter-@CLUTTER_API_VERSION@.gir $(COGL_GIR_DEP)
|
||||
Cally-@CLUTTER_API_VERSION@.gir: Makefile Clutter-@CLUTTER_API_VERSION@.gir
|
||||
|
||||
Cally_@CLUTTER_API_VERSION_AM@_gir_NAMESPACE = Cally
|
||||
Cally_@CLUTTER_API_VERSION_AM@_gir_VERSION = @CLUTTER_API_VERSION@
|
||||
@ -733,22 +684,13 @@ Cally_@CLUTTER_API_VERSION_AM@_gir_SCANNERFLAGS = \
|
||||
# Note: it's important to pass --include-uninstalled for the Cogl-1.0.gir
|
||||
# before the Clutter gir otherwise g-ir-scanner can get upset as it
|
||||
# immediatly scans the Clutter gir file and may fail to find a Cogl-1.0.gir
|
||||
if USE_SYSTEM_COGL
|
||||
Cally_@CLUTTER_API_VERSION_AM@_gir_SCANNERFLAGS += \
|
||||
--include-uninstalled=$(top_builddir)/clutter/Clutter-@CLUTTER_API_VERSION@.gir
|
||||
else
|
||||
Cally_@CLUTTER_API_VERSION_AM@_gir_LIBS += \
|
||||
$(top_builddir)/clutter/cogl/cogl/libcogl.la \
|
||||
$(top_builddir)/clutter/cogl/pango/libcoglpango.la
|
||||
Cally_@CLUTTER_API_VERSION_AM@_gir_SCANNERFLAGS += \
|
||||
--include-uninstalled=$(top_builddir)/clutter/Cogl-1.0.gir \
|
||||
--include-uninstalled=$(top_builddir)/clutter/Clutter-@CLUTTER_API_VERSION@.gir
|
||||
endif
|
||||
|
||||
INTROSPECTION_GIRS += Cally-@CLUTTER_API_VERSION@.gir
|
||||
|
||||
if SUPPORT_X11
|
||||
ClutterX11-@CLUTTER_API_VERSION@.gir: Makefile Clutter-@CLUTTER_API_VERSION@.gir $(COGL_GIR_DEP)
|
||||
ClutterX11-@CLUTTER_API_VERSION@.gir: Makefile Clutter-@CLUTTER_API_VERSION@.gir
|
||||
|
||||
ClutterX11_@CLUTTER_API_VERSION_AM@_gir_SCANNERFLAGS = \
|
||||
--identifier-prefix=ClutterX11 \
|
||||
@ -763,17 +705,8 @@ ClutterX11_@CLUTTER_API_VERSION_AM@_gir_CFLAGS = $(INCLUDES) $(CLUTTER_CFLAGS) $
|
||||
# Note: it's important to pass --include-uninstalled for the Cogl-1.0.gir
|
||||
# before the Clutter gir otherwise g-ir-scanner can get upset as it
|
||||
# immediatly scans the Clutter gir file and may fail to find a Cogl-1.0.gir
|
||||
if USE_SYSTEM_COGL
|
||||
ClutterX11_@CLUTTER_API_VERSION_AM@_gir_SCANNERFLAGS += \
|
||||
--include-uninstalled=$(top_builddir)/clutter/Clutter-@CLUTTER_API_VERSION@.gir
|
||||
else
|
||||
ClutterX11_@CLUTTER_API_VERSION_AM@_gir_SCANNERFLAGS += \
|
||||
--include-uninstalled=$(top_builddir)/clutter/Cogl-1.0.gir \
|
||||
--include-uninstalled=$(top_builddir)/clutter/Clutter-@CLUTTER_API_VERSION@.gir
|
||||
ClutterX11_@CLUTTER_API_VERSION_AM@_gir_LIBS += \
|
||||
$(top_builddir)/clutter/cogl/cogl/libcogl.la \
|
||||
$(top_builddir)/clutter/cogl/pango/libcoglpango.la
|
||||
endif
|
||||
|
||||
INTROSPECTION_GIRS += ClutterX11-@CLUTTER_API_VERSION@.gir
|
||||
endif # SUPPORT_X11
|
||||
|
@ -110,12 +110,7 @@
|
||||
#include "clutter-version.h" /* For flavour define */
|
||||
|
||||
#include <cogl/cogl.h>
|
||||
|
||||
#ifdef CLUTTER_USING_SYSTEM_COGL
|
||||
#include <cogl/cogl-pango.h>
|
||||
#else
|
||||
#include "pango/cogl-pango.h"
|
||||
#endif
|
||||
|
||||
#include "cally.h" /* For accessibility support */
|
||||
|
||||
|
@ -30,11 +30,7 @@
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
|
||||
#ifdef CLUTTER_USING_SYSTEM_COGL
|
||||
#include <cogl/cogl-pango.h>
|
||||
#else
|
||||
#include "pango/cogl-pango.h"
|
||||
#endif
|
||||
|
||||
#include "clutter-backend.h"
|
||||
#include "clutter-effect.h"
|
||||
|
@ -1,7 +0,0 @@
|
||||
SUBDIRS = cogl pango
|
||||
|
||||
if COGL_STANDALONE_BUILD
|
||||
SUBDIRS += po examples
|
||||
endif
|
||||
|
||||
ACLOCAL_AMFLAGS = -I build/autotools ${ACLOCAL_FLAGS}
|
@ -1,73 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Run this to generate all the initial makefiles, etc.
|
||||
|
||||
srcdir=`dirname $0`
|
||||
test -z "$srcdir" && srcdir=.
|
||||
|
||||
ORIGDIR=`pwd`
|
||||
|
||||
cd $srcdir
|
||||
PROJECT=Cogl
|
||||
TEST_TYPE=-f
|
||||
FILE=cogl/cogl.h
|
||||
|
||||
test $TEST_TYPE $FILE || {
|
||||
echo "You must run this script in the top-level $PROJECT directory"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if automake-1.11 --version < /dev/null > /dev/null 2>&1 ; then
|
||||
AUTOMAKE=automake-1.11
|
||||
ACLOCAL=aclocal-1.11
|
||||
export AUTOMAKE ACLOCAL
|
||||
else
|
||||
echo
|
||||
echo "You must have automake 1.11.x installed to compile $PROJECT
|
||||
ECT."
|
||||
echo "Install the appropriate package for your distribution,"
|
||||
echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(gtkdocize --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "You must have gtk-doc installed to compile $PROJECT."
|
||||
echo "Install the appropriate package for your distribution,"
|
||||
echo "or get the source tarball at http://ftp.gnome.org/pub/GNOME/sources/gtk-doc/"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# NOCONFIGURE is used by gnome-common
|
||||
if test -z "$NOCONFIGURE"; then
|
||||
if test -z "$*"; then
|
||||
echo "I am going to run ./configure with no arguments - if you wish "
|
||||
echo "to pass any to it, please specify them on the $0 command line."
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -z "$ACLOCAL_FLAGS"; then
|
||||
acdir=`$ACLOCAL --print-ac-dir`
|
||||
m4list="glib-2.0.m4"
|
||||
for file in $m4list; do
|
||||
if [ ! -f "$acdir/$file" ]; then
|
||||
echo "WARNING: aclocal's directory is $acdir, but..."
|
||||
echo " no file $acdir/$file"
|
||||
echo " You may see fatal macro warnings below."
|
||||
echo " If these files are installed in /some/dir, set the ACLOCAL_FLAGS "
|
||||
echo " environment variable to \"-I /some/dir\", or install"
|
||||
echo " $acdir/$file."
|
||||
echo ""
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
rm -rf autom4te.cache
|
||||
|
||||
gtkdocize || exit $?
|
||||
autoreconf -vfi || exit $?
|
||||
cd $ORIGDIR || exit $?
|
||||
|
||||
if test -z "$NOCONFIGURE"; then
|
||||
$srcdir/configure $AUTOGEN_CONFIGURE_ARGS "$@" || exit $?
|
||||
echo "Now type 'make' to compile $PROJECT."
|
||||
fi
|
@ -1,51 +0,0 @@
|
||||
# Rules for generating enumeration types using glib-mkenums
|
||||
#
|
||||
# Define:
|
||||
# glib_enum_h = header template file
|
||||
# glib_enum_c = source template file
|
||||
# glib_enum_headers = list of headers to parse
|
||||
#
|
||||
# before including Makefile.am.enums. You will also need to have
|
||||
# the following targets already defined:
|
||||
#
|
||||
# CLEANFILES
|
||||
# DISTCLEANFILES
|
||||
# BUILT_SOURCES
|
||||
# EXTRA_DIST
|
||||
#
|
||||
# Author: Emmanuele Bassi <ebassi@linux.intel.com>
|
||||
|
||||
# Basic sanity checks
|
||||
$(if $(GLIB_MKENUMS),,$(error Need to define GLIB_MKENUMS))
|
||||
|
||||
$(if $(or $(glib_enum_h), \
|
||||
$(glib_enum_c)),, \
|
||||
$(error Need to define glib_enum_h and glib_enum_c))
|
||||
|
||||
$(if $(glib_enum_headers),,$(error Need to define glib_enum_headers))
|
||||
|
||||
enum_tmpl_h=$(addprefix $(srcdir)/, $(glib_enum_h:.h=.h.in))
|
||||
enum_tmpl_c=$(addprefix $(srcdir)/, $(glib_enum_c:.c=.c.in))
|
||||
|
||||
CLEANFILES += stamp-enum-types
|
||||
DISTCLEANFILES += $(glib_enum_h) $(glib_enum_c)
|
||||
BUILT_SOURCES += $(glib_enum_h) $(glib_enum_c)
|
||||
EXTRA_DIST += $(enum_tmpl_h) $(enum_tmpl_c)
|
||||
|
||||
stamp-enum-types: $(glib_enum_headers) $(enum_tmpl_h)
|
||||
$(AM_V_GEN)$(GLIB_MKENUMS) \
|
||||
--template $(enum_tmpl_h) \
|
||||
$(glib_enum_headers) > xgen-eh \
|
||||
&& (cmp -s xgen-eh $(glib_enum_h) || cp -f xgen-eh $(glib_enum_h)) \
|
||||
&& rm -f xgen-eh \
|
||||
&& echo timestamp > $(@F)
|
||||
|
||||
$(glib_enum_h): stamp-enum-types
|
||||
@true
|
||||
|
||||
$(glib_enum_c): $(glib_enum_headers) $(glib_enum_h) $(enum_tmpl_c)
|
||||
$(AM_V_GEN)$(GLIB_MKENUMS) \
|
||||
--template $(enum_tmpl_c) \
|
||||
$(glib_enum_headers) > xgen-ec \
|
||||
&& cp -f xgen-ec $(glib_enum_c) \
|
||||
&& rm -f xgen-ec
|
@ -1,19 +0,0 @@
|
||||
# custom rules for quiet builds
|
||||
|
||||
QUIET_GEN = $(AM_V_GEN)
|
||||
|
||||
QUIET_LN = $(QUIET_LN_$(V))
|
||||
QUIET_LN_ = $(QUIET_LN_$(AM_DEFAULT_VERBOSITY))
|
||||
QUIET_LN_0 = @echo ' LN '$@;
|
||||
|
||||
QUIET_RM = $(QUIET_RM_$(V))
|
||||
QUIET_RM_ = $(QUIET_RM_$(AM_DEFAULT_VERBOSITY))
|
||||
QUIET_RM_0 = @echo ' RM '$@;
|
||||
|
||||
QUIET_SCAN = $(QUIET_SCAN_$(V))
|
||||
QUIET_SCAN_ = $(QUIET_SCAN_$(AM_DEFAULT_VERBOSITY))
|
||||
QUIET_SCAN_0 = @echo ' GISCAN '$@;
|
||||
|
||||
QUIET_COMP = $(QUIET_COMP_$(V))
|
||||
QUIET_COMP_ = $(QUIET_COMP_$(AM_DEFAULT_VERBOSITY))
|
||||
QUIET_COMP_0 = @echo ' GICOMP '$@;
|
@ -1,62 +0,0 @@
|
||||
dnl as-compiler-flag.m4 0.1.0
|
||||
|
||||
dnl autostars m4 macro for detection of compiler flags
|
||||
|
||||
dnl David Schleef <ds@schleef.org>
|
||||
|
||||
dnl $Id: as-compiler-flag.m4,v 1.1 2005/12/15 23:35:19 ds Exp $
|
||||
|
||||
dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
|
||||
dnl Tries to compile with the given CFLAGS.
|
||||
dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
|
||||
dnl and ACTION-IF-NOT-ACCEPTED otherwise.
|
||||
|
||||
AC_DEFUN([AS_COMPILER_FLAG],
|
||||
[
|
||||
AC_MSG_CHECKING([to see if compiler understands $1])
|
||||
|
||||
save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS $1"
|
||||
|
||||
AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
|
||||
CFLAGS="$save_CFLAGS"
|
||||
|
||||
if test "X$flag_ok" = Xyes ; then
|
||||
m4_ifvaln([$2],[$2])
|
||||
true
|
||||
else
|
||||
m4_ifvaln([$3],[$3])
|
||||
true
|
||||
fi
|
||||
AC_MSG_RESULT([$flag_ok])
|
||||
])
|
||||
|
||||
dnl AS_COMPILER_FLAGS(VAR, FLAGS)
|
||||
dnl Tries to compile with the given CFLAGS.
|
||||
|
||||
AC_DEFUN([AS_COMPILER_FLAGS],
|
||||
[
|
||||
list=$2
|
||||
flags_supported=""
|
||||
flags_unsupported=""
|
||||
AC_MSG_CHECKING([for supported compiler flags])
|
||||
for each in $list
|
||||
do
|
||||
save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS $each"
|
||||
AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
|
||||
CFLAGS="$save_CFLAGS"
|
||||
|
||||
if test "X$flag_ok" = Xyes ; then
|
||||
flags_supported="$flags_supported $each"
|
||||
else
|
||||
flags_unsupported="$flags_unsupported $each"
|
||||
fi
|
||||
done
|
||||
AC_MSG_RESULT([$flags_supported])
|
||||
if test "X$flags_unsupported" != X ; then
|
||||
AC_MSG_WARN([unsupported compiler flags: $flags_unsupported])
|
||||
fi
|
||||
$1="$$1 $flags_supported"
|
||||
])
|
||||
|
@ -1,24 +0,0 @@
|
||||
# Set ALL_ALL_LINGUAS based on the .po files present. Optional argument is the
|
||||
# name of the po directory. $podir/LINGUAS.ignore can be used to ignore a
|
||||
# subset of the po files.
|
||||
|
||||
AC_DEFUN([AS_ALL_LINGUAS],
|
||||
[
|
||||
AC_MSG_CHECKING([for linguas])
|
||||
podir="m4_default([$1],[$srcdir/po])"
|
||||
linguas=`cd $podir && ls *.po 2>/dev/null | awk 'BEGIN { FS="."; ORS=" " } { print $[]1 }'`
|
||||
if test -f "$podir/LINGUAS.ignore"; then
|
||||
ALL_LINGUAS="";
|
||||
ignore_linguas=`sed -n -e 's/^\s\+\|\s\+$//g' -e '/^#/b' -e '/\S/!b' \
|
||||
-e 's/\s\+/\n/g' -e p "$podir/LINGUAS.ignore"`;
|
||||
for lang in $linguas; do
|
||||
if ! echo "$ignore_linguas" | grep -q "^${lang}$"; then
|
||||
ALL_LINGUAS="$ALL_LINGUAS $lang";
|
||||
fi;
|
||||
done;
|
||||
else
|
||||
ALL_LINGUAS="$linguas";
|
||||
fi;
|
||||
AC_SUBST([ALL_LINGUAS])
|
||||
AC_MSG_RESULT($ALL_LINGUAS)
|
||||
])
|
@ -1,94 +0,0 @@
|
||||
dnl -*- mode: autoconf -*-
|
||||
dnl Copyright 2009 Johan Dahlin
|
||||
dnl
|
||||
dnl This file is free software; the author(s) gives unlimited
|
||||
dnl permission to copy and/or distribute it, with or without
|
||||
dnl modifications, as long as this notice is preserved.
|
||||
dnl
|
||||
|
||||
# serial 1
|
||||
|
||||
m4_define([_GOBJECT_INTROSPECTION_CHECK_INTERNAL],
|
||||
[
|
||||
AC_BEFORE([AC_PROG_LIBTOOL],[$0])dnl setup libtool first
|
||||
AC_BEFORE([AM_PROG_LIBTOOL],[$0])dnl setup libtool first
|
||||
AC_BEFORE([LT_INIT],[$0])dnl setup libtool first
|
||||
|
||||
dnl enable/disable introspection
|
||||
m4_if([$2], [require],
|
||||
[dnl
|
||||
enable_introspection=yes
|
||||
],[dnl
|
||||
AC_ARG_ENABLE(introspection,
|
||||
AS_HELP_STRING([--enable-introspection[=@<:@no/auto/yes@:>@]],
|
||||
[Enable introspection for this build]),,
|
||||
[enable_introspection=auto])
|
||||
])dnl
|
||||
|
||||
AC_MSG_CHECKING([for gobject-introspection])
|
||||
|
||||
dnl presence/version checking
|
||||
AS_CASE([$enable_introspection],
|
||||
[no], [dnl
|
||||
found_introspection="no (disabled, use --enable-introspection to enable)"
|
||||
],dnl
|
||||
[yes],[dnl
|
||||
PKG_CHECK_EXISTS([gobject-introspection-1.0],,
|
||||
AC_MSG_ERROR([gobject-introspection-1.0 is not installed]))
|
||||
PKG_CHECK_EXISTS([gobject-introspection-1.0 >= $1],
|
||||
found_introspection=yes,
|
||||
AC_MSG_ERROR([You need to have gobject-introspection >= $1 installed to build AC_PACKAGE_NAME]))
|
||||
],dnl
|
||||
[auto],[dnl
|
||||
PKG_CHECK_EXISTS([gobject-introspection-1.0 >= $1], found_introspection=yes, found_introspection=no)
|
||||
],dnl
|
||||
[dnl
|
||||
AC_MSG_ERROR([invalid argument passed to --enable-introspection, should be one of @<:@no/auto/yes@:>@])
|
||||
])dnl
|
||||
|
||||
AC_MSG_RESULT([$found_introspection])
|
||||
|
||||
INTROSPECTION_SCANNER=
|
||||
INTROSPECTION_COMPILER=
|
||||
INTROSPECTION_GENERATE=
|
||||
INTROSPECTION_GIRDIR=
|
||||
INTROSPECTION_TYPELIBDIR=
|
||||
if test "x$found_introspection" = "xyes"; then
|
||||
INTROSPECTION_SCANNER=`$PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0`
|
||||
INTROSPECTION_COMPILER=`$PKG_CONFIG --variable=g_ir_compiler gobject-introspection-1.0`
|
||||
INTROSPECTION_GENERATE=`$PKG_CONFIG --variable=g_ir_generate gobject-introspection-1.0`
|
||||
INTROSPECTION_GIRDIR=`$PKG_CONFIG --variable=girdir gobject-introspection-1.0`
|
||||
INTROSPECTION_TYPELIBDIR="$($PKG_CONFIG --variable=typelibdir gobject-introspection-1.0)"
|
||||
INTROSPECTION_CFLAGS=`$PKG_CONFIG --cflags gobject-introspection-1.0`
|
||||
INTROSPECTION_LIBS=`$PKG_CONFIG --libs gobject-introspection-1.0`
|
||||
INTROSPECTION_MAKEFILE=`$PKG_CONFIG --variable=datadir gobject-introspection-1.0`/gobject-introspection-1.0/Makefile.introspection
|
||||
fi
|
||||
AC_SUBST(INTROSPECTION_SCANNER)
|
||||
AC_SUBST(INTROSPECTION_COMPILER)
|
||||
AC_SUBST(INTROSPECTION_GENERATE)
|
||||
AC_SUBST(INTROSPECTION_GIRDIR)
|
||||
AC_SUBST(INTROSPECTION_TYPELIBDIR)
|
||||
AC_SUBST(INTROSPECTION_CFLAGS)
|
||||
AC_SUBST(INTROSPECTION_LIBS)
|
||||
AC_SUBST(INTROSPECTION_MAKEFILE)
|
||||
|
||||
AM_CONDITIONAL(HAVE_INTROSPECTION, test "x$found_introspection" = "xyes")
|
||||
])
|
||||
|
||||
|
||||
dnl Usage:
|
||||
dnl GOBJECT_INTROSPECTION_CHECK([minimum-g-i-version])
|
||||
|
||||
AC_DEFUN([GOBJECT_INTROSPECTION_CHECK],
|
||||
[
|
||||
_GOBJECT_INTROSPECTION_CHECK_INTERNAL([$1])
|
||||
])
|
||||
|
||||
dnl Usage:
|
||||
dnl GOBJECT_INTROSPECTION_REQUIRE([minimum-g-i-version])
|
||||
|
||||
|
||||
AC_DEFUN([GOBJECT_INTROSPECTION_REQUIRE],
|
||||
[
|
||||
_GOBJECT_INTROSPECTION_CHECK_INTERNAL([$1], [require])
|
||||
])
|
@ -1,419 +0,0 @@
|
||||
include $(top_srcdir)/build/autotools/Makefile.am.silent
|
||||
|
||||
# preamble
|
||||
|
||||
NULL =
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
BUILT_SOURCES =
|
||||
|
||||
EXTRA_DIST =
|
||||
CLEANFILES =
|
||||
DISTCLEANFILES =
|
||||
|
||||
noinst_LTLIBRARIES =
|
||||
lib_LTLIBRARIES =
|
||||
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_builddir) \
|
||||
-I$(srcdir)/tesselator \
|
||||
-I$(srcdir)/winsys \
|
||||
-I$(srcdir)/driver/$(COGL_DRIVER) \
|
||||
$(NULL)
|
||||
|
||||
if COGL_STANDALONE_BUILD
|
||||
INCLUDES += \
|
||||
-I$(top_srcdir)/clutter/cogl \
|
||||
-I$(top_builddir)/clutter/cogl \
|
||||
$(NULL)
|
||||
else
|
||||
INCLUDES += \
|
||||
-I$(top_srcdir)/clutter/cogl \
|
||||
-I$(top_builddir)/clutter/cogl \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-DG_DISABLE_SINGLE_INCLUDES \
|
||||
-DG_DISABLE_DEPRECATED \
|
||||
-DG_LOG_DOMAIN=\"Cogl\" \
|
||||
-DCLUTTER_COMPILATION \
|
||||
$(NULL)
|
||||
|
||||
AM_CFLAGS = $(COGL_DEP_CFLAGS) $(COGL_EXTRA_CFLAGS) $(MAINTAINER_CFLAGS)
|
||||
|
||||
BUILT_SOURCES += cogl-defines.h
|
||||
DISTCLEANFILES += cogl-defines.h
|
||||
EXTRA_DIST += cogl-defines.h.in
|
||||
|
||||
# Note: The cogl-1.0/cogl-gl-1.0 files are essentially for
|
||||
# compatability only. I'm not really sure who could possibly be using
|
||||
# them so we may decide to remove them entirely at some point.
|
||||
pc_files = \
|
||||
cogl-1.0.pc \
|
||||
cogl-gl-1.0.pc
|
||||
|
||||
if COGL_STANDALONE_BUILD
|
||||
pc_files += cogl-$(COGL_API_VERSION).pc
|
||||
endif
|
||||
|
||||
cogl-gl-1.0.pc: cogl-1.0.pc
|
||||
$(QUIET_GEN)cp -f $< $(@F)
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = $(pc_files)
|
||||
|
||||
EXTRA_DIST += cogl.pc.in
|
||||
DISTCLEANFILES += $(pc_files)
|
||||
|
||||
# public headers
|
||||
cogl_public_h = \
|
||||
$(srcdir)/cogl-object.h \
|
||||
$(srcdir)/cogl-bitmap.h \
|
||||
$(srcdir)/cogl-buffer.h \
|
||||
$(srcdir)/cogl-color.h \
|
||||
$(srcdir)/cogl-fixed.h \
|
||||
$(srcdir)/cogl-material-compat.h \
|
||||
$(srcdir)/cogl-pipeline.h \
|
||||
$(srcdir)/cogl-vector.h \
|
||||
$(srcdir)/cogl-matrix.h \
|
||||
$(srcdir)/cogl-offscreen.h \
|
||||
$(srcdir)/cogl-primitives.h \
|
||||
$(srcdir)/cogl-path.h \
|
||||
$(srcdir)/cogl-pixel-array.h \
|
||||
$(srcdir)/cogl-shader.h \
|
||||
$(srcdir)/cogl-texture.h \
|
||||
$(srcdir)/cogl-texture-3d.h \
|
||||
$(srcdir)/cogl-types.h \
|
||||
$(srcdir)/cogl-vertex-buffer.h \
|
||||
$(srcdir)/cogl-index-array.h \
|
||||
$(srcdir)/cogl-vertex-array.h \
|
||||
$(srcdir)/cogl-indices.h \
|
||||
$(srcdir)/cogl-attribute.h \
|
||||
$(srcdir)/cogl-primitive.h \
|
||||
$(srcdir)/cogl-clip-state.h \
|
||||
$(srcdir)/cogl-framebuffer.h \
|
||||
$(srcdir)/cogl-clutter.h \
|
||||
$(srcdir)/cogl.h \
|
||||
$(NULL)
|
||||
|
||||
cogl_experimental_h = \
|
||||
$(srcdir)/cogl-renderer.h \
|
||||
$(srcdir)/cogl-swap-chain.h \
|
||||
$(srcdir)/cogl-onscreen-template.h \
|
||||
$(srcdir)/cogl-display.h \
|
||||
$(srcdir)/cogl-context.h \
|
||||
$(srcdir)/cogl2-path.h \
|
||||
$(srcdir)/cogl2-clip-state.h \
|
||||
$(NULL)
|
||||
|
||||
# driver sources
|
||||
cogl_driver_sources =
|
||||
|
||||
if COGL_DRIVER_GL
|
||||
cogl_driver_sources += \
|
||||
$(srcdir)/driver/gl/cogl-feature-functions-gl.h \
|
||||
$(srcdir)/driver/gl/cogl-gl.c \
|
||||
$(srcdir)/driver/gl/cogl-texture-driver-gl.c \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
if COGL_DRIVER_GLES
|
||||
cogl_driver_sources += \
|
||||
$(srcdir)/driver/gles/cogl-feature-functions-gles.h \
|
||||
$(srcdir)/driver/gles/cogl-gles.c \
|
||||
$(srcdir)/driver/gles/cogl-texture-driver-gles.c \
|
||||
$(NULL)
|
||||
|
||||
endif # COGL_DRIVER_GLES
|
||||
|
||||
# winsys sources, common to all backends
|
||||
cogl_winsys_common_sources = \
|
||||
$(srcdir)/winsys/cogl-winsys-private.h \
|
||||
$(srcdir)/winsys/cogl-winsys.c \
|
||||
$(NULL)
|
||||
|
||||
# tesselator sources
|
||||
cogl_tesselator_sources = \
|
||||
$(srcdir)/tesselator/dict-list.h \
|
||||
$(srcdir)/tesselator/dict.c \
|
||||
$(srcdir)/tesselator/dict.h \
|
||||
$(srcdir)/tesselator/geom.c \
|
||||
$(srcdir)/tesselator/geom.h \
|
||||
$(srcdir)/tesselator/gluos.h \
|
||||
$(srcdir)/tesselator/memalloc.h \
|
||||
$(srcdir)/tesselator/mesh.c \
|
||||
$(srcdir)/tesselator/mesh.h \
|
||||
$(srcdir)/tesselator/normal.c \
|
||||
$(srcdir)/tesselator/normal.h \
|
||||
$(srcdir)/tesselator/priorityq-heap.h \
|
||||
$(srcdir)/tesselator/priorityq-sort.h \
|
||||
$(srcdir)/tesselator/priorityq.c \
|
||||
$(srcdir)/tesselator/priorityq.h \
|
||||
$(srcdir)/tesselator/render.c \
|
||||
$(srcdir)/tesselator/render.h \
|
||||
$(srcdir)/tesselator/sweep.c \
|
||||
$(srcdir)/tesselator/sweep.h \
|
||||
$(srcdir)/tesselator/tess.c \
|
||||
$(srcdir)/tesselator/tess.h \
|
||||
$(srcdir)/tesselator/tesselator.h \
|
||||
$(srcdir)/tesselator/tessmono.c \
|
||||
$(srcdir)/tesselator/tessmono.h \
|
||||
$(srcdir)/tesselator/GL/glu.h \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST += \
|
||||
$(srcdir)/tesselator/README \
|
||||
$(srcdir)/tesselator/priorityq-heap.c \
|
||||
$(NULL)
|
||||
|
||||
# sources
|
||||
cogl_sources_c = \
|
||||
$(cogl_driver_sources) \
|
||||
$(cogl_winsys_common_sources) \
|
||||
$(cogl_tesselator_sources) \
|
||||
$(srcdir)/cogl-private.h \
|
||||
$(srcdir)/cogl-debug.h \
|
||||
$(srcdir)/cogl-debug-options.h \
|
||||
$(srcdir)/cogl-handle.h \
|
||||
$(srcdir)/cogl-context-private.h \
|
||||
$(srcdir)/cogl-context.c \
|
||||
$(srcdir)/cogl-renderer-private.h \
|
||||
$(srcdir)/cogl-renderer.h \
|
||||
$(srcdir)/cogl-renderer.c \
|
||||
$(srcdir)/cogl-swap-chain-private.h \
|
||||
$(srcdir)/cogl-swap-chain.h \
|
||||
$(srcdir)/cogl-swap-chain.c \
|
||||
$(srcdir)/cogl-onscreen-template-private.h \
|
||||
$(srcdir)/cogl-onscreen-template.h \
|
||||
$(srcdir)/cogl-onscreen-template.c \
|
||||
$(srcdir)/cogl-display-private.h \
|
||||
$(srcdir)/cogl-display.h \
|
||||
$(srcdir)/cogl-display.c \
|
||||
$(srcdir)/cogl-internal.h \
|
||||
$(srcdir)/cogl.c \
|
||||
$(srcdir)/cogl-object-private.h \
|
||||
$(srcdir)/cogl-object.h \
|
||||
$(srcdir)/cogl-object.c \
|
||||
$(srcdir)/cogl-util.h \
|
||||
$(srcdir)/cogl-util.c \
|
||||
$(srcdir)/cogl-bitmap-private.h \
|
||||
$(srcdir)/cogl-bitmap.c \
|
||||
$(srcdir)/cogl-bitmap-fallback.c \
|
||||
$(srcdir)/cogl-primitives-private.h \
|
||||
$(srcdir)/cogl-primitives.h \
|
||||
$(srcdir)/cogl-primitives.c \
|
||||
$(srcdir)/cogl-path-private.h \
|
||||
$(srcdir)/cogl-path.h \
|
||||
$(srcdir)/cogl-path.c \
|
||||
$(srcdir)/cogl2-path.h \
|
||||
$(srcdir)/cogl2-path.c \
|
||||
$(srcdir)/cogl-bitmap-pixbuf.c \
|
||||
$(srcdir)/cogl-clip-stack.h \
|
||||
$(srcdir)/cogl-clip-stack.c \
|
||||
$(srcdir)/cogl-clip-state-private.h \
|
||||
$(srcdir)/cogl-clip-state.h \
|
||||
$(srcdir)/cogl-clip-state.c \
|
||||
$(srcdir)/cogl2-clip-state.h \
|
||||
$(srcdir)/cogl2-clip-state.c \
|
||||
$(srcdir)/cogl-feature-private.h \
|
||||
$(srcdir)/cogl-feature-private.c \
|
||||
$(srcdir)/cogl-fixed.c \
|
||||
$(srcdir)/cogl-color-private.h \
|
||||
$(srcdir)/cogl-color.c \
|
||||
$(srcdir)/cogl-buffer-private.h \
|
||||
$(srcdir)/cogl-buffer.c \
|
||||
$(srcdir)/cogl-pixel-array-private.h \
|
||||
$(srcdir)/cogl-pixel-array.c \
|
||||
$(srcdir)/cogl-vertex-buffer-private.h \
|
||||
$(srcdir)/cogl-vertex-buffer.c \
|
||||
$(srcdir)/cogl-index-array-private.h \
|
||||
$(srcdir)/cogl-index-array.c \
|
||||
$(srcdir)/cogl-vertex-array-private.h \
|
||||
$(srcdir)/cogl-vertex-array.c \
|
||||
$(srcdir)/cogl-indices-private.h \
|
||||
$(srcdir)/cogl-indices.c \
|
||||
$(srcdir)/cogl-attribute-private.h \
|
||||
$(srcdir)/cogl-attribute.c \
|
||||
$(srcdir)/cogl-primitive-private.h \
|
||||
$(srcdir)/cogl-primitive.c \
|
||||
$(srcdir)/cogl-matrix.c \
|
||||
$(srcdir)/cogl-vector.c \
|
||||
$(srcdir)/cogl-matrix-private.h \
|
||||
$(srcdir)/cogl-matrix-stack.c \
|
||||
$(srcdir)/cogl-matrix-stack.h \
|
||||
$(srcdir)/cogl-pipeline.c \
|
||||
$(srcdir)/cogl-pipeline-private.h \
|
||||
$(srcdir)/cogl-pipeline-opengl.c \
|
||||
$(srcdir)/cogl-pipeline-opengl-private.h \
|
||||
$(srcdir)/cogl-pipeline-fragend-glsl.c \
|
||||
$(srcdir)/cogl-pipeline-fragend-glsl-private.h \
|
||||
$(srcdir)/cogl-pipeline-fragend-arbfp.c \
|
||||
$(srcdir)/cogl-pipeline-fragend-arbfp-private.h \
|
||||
$(srcdir)/cogl-pipeline-fragend-fixed.c \
|
||||
$(srcdir)/cogl-pipeline-fragend-fixed-private.h \
|
||||
$(srcdir)/cogl-pipeline-vertend-glsl.c \
|
||||
$(srcdir)/cogl-pipeline-vertend-glsl-private.h \
|
||||
$(srcdir)/cogl-pipeline-vertend-fixed.c \
|
||||
$(srcdir)/cogl-pipeline-vertend-fixed-private.h \
|
||||
$(srcdir)/cogl-pipeline-progend-glsl.c \
|
||||
$(srcdir)/cogl-pipeline-progend-glsl-private.h \
|
||||
$(srcdir)/cogl-material-compat.c \
|
||||
$(srcdir)/cogl-program.c \
|
||||
$(srcdir)/cogl-program-private.h \
|
||||
$(srcdir)/cogl-blend-string.c \
|
||||
$(srcdir)/cogl-blend-string.h \
|
||||
$(srcdir)/cogl-debug.c \
|
||||
$(srcdir)/cogl-sub-texture-private.h \
|
||||
$(srcdir)/cogl-texture-private.h \
|
||||
$(srcdir)/cogl-texture-2d-private.h \
|
||||
$(srcdir)/cogl-texture-2d-sliced-private.h \
|
||||
$(srcdir)/cogl-texture-3d-private.h \
|
||||
$(srcdir)/cogl-texture-driver.h \
|
||||
$(srcdir)/cogl-sub-texture.c \
|
||||
$(srcdir)/cogl-texture.c \
|
||||
$(srcdir)/cogl-texture-2d.c \
|
||||
$(srcdir)/cogl-texture-2d-sliced.c \
|
||||
$(srcdir)/cogl-texture-3d.c \
|
||||
$(srcdir)/cogl-texture-rectangle-private.h \
|
||||
$(srcdir)/cogl-texture-rectangle.c \
|
||||
$(srcdir)/cogl-rectangle-map.h \
|
||||
$(srcdir)/cogl-rectangle-map.c \
|
||||
$(srcdir)/cogl-atlas.h \
|
||||
$(srcdir)/cogl-atlas.c \
|
||||
$(srcdir)/cogl-atlas-texture-private.h \
|
||||
$(srcdir)/cogl-atlas-texture.c \
|
||||
$(srcdir)/cogl-blit.h \
|
||||
$(srcdir)/cogl-blit.c \
|
||||
$(srcdir)/cogl-spans.h \
|
||||
$(srcdir)/cogl-spans.c \
|
||||
$(srcdir)/cogl-journal-private.h \
|
||||
$(srcdir)/cogl-journal.c \
|
||||
$(srcdir)/cogl-framebuffer-private.h \
|
||||
$(srcdir)/cogl-framebuffer.c \
|
||||
$(srcdir)/cogl-matrix-mesa.h \
|
||||
$(srcdir)/cogl-matrix-mesa.c \
|
||||
$(srcdir)/cogl-profile.h \
|
||||
$(srcdir)/cogl-profile.c \
|
||||
$(srcdir)/cogl-flags.h \
|
||||
$(srcdir)/cogl-bitmask.h \
|
||||
$(srcdir)/cogl-bitmask.c \
|
||||
$(srcdir)/cogl-shader-boilerplate.h \
|
||||
$(srcdir)/cogl-shader-private.h \
|
||||
$(srcdir)/cogl-shader.c \
|
||||
$(srcdir)/cogl-gtype-private.h \
|
||||
$(srcdir)/cogl-point-in-poly-private.h \
|
||||
$(srcdir)/cogl-point-in-poly.c \
|
||||
$(srcdir)/cogl-clutter.c \
|
||||
$(NULL)
|
||||
|
||||
if SUPPORT_XLIB
|
||||
cogl_experimental_h += \
|
||||
$(srcdir)/winsys/cogl-texture-pixmap-x11.h \
|
||||
$(srcdir)/cogl-xlib.h
|
||||
|
||||
cogl_sources_c += \
|
||||
$(srcdir)/cogl-renderer-x11-private.h \
|
||||
$(srcdir)/cogl-renderer-xlib-private.h \
|
||||
$(srcdir)/cogl-renderer-xlib.c \
|
||||
$(srcdir)/cogl-display-xlib-private.h \
|
||||
$(srcdir)/cogl-xlib.c \
|
||||
$(srcdir)/winsys/cogl-texture-pixmap-x11.c \
|
||||
$(srcdir)/winsys/cogl-texture-pixmap-x11-private.h
|
||||
endif
|
||||
if SUPPORT_GLX
|
||||
cogl_sources_c += \
|
||||
$(srcdir)/cogl-renderer-glx-private.h \
|
||||
$(srcdir)/cogl-display-glx-private.h \
|
||||
$(srcdir)/winsys/cogl-winsys-glx-feature-functions.h \
|
||||
$(srcdir)/winsys/cogl-winsys-glx.c
|
||||
endif
|
||||
if SUPPORT_EGL_PLATFORM_POWERVR_X11
|
||||
cogl_sources_c += \
|
||||
$(srcdir)/winsys/cogl-winsys-egl.c
|
||||
endif
|
||||
if SUPPORT_EGL_PLATFORM_POWERVR_NULL
|
||||
cogl_sources_c += \
|
||||
$(srcdir)/winsys/cogl-winsys-egl.c
|
||||
endif
|
||||
if SUPPORT_EGL_PLATFORM_GDL
|
||||
cogl_sources_c += \
|
||||
$(srcdir)/winsys/cogl-winsys-egl.c
|
||||
endif
|
||||
if SUPPORT_STUB
|
||||
cogl_sources_c += \
|
||||
$(srcdir)/winsys/cogl-winsys-stub.c
|
||||
endif
|
||||
|
||||
EXTRA_DIST += stb_image.c
|
||||
|
||||
# glib-mkenums rules
|
||||
glib_enum_h = cogl-enum-types.h
|
||||
glib_enum_c = cogl-enum-types.c
|
||||
glib_enum_headers = $(cogl_public_h)
|
||||
include $(top_srcdir)/build/autotools/Makefile.am.enums
|
||||
|
||||
if COGL_STANDALONE_BUILD
|
||||
lib_LTLIBRARIES += libcogl.la
|
||||
else
|
||||
noinst_LTLIBRARIES += libcogl.la
|
||||
endif
|
||||
|
||||
libcogl_la_LIBADD = -lm $(COGL_DEP_LIBS) $(COGL_EXTRA_LDFLAGS)
|
||||
if SUPPORT_GLX
|
||||
libcogl_la_LIBADD += -ldl
|
||||
endif
|
||||
if COGL_STANDALONE_BUILD
|
||||
# XXX: The aim is to eventually get rid of all private API exports
|
||||
# for coglpango.
|
||||
libcogl_la_LDFLAGS = \
|
||||
-no-undefined \
|
||||
-version-info @COGL_LT_CURRENT@:@COGL_LT_REVISION@:@COGL_LT_AGE@ \
|
||||
-export-dynamic \
|
||||
-export-symbols-regex "^(cogl|_cogl_debug_flags|_cogl_atlas_new|_cogl_atlas_add_reorganize_callback|_cogl_atlas_reserve_space|_cogl_callback|_cogl_util_get_eye_planes_for_screen_poly).*"
|
||||
endif
|
||||
|
||||
libcogl_la_SOURCES = $(cogl_sources_c)
|
||||
nodist_libcogl_la_SOURCES = $(BUILT_SOURCES)
|
||||
|
||||
# Cogl installed headers
|
||||
cogl_headers = \
|
||||
$(cogl_public_h) \
|
||||
$(srcdir)/cogl-deprecated.h \
|
||||
$(NULL)
|
||||
|
||||
if COGL_STANDALONE_BUILD
|
||||
coglincludedir = $(includedir)/cogl/cogl
|
||||
coglinclude_HEADERS = $(cogl_headers) $(cogl_experimental_h)
|
||||
nodist_coglinclude_HEADERS = cogl-defines.h cogl-enum-types.h
|
||||
else
|
||||
coglincludedir = $(includedir)/clutter-@CLUTTER_API_VERSION@/cogl
|
||||
coglinclude_HEADERS = $(cogl_headers) $(cogl_experimental_h)
|
||||
nodist_coglinclude_HEADERS = cogl-defines.h cogl-enum-types.h
|
||||
endif
|
||||
|
||||
-include $(INTROSPECTION_MAKEFILE)
|
||||
|
||||
INTROSPECTION_GIRS =
|
||||
|
||||
if HAVE_INTROSPECTION
|
||||
Cogl-1.0.gir: libcogl.la Makefile
|
||||
|
||||
Cogl_1_0_gir_NAMESPACE = Cogl
|
||||
Cogl_1_0_gir_VERSION = 1.0
|
||||
Cogl_1_0_gir_LIBS = libcogl.la
|
||||
Cogl_1_0_gir_FILES = $(cogl_headers) cogl-enum-types.h
|
||||
Cogl_1_0_gir_CFLAGS = $(INCLUDES) $(AM_CPPFLAGS)
|
||||
Cogl_1_0_gir_INCLUDES = GL-1.0 GObject-2.0
|
||||
Cogl_1_0_gir_EXPORT_PACKAGES = cogl-1.0
|
||||
Cogl_1_0_gir_SCANNERFLAGS = --warn-all --c-include='cogl/cogl.h'
|
||||
|
||||
INTROSPECTION_GIRS += Cogl-1.0.gir
|
||||
|
||||
girdir = $(datadir)/gir-1.0
|
||||
gir_DATA = $(INTROSPECTION_GIRS)
|
||||
|
||||
CLEANFILES += $(INTROSPECTION_GIRS)
|
||||
endif
|
@ -1,17 +0,0 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
apiversion=1.0
|
||||
requires=@COGL_PKG_REQUIRES@
|
||||
backend=none #only kept for backward compatability
|
||||
winsys=none
|
||||
cogl=none #only kept for backward compatability
|
||||
driver=none
|
||||
|
||||
Name: Cogl
|
||||
Description: An object oriented GL/GLES Abstraction/Utility Layer
|
||||
Version: @COGL_1_VERSION@
|
||||
Libs: -L${libdir} -lcogl -lcoglpango
|
||||
Cflags: -I${includedir}/clutter-${apiversion}
|
||||
Requires: ${requires}
|
@ -1,13 +0,0 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
apiversion=1.0
|
||||
requires=@COGL_PKG_REQUIRES@
|
||||
|
||||
Name: Cogl
|
||||
Description: An object oriented GL/GLES Abstraction/Utility Layer
|
||||
Version: @COGL_1_VERSION@
|
||||
Libs: -L${libdir} -lcogl -lcoglpango
|
||||
Cflags: -I${includedir}/cogl
|
||||
Requires: ${requires}
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_ATLAS_TEXTURE_H
|
||||
#define __COGL_ATLAS_TEXTURE_H
|
||||
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-texture-private.h"
|
||||
#include "cogl-rectangle-map.h"
|
||||
#include "cogl-atlas.h"
|
||||
|
||||
#define COGL_ATLAS_TEXTURE(tex) ((CoglAtlasTexture *) tex)
|
||||
|
||||
typedef struct _CoglAtlasTexture CoglAtlasTexture;
|
||||
|
||||
struct _CoglAtlasTexture
|
||||
{
|
||||
CoglTexture _parent;
|
||||
|
||||
/* The format that the texture is in. This isn't necessarily the
|
||||
same format as the atlas texture because we can store
|
||||
pre-multiplied and non-pre-multiplied textures together */
|
||||
CoglPixelFormat format;
|
||||
|
||||
/* The rectangle that was used to add this texture to the
|
||||
atlas. This includes the 1-pixel border */
|
||||
CoglRectangleMapEntry rectangle;
|
||||
|
||||
/* The atlas that this texture is in. If the texture is no longer in
|
||||
an atlas then this will be NULL. A reference is taken on the
|
||||
atlas by the texture (but not vice versa so there is no cycle) */
|
||||
CoglAtlas *atlas;
|
||||
|
||||
/* A CoglSubTexture representing the region for easy rendering */
|
||||
CoglHandle sub_texture;
|
||||
};
|
||||
|
||||
GQuark
|
||||
_cogl_handle_atlas_texture_get_type (void);
|
||||
|
||||
CoglHandle
|
||||
_cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
|
||||
CoglTextureFlags flags,
|
||||
CoglPixelFormat internal_format);
|
||||
|
||||
CoglHandle
|
||||
_cogl_atlas_texture_new_with_size (unsigned int width,
|
||||
unsigned int height,
|
||||
CoglTextureFlags flags,
|
||||
CoglPixelFormat internal_format);
|
||||
|
||||
void
|
||||
_cogl_atlas_texture_add_reorganize_callback (GHookFunc callback,
|
||||
void *user_data);
|
||||
|
||||
void
|
||||
_cogl_atlas_texture_remove_reorganize_callback (GHookFunc callback,
|
||||
void *user_data);
|
||||
|
||||
#endif /* __COGL_ATLAS_TEXTURE_H */
|
@ -1,806 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009,2010,2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Neil Roberts <neil@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-debug.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-util.h"
|
||||
#include "cogl-texture-private.h"
|
||||
#include "cogl-atlas-texture-private.h"
|
||||
#include "cogl-texture-2d-private.h"
|
||||
#include "cogl-sub-texture-private.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-texture-driver.h"
|
||||
#include "cogl-rectangle-map.h"
|
||||
#include "cogl-journal-private.h"
|
||||
#include "cogl-pipeline-opengl-private.h"
|
||||
#include "cogl-atlas.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static void _cogl_atlas_texture_free (CoglAtlasTexture *sub_tex);
|
||||
|
||||
COGL_TEXTURE_INTERNAL_DEFINE (AtlasTexture, atlas_texture);
|
||||
|
||||
static const CoglTextureVtable cogl_atlas_texture_vtable;
|
||||
|
||||
static CoglHandle
|
||||
_cogl_atlas_texture_create_sub_texture (CoglHandle full_texture,
|
||||
const CoglRectangleMapEntry *rectangle)
|
||||
{
|
||||
/* Create a subtexture for the given rectangle not including the
|
||||
1-pixel border */
|
||||
return _cogl_sub_texture_new (full_texture,
|
||||
rectangle->x + 1,
|
||||
rectangle->y + 1,
|
||||
rectangle->width - 2,
|
||||
rectangle->height - 2);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_update_position_cb (gpointer user_data,
|
||||
CoglHandle new_texture,
|
||||
const CoglRectangleMapEntry *rectangle)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = user_data;
|
||||
|
||||
/* Update the sub texture */
|
||||
if (atlas_tex->sub_texture)
|
||||
cogl_handle_unref (atlas_tex->sub_texture);
|
||||
atlas_tex->sub_texture =
|
||||
_cogl_atlas_texture_create_sub_texture (new_texture, rectangle);
|
||||
|
||||
/* Update the position */
|
||||
atlas_tex->rectangle = *rectangle;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_pre_reorganize_foreach_cb
|
||||
(const CoglRectangleMapEntry *entry,
|
||||
void *rectangle_data,
|
||||
void *user_data)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = rectangle_data;
|
||||
|
||||
/* Keep a reference to the texture because we don't want it to be
|
||||
destroyed during the reorganization */
|
||||
cogl_handle_ref (atlas_tex);
|
||||
|
||||
/* Notify cogl-pipeline.c that the texture's underlying GL texture
|
||||
* storage is changing so it knows it may need to bind a new texture
|
||||
* if the CoglTexture is reused with the same texture unit. */
|
||||
_cogl_pipeline_texture_storage_change_notify (COGL_TEXTURE (atlas_tex));
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_pre_reorganize_cb (void *data)
|
||||
{
|
||||
CoglAtlas *atlas = data;
|
||||
|
||||
/* We don't know if any journal entries currently depend on OpenGL
|
||||
* texture coordinates that would be invalidated by reorganizing
|
||||
* this atlas so we flush all journals before migrating.
|
||||
*
|
||||
* We are assuming that texture atlas migration never happens
|
||||
* during a flush so we don't have to consider recursion here.
|
||||
*/
|
||||
cogl_flush ();
|
||||
|
||||
if (atlas->map)
|
||||
_cogl_rectangle_map_foreach (atlas->map,
|
||||
_cogl_atlas_texture_pre_reorganize_foreach_cb,
|
||||
NULL);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CoglAtlasTexture **textures;
|
||||
/* Number of textures found so far */
|
||||
unsigned int n_textures;
|
||||
} CoglAtlasTextureGetRectanglesData;
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_get_rectangles_cb (const CoglRectangleMapEntry *entry,
|
||||
void *rectangle_data,
|
||||
void *user_data)
|
||||
{
|
||||
CoglAtlasTextureGetRectanglesData *data = user_data;
|
||||
|
||||
data->textures[data->n_textures++] = rectangle_data;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_post_reorganize_cb (void *user_data)
|
||||
{
|
||||
CoglAtlas *atlas = user_data;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
if (atlas->map)
|
||||
{
|
||||
CoglAtlasTextureGetRectanglesData data;
|
||||
unsigned int i;
|
||||
|
||||
data.textures = g_new (CoglAtlasTexture *,
|
||||
_cogl_rectangle_map_get_n_rectangles (atlas->map));
|
||||
data.n_textures = 0;
|
||||
|
||||
/* We need to remove all of the references that we took during
|
||||
the preorganize callback. We have to get a separate array of
|
||||
the textures because CoglRectangleMap doesn't support
|
||||
removing rectangles during iteration */
|
||||
_cogl_rectangle_map_foreach (atlas->map,
|
||||
_cogl_atlas_texture_get_rectangles_cb,
|
||||
&data);
|
||||
|
||||
for (i = 0; i < data.n_textures; i++)
|
||||
{
|
||||
/* Ignore textures that don't have an atlas yet. This will
|
||||
happen when a new texture is added because we allocate
|
||||
the structure for the texture so that it can get stored
|
||||
in the atlas but it isn't a valid object yet */
|
||||
if (data.textures[i]->atlas)
|
||||
cogl_object_unref (data.textures[i]);
|
||||
}
|
||||
|
||||
g_free (data.textures);
|
||||
}
|
||||
|
||||
/* Notify any listeners that an atlas has changed */
|
||||
g_hook_list_invoke (&ctx->atlas_reorganize_callbacks, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_atlas_destroyed_cb (void *user_data)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
/* Remove the atlas from the global list */
|
||||
ctx->atlases = g_slist_remove (ctx->atlases, user_data);
|
||||
}
|
||||
|
||||
static CoglAtlas *
|
||||
_cogl_atlas_texture_create_atlas (void)
|
||||
{
|
||||
static CoglUserDataKey atlas_private_key;
|
||||
|
||||
CoglAtlas *atlas;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
|
||||
|
||||
atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_RGBA_8888,
|
||||
0,
|
||||
_cogl_atlas_texture_update_position_cb);
|
||||
|
||||
_cogl_atlas_add_reorganize_callback (atlas,
|
||||
_cogl_atlas_texture_pre_reorganize_cb,
|
||||
_cogl_atlas_texture_post_reorganize_cb,
|
||||
atlas);
|
||||
|
||||
ctx->atlases = g_slist_prepend (ctx->atlases, atlas);
|
||||
|
||||
/* Set some data on the atlas so we can get notification when it is
|
||||
destroyed in order to remove it from the list. ctx->atlases
|
||||
effectively holds a weak reference. We don't need a strong
|
||||
reference because the atlas textures take a reference on the
|
||||
atlas so it will stay alive */
|
||||
cogl_object_set_user_data (COGL_OBJECT (atlas), &atlas_private_key, atlas,
|
||||
_cogl_atlas_texture_atlas_destroyed_cb);
|
||||
|
||||
return atlas;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_foreach_sub_texture_in_region (
|
||||
CoglTexture *tex,
|
||||
float virtual_tx_1,
|
||||
float virtual_ty_1,
|
||||
float virtual_tx_2,
|
||||
float virtual_ty_2,
|
||||
CoglTextureSliceCallback callback,
|
||||
void *user_data)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
_cogl_texture_foreach_sub_texture_in_region (atlas_tex->sub_texture,
|
||||
virtual_tx_1,
|
||||
virtual_ty_1,
|
||||
virtual_tx_2,
|
||||
virtual_ty_2,
|
||||
callback,
|
||||
user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_set_wrap_mode_parameters (CoglTexture *tex,
|
||||
GLenum wrap_mode_s,
|
||||
GLenum wrap_mode_t,
|
||||
GLenum wrap_mode_p)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
_cogl_texture_set_wrap_mode_parameters (atlas_tex->sub_texture,
|
||||
wrap_mode_s,
|
||||
wrap_mode_t,
|
||||
wrap_mode_p);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_remove_from_atlas (CoglAtlasTexture *atlas_tex)
|
||||
{
|
||||
if (atlas_tex->atlas)
|
||||
{
|
||||
_cogl_atlas_remove (atlas_tex->atlas,
|
||||
&atlas_tex->rectangle);
|
||||
|
||||
cogl_object_unref (atlas_tex->atlas);
|
||||
atlas_tex->atlas = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_free (CoglAtlasTexture *atlas_tex)
|
||||
{
|
||||
_cogl_atlas_texture_remove_from_atlas (atlas_tex);
|
||||
|
||||
cogl_handle_unref (atlas_tex->sub_texture);
|
||||
|
||||
/* Chain up */
|
||||
_cogl_texture_free (COGL_TEXTURE (atlas_tex));
|
||||
}
|
||||
|
||||
static int
|
||||
_cogl_atlas_texture_get_max_waste (CoglTexture *tex)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
return cogl_texture_get_max_waste (atlas_tex->sub_texture);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_atlas_texture_is_sliced (CoglTexture *tex)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
return cogl_texture_is_sliced (atlas_tex->sub_texture);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_atlas_texture_can_hardware_repeat (CoglTexture *tex)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
return _cogl_texture_can_hardware_repeat (atlas_tex->sub_texture);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_transform_coords_to_gl (CoglTexture *tex,
|
||||
float *s,
|
||||
float *t)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
_cogl_texture_transform_coords_to_gl (atlas_tex->sub_texture, s, t);
|
||||
}
|
||||
|
||||
static CoglTransformResult
|
||||
_cogl_atlas_texture_transform_quad_coords_to_gl (CoglTexture *tex,
|
||||
float *coords)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
return _cogl_texture_transform_quad_coords_to_gl (atlas_tex->sub_texture,
|
||||
coords);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_atlas_texture_get_gl_texture (CoglTexture *tex,
|
||||
GLuint *out_gl_handle,
|
||||
GLenum *out_gl_target)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
return cogl_texture_get_gl_texture (atlas_tex->sub_texture,
|
||||
out_gl_handle,
|
||||
out_gl_target);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_set_filters (CoglTexture *tex,
|
||||
GLenum min_filter,
|
||||
GLenum mag_filter)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
_cogl_texture_set_filters (atlas_tex->sub_texture, min_filter, mag_filter);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
|
||||
{
|
||||
/* Make sure this texture is not in the atlas */
|
||||
if (atlas_tex->atlas)
|
||||
{
|
||||
CoglHandle sub_texture;
|
||||
|
||||
COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
|
||||
|
||||
/* We don't know if any journal entries currently depend on
|
||||
* OpenGL texture coordinates that would be invalidated by
|
||||
* migrating textures in this atlas so we flush all journals
|
||||
* before migrating.
|
||||
*
|
||||
* We are assuming that texture atlas migration never happens
|
||||
* during a flush so we don't have to consider recursion here.
|
||||
*/
|
||||
cogl_flush ();
|
||||
|
||||
sub_texture =
|
||||
_cogl_atlas_copy_rectangle (atlas_tex->atlas,
|
||||
atlas_tex->rectangle.x + 1,
|
||||
atlas_tex->rectangle.y + 1,
|
||||
atlas_tex->rectangle.width - 2,
|
||||
atlas_tex->rectangle.height - 2,
|
||||
COGL_TEXTURE_NO_ATLAS,
|
||||
atlas_tex->format);
|
||||
|
||||
/* Notify cogl-pipeline.c that the texture's underlying GL texture
|
||||
* storage is changing so it knows it may need to bind a new texture
|
||||
* if the CoglTexture is reused with the same texture unit. */
|
||||
_cogl_pipeline_texture_storage_change_notify (atlas_tex);
|
||||
|
||||
/* We need to unref the sub texture after doing the copy because
|
||||
the copy can involve rendering which might cause the texture
|
||||
to be used if it is used from a layer that is left in a
|
||||
texture unit */
|
||||
cogl_handle_unref (atlas_tex->sub_texture);
|
||||
atlas_tex->sub_texture = sub_texture;
|
||||
|
||||
_cogl_atlas_texture_remove_from_atlas (atlas_tex);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
if ((flags & COGL_TEXTURE_NEEDS_MIPMAP))
|
||||
/* Mipmaps do not work well with the current atlas so instead
|
||||
we'll just migrate the texture out and use a regular texture */
|
||||
_cogl_atlas_texture_migrate_out_of_atlas (atlas_tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
_cogl_texture_pre_paint (atlas_tex->sub_texture, flags);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_texture_ensure_non_quad_rendering (CoglTexture *tex)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Sub textures can't support non-quad rendering so we'll just
|
||||
migrate the texture out */
|
||||
_cogl_atlas_texture_migrate_out_of_atlas (atlas_tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
_cogl_texture_ensure_non_quad_rendering (atlas_tex->sub_texture);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_atlas_texture_set_region_with_border (CoglAtlasTexture *atlas_tex,
|
||||
int src_x,
|
||||
int src_y,
|
||||
int dst_x,
|
||||
int dst_y,
|
||||
unsigned int dst_width,
|
||||
unsigned int dst_height,
|
||||
CoglBitmap *bmp)
|
||||
{
|
||||
CoglAtlas *atlas = atlas_tex->atlas;
|
||||
|
||||
/* Copy the central data */
|
||||
if (!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||
src_x, src_y,
|
||||
dst_x + atlas_tex->rectangle.x + 1,
|
||||
dst_y + atlas_tex->rectangle.y + 1,
|
||||
dst_width,
|
||||
dst_height,
|
||||
bmp))
|
||||
return FALSE;
|
||||
|
||||
/* Update the left edge pixels */
|
||||
if (dst_x == 0 &&
|
||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||
src_x, src_y,
|
||||
atlas_tex->rectangle.x,
|
||||
dst_y + atlas_tex->rectangle.y + 1,
|
||||
1, dst_height,
|
||||
bmp))
|
||||
return FALSE;
|
||||
/* Update the right edge pixels */
|
||||
if (dst_x + dst_width == atlas_tex->rectangle.width - 2 &&
|
||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||
src_x + dst_width - 1, src_y,
|
||||
atlas_tex->rectangle.x +
|
||||
atlas_tex->rectangle.width - 1,
|
||||
dst_y + atlas_tex->rectangle.y + 1,
|
||||
1, dst_height,
|
||||
bmp))
|
||||
return FALSE;
|
||||
/* Update the top edge pixels */
|
||||
if (dst_y == 0 &&
|
||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||
src_x, src_y,
|
||||
dst_x + atlas_tex->rectangle.x + 1,
|
||||
atlas_tex->rectangle.y,
|
||||
dst_width, 1,
|
||||
bmp))
|
||||
return FALSE;
|
||||
/* Update the bottom edge pixels */
|
||||
if (dst_y + dst_height == atlas_tex->rectangle.height - 2 &&
|
||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||
src_x, src_y + dst_height - 1,
|
||||
dst_x + atlas_tex->rectangle.x + 1,
|
||||
atlas_tex->rectangle.y +
|
||||
atlas_tex->rectangle.height - 1,
|
||||
dst_width, 1,
|
||||
bmp))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_atlas_texture_set_region (CoglTexture *tex,
|
||||
int src_x,
|
||||
int src_y,
|
||||
int dst_x,
|
||||
int dst_y,
|
||||
unsigned int dst_width,
|
||||
unsigned int dst_height,
|
||||
CoglBitmap *bmp)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* If the texture is in the atlas then we need to copy the edge
|
||||
pixels to the border */
|
||||
if (atlas_tex->atlas)
|
||||
{
|
||||
gboolean ret;
|
||||
|
||||
bmp = _cogl_bitmap_new_shared (bmp,
|
||||
_cogl_bitmap_get_format (bmp) &
|
||||
~COGL_PREMULT_BIT,
|
||||
_cogl_bitmap_get_width (bmp),
|
||||
_cogl_bitmap_get_height (bmp),
|
||||
_cogl_bitmap_get_rowstride (bmp));
|
||||
|
||||
/* Upload the data ignoring the premult bit */
|
||||
ret = _cogl_atlas_texture_set_region_with_border (atlas_tex,
|
||||
src_x, src_y,
|
||||
dst_x, dst_y,
|
||||
dst_width, dst_height,
|
||||
bmp);
|
||||
|
||||
cogl_object_unref (bmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
/* Otherwise we can just forward on to the sub texture */
|
||||
return _cogl_texture_set_region_from_bitmap (atlas_tex->sub_texture,
|
||||
src_x, src_y,
|
||||
dst_x, dst_y,
|
||||
dst_width, dst_height,
|
||||
bmp);
|
||||
}
|
||||
|
||||
static CoglPixelFormat
|
||||
_cogl_atlas_texture_get_format (CoglTexture *tex)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* We don't want to forward this on the sub-texture because it isn't
|
||||
the necessarily the same format. This will happen if the texture
|
||||
isn't pre-multiplied */
|
||||
return atlas_tex->format;
|
||||
}
|
||||
|
||||
static GLenum
|
||||
_cogl_atlas_texture_get_gl_format (CoglTexture *tex)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
return _cogl_texture_get_gl_format (atlas_tex->sub_texture);
|
||||
}
|
||||
|
||||
static int
|
||||
_cogl_atlas_texture_get_width (CoglTexture *tex)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
return cogl_texture_get_width (atlas_tex->sub_texture);
|
||||
}
|
||||
|
||||
static int
|
||||
_cogl_atlas_texture_get_height (CoglTexture *tex)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
|
||||
|
||||
/* Forward on to the sub texture */
|
||||
return cogl_texture_get_height (atlas_tex->sub_texture);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_atlas_texture_can_use_format (CoglPixelFormat format)
|
||||
{
|
||||
/* We don't care about the ordering or the premult status and we can
|
||||
accept RGBA or RGB textures. Although we could also accept
|
||||
luminance and alpha only textures or 16-bit formats it seems that
|
||||
if the application is explicitly using these formats then they've
|
||||
got a reason to want the lower memory requirements so putting
|
||||
them in the atlas might not be a good idea */
|
||||
format &= ~(COGL_PREMULT_BIT | COGL_BGR_BIT | COGL_AFIRST_BIT);
|
||||
return (format == COGL_PIXEL_FORMAT_RGB_888 ||
|
||||
format == COGL_PIXEL_FORMAT_RGBA_8888);
|
||||
}
|
||||
|
||||
CoglHandle
|
||||
_cogl_atlas_texture_new_with_size (unsigned int width,
|
||||
unsigned int height,
|
||||
CoglTextureFlags flags,
|
||||
CoglPixelFormat internal_format)
|
||||
{
|
||||
CoglAtlasTexture *atlas_tex;
|
||||
CoglAtlas *atlas;
|
||||
GSList *l;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
|
||||
|
||||
/* Don't put textures in the atlas if the user has explicitly
|
||||
requested to disable it */
|
||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_ATLAS)))
|
||||
return COGL_INVALID_HANDLE;
|
||||
|
||||
/* We can't put the texture in the atlas if there are any special
|
||||
flags. This precludes textures with COGL_TEXTURE_NO_ATLAS and
|
||||
COGL_TEXTURE_NO_SLICING from being atlased */
|
||||
if (flags)
|
||||
return COGL_INVALID_HANDLE;
|
||||
|
||||
/* We can't atlas zero-sized textures because it breaks the atlas
|
||||
data structure */
|
||||
if (width < 1 || height < 1)
|
||||
return COGL_INVALID_HANDLE;
|
||||
|
||||
/* If we can't use FBOs then it will be too slow to migrate textures
|
||||
and we shouldn't use the atlas */
|
||||
if (!cogl_features_available (COGL_FEATURE_OFFSCREEN))
|
||||
return COGL_INVALID_HANDLE;
|
||||
|
||||
COGL_NOTE (ATLAS, "Adding texture of size %ix%i", width, height);
|
||||
|
||||
/* If the texture is in a strange format then we won't use it */
|
||||
if (!_cogl_atlas_texture_can_use_format (internal_format))
|
||||
{
|
||||
COGL_NOTE (ATLAS, "Texture can not be added because the "
|
||||
"format is unsupported");
|
||||
|
||||
return COGL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/* We need to allocate the texture now because we need the pointer
|
||||
to set as the data for the rectangle in the atlas */
|
||||
atlas_tex = g_new (CoglAtlasTexture, 1);
|
||||
/* Mark it as having no atlas so we don't try to unref it in
|
||||
_cogl_atlas_texture_post_reorganize_cb */
|
||||
atlas_tex->atlas = NULL;
|
||||
|
||||
_cogl_texture_init (COGL_TEXTURE (atlas_tex),
|
||||
&cogl_atlas_texture_vtable);
|
||||
|
||||
atlas_tex->sub_texture = COGL_INVALID_HANDLE;
|
||||
|
||||
/* Look for an existing atlas that can hold the texture */
|
||||
for (l = ctx->atlases; l; l = l->next)
|
||||
/* Try to make some space in the atlas for the texture */
|
||||
if (_cogl_atlas_reserve_space (atlas = l->data,
|
||||
/* Add two pixels for the border */
|
||||
width + 2, height + 2,
|
||||
atlas_tex))
|
||||
{
|
||||
cogl_object_ref (atlas);
|
||||
break;
|
||||
}
|
||||
|
||||
/* If we couldn't find a suitable atlas then start another */
|
||||
if (l == NULL)
|
||||
{
|
||||
atlas = _cogl_atlas_texture_create_atlas ();
|
||||
COGL_NOTE (ATLAS, "Created new atlas for textures: %p", atlas);
|
||||
if (!_cogl_atlas_reserve_space (atlas,
|
||||
/* Add two pixels for the border */
|
||||
width + 2, height + 2,
|
||||
atlas_tex))
|
||||
{
|
||||
/* Ok, this means we really can't add it to the atlas */
|
||||
cogl_object_unref (atlas);
|
||||
g_free (atlas_tex);
|
||||
return COGL_INVALID_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
atlas_tex->format = internal_format;
|
||||
atlas_tex->atlas = atlas;
|
||||
|
||||
return _cogl_atlas_texture_handle_new (atlas_tex);
|
||||
}
|
||||
|
||||
CoglHandle
|
||||
_cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
|
||||
CoglTextureFlags flags,
|
||||
CoglPixelFormat internal_format)
|
||||
{
|
||||
CoglHandle atlas_tex_handle;
|
||||
CoglAtlasTexture *atlas_tex;
|
||||
CoglBitmap *dst_bmp;
|
||||
CoglBitmap *override_bmp;
|
||||
GLenum gl_intformat;
|
||||
GLenum gl_format;
|
||||
GLenum gl_type;
|
||||
int bmp_width;
|
||||
int bmp_height;
|
||||
CoglPixelFormat bmp_format;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
|
||||
|
||||
g_return_val_if_fail (cogl_is_bitmap (bmp), COGL_INVALID_HANDLE);
|
||||
|
||||
bmp_width = _cogl_bitmap_get_width (bmp);
|
||||
bmp_height = _cogl_bitmap_get_height (bmp);
|
||||
bmp_format = _cogl_bitmap_get_format (bmp);
|
||||
|
||||
internal_format = _cogl_texture_determine_internal_format (bmp_format,
|
||||
internal_format);
|
||||
|
||||
atlas_tex_handle = _cogl_atlas_texture_new_with_size (bmp_width, bmp_height,
|
||||
flags, internal_format);
|
||||
|
||||
if (atlas_tex_handle == COGL_INVALID_HANDLE)
|
||||
return COGL_INVALID_HANDLE;
|
||||
|
||||
atlas_tex = atlas_tex_handle;
|
||||
|
||||
dst_bmp = _cogl_texture_prepare_for_upload (bmp,
|
||||
internal_format,
|
||||
&internal_format,
|
||||
&gl_intformat,
|
||||
&gl_format,
|
||||
&gl_type);
|
||||
|
||||
if (dst_bmp == NULL)
|
||||
{
|
||||
cogl_handle_unref (atlas_tex_handle);
|
||||
return COGL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/* Make another bitmap so that we can override the format */
|
||||
override_bmp = _cogl_bitmap_new_shared (dst_bmp,
|
||||
_cogl_bitmap_get_format (dst_bmp) &
|
||||
~COGL_PREMULT_BIT,
|
||||
_cogl_bitmap_get_width (dst_bmp),
|
||||
_cogl_bitmap_get_height (dst_bmp),
|
||||
_cogl_bitmap_get_rowstride (dst_bmp));
|
||||
cogl_object_unref (dst_bmp);
|
||||
|
||||
/* Defer to set_region so that we can share the code for copying the
|
||||
edge pixels to the border. We don't want to pass the actual
|
||||
format of the converted texture because otherwise it will get
|
||||
unpremultiplied. */
|
||||
_cogl_atlas_texture_set_region_with_border (atlas_tex,
|
||||
0, /* src_x */
|
||||
0, /* src_y */
|
||||
0, /* dst_x */
|
||||
0, /* dst_y */
|
||||
bmp_width, /* dst_width */
|
||||
bmp_height, /* dst_height */
|
||||
override_bmp);
|
||||
|
||||
cogl_object_unref (override_bmp);
|
||||
|
||||
return atlas_tex_handle;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_atlas_texture_add_reorganize_callback (GHookFunc callback,
|
||||
void *user_data)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
hook = g_hook_alloc (&ctx->atlas_reorganize_callbacks);
|
||||
hook->func = callback;
|
||||
hook->data = user_data;
|
||||
g_hook_prepend (&ctx->atlas_reorganize_callbacks, hook);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_atlas_texture_remove_reorganize_callback (GHookFunc callback,
|
||||
void *user_data)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
hook = g_hook_find_func_data (&ctx->atlas_reorganize_callbacks,
|
||||
FALSE,
|
||||
callback,
|
||||
user_data);
|
||||
|
||||
if (hook)
|
||||
g_hook_destroy_link (&ctx->atlas_reorganize_callbacks, hook);
|
||||
}
|
||||
|
||||
static const CoglTextureVtable
|
||||
cogl_atlas_texture_vtable =
|
||||
{
|
||||
_cogl_atlas_texture_set_region,
|
||||
NULL, /* get_data */
|
||||
_cogl_atlas_texture_foreach_sub_texture_in_region,
|
||||
_cogl_atlas_texture_get_max_waste,
|
||||
_cogl_atlas_texture_is_sliced,
|
||||
_cogl_atlas_texture_can_hardware_repeat,
|
||||
_cogl_atlas_texture_transform_coords_to_gl,
|
||||
_cogl_atlas_texture_transform_quad_coords_to_gl,
|
||||
_cogl_atlas_texture_get_gl_texture,
|
||||
_cogl_atlas_texture_set_filters,
|
||||
_cogl_atlas_texture_pre_paint,
|
||||
_cogl_atlas_texture_ensure_non_quad_rendering,
|
||||
_cogl_atlas_texture_set_wrap_mode_parameters,
|
||||
_cogl_atlas_texture_get_format,
|
||||
_cogl_atlas_texture_get_gl_format,
|
||||
_cogl_atlas_texture_get_width,
|
||||
_cogl_atlas_texture_get_height,
|
||||
NULL /* is_foreign */
|
||||
};
|
@ -1,589 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010,2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Neil Roberts <neil@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-atlas.h"
|
||||
#include "cogl-rectangle-map.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-texture-private.h"
|
||||
#include "cogl-texture-2d-private.h"
|
||||
#include "cogl-texture-driver.h"
|
||||
#include "cogl-pipeline-opengl-private.h"
|
||||
#include "cogl-debug.h"
|
||||
#include "cogl-framebuffer-private.h"
|
||||
#include "cogl-blit.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static void _cogl_atlas_free (CoglAtlas *atlas);
|
||||
|
||||
COGL_OBJECT_INTERNAL_DEFINE (Atlas, atlas);
|
||||
|
||||
CoglAtlas *
|
||||
_cogl_atlas_new (CoglPixelFormat texture_format,
|
||||
CoglAtlasFlags flags,
|
||||
CoglAtlasUpdatePositionCallback update_position_cb)
|
||||
{
|
||||
CoglAtlas *atlas = g_new (CoglAtlas, 1);
|
||||
|
||||
atlas->update_position_cb = update_position_cb;
|
||||
atlas->map = NULL;
|
||||
atlas->texture = NULL;
|
||||
atlas->flags = flags;
|
||||
atlas->texture_format = texture_format;
|
||||
g_hook_list_init (&atlas->pre_reorganize_callbacks, sizeof (GHook));
|
||||
g_hook_list_init (&atlas->post_reorganize_callbacks, sizeof (GHook));
|
||||
|
||||
return _cogl_atlas_object_new (atlas);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_free (CoglAtlas *atlas)
|
||||
{
|
||||
COGL_NOTE (ATLAS, "%p: Atlas destroyed", atlas);
|
||||
|
||||
if (atlas->texture)
|
||||
cogl_handle_unref (atlas->texture);
|
||||
if (atlas->map)
|
||||
_cogl_rectangle_map_free (atlas->map);
|
||||
|
||||
g_hook_list_clear (&atlas->pre_reorganize_callbacks);
|
||||
g_hook_list_clear (&atlas->post_reorganize_callbacks);
|
||||
|
||||
g_free (atlas);
|
||||
}
|
||||
|
||||
typedef struct _CoglAtlasRepositionData
|
||||
{
|
||||
/* The current user data for this texture */
|
||||
void *user_data;
|
||||
/* The old and new positions of the texture */
|
||||
CoglRectangleMapEntry old_position;
|
||||
CoglRectangleMapEntry new_position;
|
||||
} CoglAtlasRepositionData;
|
||||
|
||||
static void
|
||||
_cogl_atlas_migrate (CoglAtlas *atlas,
|
||||
unsigned int n_textures,
|
||||
CoglAtlasRepositionData *textures,
|
||||
CoglHandle old_texture,
|
||||
CoglHandle new_texture,
|
||||
void *skip_user_data)
|
||||
{
|
||||
unsigned int i;
|
||||
CoglBlitData blit_data;
|
||||
|
||||
/* If the 'disable migrate' flag is set then we won't actually copy
|
||||
the textures to their new location. Instead we'll just invoke the
|
||||
callback to update the position */
|
||||
if ((atlas->flags & COGL_ATLAS_DISABLE_MIGRATION))
|
||||
for (i = 0; i < n_textures; i++)
|
||||
/* Update the texture position */
|
||||
atlas->update_position_cb (textures[i].user_data,
|
||||
new_texture,
|
||||
&textures[i].new_position);
|
||||
else
|
||||
{
|
||||
_cogl_blit_begin (&blit_data, new_texture, old_texture);
|
||||
|
||||
for (i = 0; i < n_textures; i++)
|
||||
{
|
||||
/* Skip the texture that is being added because it doesn't contain
|
||||
any data yet */
|
||||
if (textures[i].user_data != skip_user_data)
|
||||
_cogl_blit (&blit_data,
|
||||
textures[i].old_position.x,
|
||||
textures[i].old_position.y,
|
||||
textures[i].new_position.x,
|
||||
textures[i].new_position.y,
|
||||
textures[i].new_position.width,
|
||||
textures[i].new_position.height);
|
||||
|
||||
/* Update the texture position */
|
||||
atlas->update_position_cb (textures[i].user_data,
|
||||
new_texture,
|
||||
&textures[i].new_position);
|
||||
}
|
||||
|
||||
_cogl_blit_end (&blit_data);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct _CoglAtlasGetRectanglesData
|
||||
{
|
||||
CoglAtlasRepositionData *textures;
|
||||
/* Number of textures found so far */
|
||||
unsigned int n_textures;
|
||||
} CoglAtlasGetRectanglesData;
|
||||
|
||||
static void
|
||||
_cogl_atlas_get_rectangles_cb (const CoglRectangleMapEntry *rectangle,
|
||||
void *rect_data,
|
||||
void *user_data)
|
||||
{
|
||||
CoglAtlasGetRectanglesData *data = user_data;
|
||||
|
||||
data->textures[data->n_textures].old_position = *rectangle;
|
||||
data->textures[data->n_textures++].user_data = rect_data;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_get_next_size (unsigned int *map_width,
|
||||
unsigned int *map_height)
|
||||
{
|
||||
/* Double the size of the texture by increasing whichever dimension
|
||||
is smaller */
|
||||
if (*map_width < *map_height)
|
||||
*map_width <<= 1;
|
||||
else
|
||||
*map_height <<= 1;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_get_initial_size (CoglPixelFormat format,
|
||||
unsigned int *map_width,
|
||||
unsigned int *map_height)
|
||||
{
|
||||
unsigned int size;
|
||||
GLenum gl_intformat;
|
||||
GLenum gl_type;
|
||||
|
||||
_cogl_pixel_format_to_gl (format,
|
||||
&gl_intformat,
|
||||
NULL, /* gl_format */
|
||||
&gl_type);
|
||||
|
||||
/* At least on Intel hardware, the texture size will be rounded up
|
||||
to at least 1MB so we might as well try to aim for that as an
|
||||
initial minimum size. If the format is only 1 byte per pixel we
|
||||
can use 1024x1024, otherwise we'll assume it will take 4 bytes
|
||||
per pixel and use 512x512. */
|
||||
if (_cogl_get_format_bpp (format) == 1)
|
||||
size = 1024;
|
||||
else
|
||||
size = 512;
|
||||
|
||||
/* Some platforms might not support this large size so we'll
|
||||
decrease the size until it can */
|
||||
while (size > 1 &&
|
||||
!_cogl_texture_driver_size_supported (GL_TEXTURE_2D,
|
||||
gl_intformat,
|
||||
gl_type,
|
||||
size, size))
|
||||
size >>= 1;
|
||||
|
||||
*map_width = size;
|
||||
*map_height = size;
|
||||
}
|
||||
|
||||
static CoglRectangleMap *
|
||||
_cogl_atlas_create_map (CoglPixelFormat format,
|
||||
unsigned int map_width,
|
||||
unsigned int map_height,
|
||||
unsigned int n_textures,
|
||||
CoglAtlasRepositionData *textures)
|
||||
{
|
||||
GLenum gl_intformat;
|
||||
GLenum gl_type;
|
||||
|
||||
_cogl_pixel_format_to_gl (format,
|
||||
&gl_intformat,
|
||||
NULL, /* gl_format */
|
||||
&gl_type);
|
||||
|
||||
/* Keep trying increasingly larger atlases until we can fit all of
|
||||
the textures */
|
||||
while (_cogl_texture_driver_size_supported (GL_TEXTURE_2D,
|
||||
gl_intformat,
|
||||
gl_type,
|
||||
map_width, map_height))
|
||||
{
|
||||
CoglRectangleMap *new_atlas = _cogl_rectangle_map_new (map_width,
|
||||
map_height,
|
||||
NULL);
|
||||
unsigned int i;
|
||||
|
||||
COGL_NOTE (ATLAS, "Trying to resize the atlas to %ux%u",
|
||||
map_width, map_height);
|
||||
|
||||
/* Add all of the textures and keep track of the new position */
|
||||
for (i = 0; i < n_textures; i++)
|
||||
if (!_cogl_rectangle_map_add (new_atlas,
|
||||
textures[i].old_position.width,
|
||||
textures[i].old_position.height,
|
||||
textures[i].user_data,
|
||||
&textures[i].new_position))
|
||||
break;
|
||||
|
||||
/* If the atlas can contain all of the textures then we have a
|
||||
winner */
|
||||
if (i >= n_textures)
|
||||
return new_atlas;
|
||||
else
|
||||
COGL_NOTE (ATLAS, "Atlas size abandoned after trying "
|
||||
"%u out of %u textures",
|
||||
i, n_textures);
|
||||
|
||||
_cogl_rectangle_map_free (new_atlas);
|
||||
_cogl_atlas_get_next_size (&map_width, &map_height);
|
||||
}
|
||||
|
||||
/* If we get here then there's no atlas that can accommodate all of
|
||||
the rectangles */
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static CoglHandle
|
||||
_cogl_atlas_create_texture (CoglAtlas *atlas,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
CoglHandle tex;
|
||||
|
||||
if ((atlas->flags & COGL_ATLAS_CLEAR_TEXTURE))
|
||||
{
|
||||
guint8 *clear_data;
|
||||
CoglBitmap *clear_bmp;
|
||||
int bpp = _cogl_get_format_bpp (atlas->texture_format);
|
||||
|
||||
/* Create a buffer of zeroes to initially clear the texture */
|
||||
clear_data = g_malloc0 (width * height * bpp);
|
||||
clear_bmp = _cogl_bitmap_new_from_data (clear_data,
|
||||
atlas->texture_format,
|
||||
width,
|
||||
height,
|
||||
width * bpp,
|
||||
(CoglBitmapDestroyNotify) g_free,
|
||||
NULL);
|
||||
|
||||
tex = _cogl_texture_2d_new_from_bitmap (clear_bmp, COGL_TEXTURE_NONE,
|
||||
atlas->texture_format);
|
||||
cogl_object_unref (clear_bmp);
|
||||
}
|
||||
else
|
||||
tex = _cogl_texture_2d_new_with_size (width, height, COGL_TEXTURE_NONE,
|
||||
atlas->texture_format);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
static int
|
||||
_cogl_atlas_compare_size_cb (const void *a,
|
||||
const void *b)
|
||||
{
|
||||
const CoglAtlasRepositionData *ta = a;
|
||||
const CoglAtlasRepositionData *tb = b;
|
||||
unsigned int a_size, b_size;
|
||||
|
||||
a_size = ta->old_position.width * ta->old_position.height;
|
||||
b_size = tb->old_position.width * tb->old_position.height;
|
||||
|
||||
return a_size < b_size ? 1 : a_size > b_size ? -1 : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_notify_pre_reorganize (CoglAtlas *atlas)
|
||||
{
|
||||
g_hook_list_invoke (&atlas->pre_reorganize_callbacks, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_atlas_notify_post_reorganize (CoglAtlas *atlas)
|
||||
{
|
||||
g_hook_list_invoke (&atlas->post_reorganize_callbacks, FALSE);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_atlas_reserve_space (CoglAtlas *atlas,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
void *user_data)
|
||||
{
|
||||
CoglAtlasGetRectanglesData data;
|
||||
CoglRectangleMap *new_map;
|
||||
CoglHandle new_tex;
|
||||
unsigned int map_width, map_height;
|
||||
gboolean ret;
|
||||
CoglRectangleMapEntry new_position;
|
||||
|
||||
/* Check if we can fit the rectangle into the existing map */
|
||||
if (atlas->map &&
|
||||
_cogl_rectangle_map_add (atlas->map, width, height,
|
||||
user_data,
|
||||
&new_position))
|
||||
{
|
||||
COGL_NOTE (ATLAS, "%p: Atlas is %ix%i, has %i textures and is %i%% waste",
|
||||
atlas,
|
||||
_cogl_rectangle_map_get_width (atlas->map),
|
||||
_cogl_rectangle_map_get_height (atlas->map),
|
||||
_cogl_rectangle_map_get_n_rectangles (atlas->map),
|
||||
/* waste as a percentage */
|
||||
_cogl_rectangle_map_get_remaining_space (atlas->map) *
|
||||
100 / (_cogl_rectangle_map_get_width (atlas->map) *
|
||||
_cogl_rectangle_map_get_height (atlas->map)));
|
||||
|
||||
atlas->update_position_cb (user_data,
|
||||
atlas->texture,
|
||||
&new_position);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* If we make it here then we need to reorganize the atlas. First
|
||||
we'll notify any users of the atlas that this is going to happen
|
||||
so that for example in CoglAtlasTexture it can notify that the
|
||||
storage has changed and cause a flush */
|
||||
_cogl_atlas_notify_pre_reorganize (atlas);
|
||||
|
||||
/* Get an array of all the textures currently in the atlas. */
|
||||
data.n_textures = 0;
|
||||
if (atlas->map == NULL)
|
||||
data.textures = g_malloc (sizeof (CoglAtlasRepositionData));
|
||||
else
|
||||
{
|
||||
unsigned int n_rectangles =
|
||||
_cogl_rectangle_map_get_n_rectangles (atlas->map);
|
||||
data.textures = g_malloc (sizeof (CoglAtlasRepositionData) *
|
||||
(n_rectangles + 1));
|
||||
_cogl_rectangle_map_foreach (atlas->map,
|
||||
_cogl_atlas_get_rectangles_cb,
|
||||
&data);
|
||||
}
|
||||
|
||||
/* Add the new rectangle as a dummy texture so that it can be
|
||||
positioned with the rest */
|
||||
data.textures[data.n_textures].old_position.x = 0;
|
||||
data.textures[data.n_textures].old_position.y = 0;
|
||||
data.textures[data.n_textures].old_position.width = width;
|
||||
data.textures[data.n_textures].old_position.height = height;
|
||||
data.textures[data.n_textures++].user_data = user_data;
|
||||
|
||||
/* The atlasing algorithm works a lot better if the rectangles are
|
||||
added in decreasing order of size so we'll first sort the
|
||||
array */
|
||||
qsort (data.textures, data.n_textures,
|
||||
sizeof (CoglAtlasRepositionData),
|
||||
_cogl_atlas_compare_size_cb);
|
||||
|
||||
/* Try to create a new atlas that can contain all of the textures */
|
||||
if (atlas->map)
|
||||
{
|
||||
map_width = _cogl_rectangle_map_get_width (atlas->map);
|
||||
map_height = _cogl_rectangle_map_get_height (atlas->map);
|
||||
|
||||
/* If there is enough space in for the new rectangle in the
|
||||
existing atlas with at least 6% waste we'll start with the
|
||||
same size, otherwise we'll immediately double it */
|
||||
if ((map_width * map_height -
|
||||
_cogl_rectangle_map_get_remaining_space (atlas->map) +
|
||||
width * height) * 53 / 50 >
|
||||
map_width * map_height)
|
||||
_cogl_atlas_get_next_size (&map_width, &map_height);
|
||||
}
|
||||
else
|
||||
_cogl_atlas_get_initial_size (atlas->texture_format,
|
||||
&map_width, &map_height);
|
||||
|
||||
new_map = _cogl_atlas_create_map (atlas->texture_format,
|
||||
map_width, map_height,
|
||||
data.n_textures, data.textures);
|
||||
|
||||
/* If we can't create a map with the texture then give up */
|
||||
if (new_map == NULL)
|
||||
{
|
||||
COGL_NOTE (ATLAS, "%p: Could not fit texture in the atlas", atlas);
|
||||
ret = FALSE;
|
||||
}
|
||||
/* We need to migrate the existing textures into a new texture */
|
||||
else if ((new_tex = _cogl_atlas_create_texture
|
||||
(atlas,
|
||||
_cogl_rectangle_map_get_width (new_map),
|
||||
_cogl_rectangle_map_get_height (new_map))) == COGL_INVALID_HANDLE)
|
||||
{
|
||||
COGL_NOTE (ATLAS, "%p: Could not create a CoglTexture2D", atlas);
|
||||
_cogl_rectangle_map_free (new_map);
|
||||
ret = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
int waste;
|
||||
|
||||
COGL_NOTE (ATLAS,
|
||||
"%p: Atlas %s with size %ix%i",
|
||||
atlas,
|
||||
atlas->map == NULL ||
|
||||
_cogl_rectangle_map_get_width (atlas->map) !=
|
||||
_cogl_rectangle_map_get_width (new_map) ||
|
||||
_cogl_rectangle_map_get_height (atlas->map) !=
|
||||
_cogl_rectangle_map_get_height (new_map) ?
|
||||
"resized" : "reorganized",
|
||||
_cogl_rectangle_map_get_width (new_map),
|
||||
_cogl_rectangle_map_get_height (new_map));
|
||||
|
||||
if (atlas->map)
|
||||
{
|
||||
/* Move all the textures to the right position in the new
|
||||
texture. This will also update the texture's rectangle */
|
||||
_cogl_atlas_migrate (atlas,
|
||||
data.n_textures,
|
||||
data.textures,
|
||||
atlas->texture,
|
||||
new_tex,
|
||||
user_data);
|
||||
_cogl_rectangle_map_free (atlas->map);
|
||||
cogl_handle_unref (atlas->texture);
|
||||
}
|
||||
else
|
||||
/* We know there's only one texture so we can just directly
|
||||
update the rectangle from its new position */
|
||||
atlas->update_position_cb (data.textures[0].user_data,
|
||||
new_tex,
|
||||
&data.textures[0].new_position);
|
||||
|
||||
atlas->map = new_map;
|
||||
atlas->texture = new_tex;
|
||||
|
||||
waste = (_cogl_rectangle_map_get_remaining_space (atlas->map) *
|
||||
100 / (_cogl_rectangle_map_get_width (atlas->map) *
|
||||
_cogl_rectangle_map_get_height (atlas->map)));
|
||||
|
||||
COGL_NOTE (ATLAS, "%p: Atlas is %ix%i, has %i textures and is %i%% waste",
|
||||
atlas,
|
||||
_cogl_rectangle_map_get_width (atlas->map),
|
||||
_cogl_rectangle_map_get_height (atlas->map),
|
||||
_cogl_rectangle_map_get_n_rectangles (atlas->map),
|
||||
waste);
|
||||
|
||||
ret = TRUE;
|
||||
}
|
||||
|
||||
g_free (data.textures);
|
||||
|
||||
_cogl_atlas_notify_post_reorganize (atlas);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_atlas_remove (CoglAtlas *atlas,
|
||||
const CoglRectangleMapEntry *rectangle)
|
||||
{
|
||||
_cogl_rectangle_map_remove (atlas->map, rectangle);
|
||||
|
||||
COGL_NOTE (ATLAS, "%p: Removed rectangle sized %ix%i",
|
||||
atlas,
|
||||
rectangle->width,
|
||||
rectangle->height);
|
||||
COGL_NOTE (ATLAS, "%p: Atlas is %ix%i, has %i textures and is %i%% waste",
|
||||
atlas,
|
||||
_cogl_rectangle_map_get_width (atlas->map),
|
||||
_cogl_rectangle_map_get_height (atlas->map),
|
||||
_cogl_rectangle_map_get_n_rectangles (atlas->map),
|
||||
_cogl_rectangle_map_get_remaining_space (atlas->map) *
|
||||
100 / (_cogl_rectangle_map_get_width (atlas->map) *
|
||||
_cogl_rectangle_map_get_height (atlas->map)));
|
||||
};
|
||||
|
||||
CoglHandle
|
||||
_cogl_atlas_copy_rectangle (CoglAtlas *atlas,
|
||||
unsigned int x,
|
||||
unsigned int y,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
CoglTextureFlags flags,
|
||||
CoglPixelFormat format)
|
||||
{
|
||||
CoglHandle tex;
|
||||
CoglBlitData blit_data;
|
||||
|
||||
/* Create a new texture at the right size */
|
||||
tex = cogl_texture_new_with_size (width, height, flags, format);
|
||||
|
||||
/* Blit the data out of the atlas to the new texture. If FBOs
|
||||
aren't available this will end up having to copy the entire
|
||||
atlas texture */
|
||||
_cogl_blit_begin (&blit_data, tex, atlas->texture);
|
||||
_cogl_blit (&blit_data,
|
||||
x, y,
|
||||
0, 0,
|
||||
width, height);
|
||||
_cogl_blit_end (&blit_data);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_atlas_add_reorganize_callback (CoglAtlas *atlas,
|
||||
GHookFunc pre_callback,
|
||||
GHookFunc post_callback,
|
||||
void *user_data)
|
||||
{
|
||||
if (pre_callback)
|
||||
{
|
||||
GHook *hook = g_hook_alloc (&atlas->post_reorganize_callbacks);
|
||||
hook->func = pre_callback;
|
||||
hook->data = user_data;
|
||||
g_hook_prepend (&atlas->pre_reorganize_callbacks, hook);
|
||||
}
|
||||
if (post_callback)
|
||||
{
|
||||
GHook *hook = g_hook_alloc (&atlas->pre_reorganize_callbacks);
|
||||
hook->func = post_callback;
|
||||
hook->data = user_data;
|
||||
g_hook_prepend (&atlas->post_reorganize_callbacks, hook);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_atlas_remove_reorganize_callback (CoglAtlas *atlas,
|
||||
GHookFunc pre_callback,
|
||||
GHookFunc post_callback,
|
||||
void *user_data)
|
||||
{
|
||||
if (pre_callback)
|
||||
{
|
||||
GHook *hook = g_hook_find_func_data (&atlas->pre_reorganize_callbacks,
|
||||
FALSE,
|
||||
pre_callback,
|
||||
user_data);
|
||||
if (hook)
|
||||
g_hook_destroy_link (&atlas->pre_reorganize_callbacks, hook);
|
||||
}
|
||||
if (post_callback)
|
||||
{
|
||||
GHook *hook = g_hook_find_func_data (&atlas->post_reorganize_callbacks,
|
||||
FALSE,
|
||||
post_callback,
|
||||
user_data);
|
||||
if (hook)
|
||||
g_hook_destroy_link (&atlas->post_reorganize_callbacks, hook);
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010,2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __COGL_ATLAS_H
|
||||
#define __COGL_ATLAS_H
|
||||
|
||||
#include "cogl-rectangle-map.h"
|
||||
#include "cogl-object-private.h"
|
||||
|
||||
typedef void
|
||||
(* CoglAtlasUpdatePositionCallback) (void *user_data,
|
||||
CoglHandle new_texture,
|
||||
const CoglRectangleMapEntry *rect);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COGL_ATLAS_CLEAR_TEXTURE = (1 << 0),
|
||||
COGL_ATLAS_DISABLE_MIGRATION = (1 << 1)
|
||||
} CoglAtlasFlags;
|
||||
|
||||
typedef struct _CoglAtlas CoglAtlas;
|
||||
|
||||
#define COGL_ATLAS(object) ((CoglAtlas *) object)
|
||||
|
||||
struct _CoglAtlas
|
||||
{
|
||||
CoglObject _parent;
|
||||
|
||||
CoglRectangleMap *map;
|
||||
|
||||
CoglHandle texture;
|
||||
CoglPixelFormat texture_format;
|
||||
CoglAtlasFlags flags;
|
||||
|
||||
CoglAtlasUpdatePositionCallback update_position_cb;
|
||||
|
||||
GHookList pre_reorganize_callbacks;
|
||||
GHookList post_reorganize_callbacks;
|
||||
};
|
||||
|
||||
CoglAtlas *
|
||||
_cogl_atlas_new (CoglPixelFormat texture_format,
|
||||
CoglAtlasFlags flags,
|
||||
CoglAtlasUpdatePositionCallback update_position_cb);
|
||||
|
||||
gboolean
|
||||
_cogl_atlas_reserve_space (CoglAtlas *atlas,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
void *user_data);
|
||||
|
||||
void
|
||||
_cogl_atlas_remove (CoglAtlas *atlas,
|
||||
const CoglRectangleMapEntry *rectangle);
|
||||
|
||||
CoglHandle
|
||||
_cogl_atlas_copy_rectangle (CoglAtlas *atlas,
|
||||
unsigned int x,
|
||||
unsigned int y,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
CoglTextureFlags flags,
|
||||
CoglPixelFormat format);
|
||||
|
||||
void
|
||||
_cogl_atlas_add_reorganize_callback (CoglAtlas *atlas,
|
||||
GHookFunc pre_callback,
|
||||
GHookFunc post_callback,
|
||||
void *user_data);
|
||||
|
||||
void
|
||||
_cogl_atlas_remove_reorganize_callback (CoglAtlas *atlas,
|
||||
GHookFunc pre_callback,
|
||||
GHookFunc post_callback,
|
||||
void *user_data);
|
||||
|
||||
#endif /* __COGL_ATLAS_H */
|
@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_ATTRIBUTE_PRIVATE_H
|
||||
#define __COGL_ATTRIBUTE_PRIVATE_H
|
||||
|
||||
#include "cogl-object-private.h"
|
||||
#include "cogl-attribute.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY,
|
||||
COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY,
|
||||
COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY,
|
||||
COGL_ATTRIBUTE_NAME_ID_NORMAL_ARRAY,
|
||||
COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY
|
||||
} CoglAttributeNameID;
|
||||
|
||||
struct _CoglAttribute
|
||||
{
|
||||
CoglObject _parent;
|
||||
|
||||
CoglVertexArray *array;
|
||||
char *name;
|
||||
CoglAttributeNameID name_id;
|
||||
gsize stride;
|
||||
gsize offset;
|
||||
int n_components;
|
||||
CoglAttributeType type;
|
||||
gboolean normalized;
|
||||
unsigned int texture_unit;
|
||||
|
||||
int immutable_ref;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COGL_DRAW_SKIP_JOURNAL_FLUSH = 1 << 0,
|
||||
COGL_DRAW_SKIP_PIPELINE_VALIDATION = 1 << 1,
|
||||
COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH = 1 << 2,
|
||||
/* When flushing from the journal the logged pipeline will already
|
||||
contain the legacy state overrides so we don't want to apply them
|
||||
again when we flush the pipeline for drawing */
|
||||
COGL_DRAW_SKIP_LEGACY_STATE = 1 << 3,
|
||||
/* By default the vertex attribute drawing code will assume that if
|
||||
there is a color attribute array enabled then we can't determine
|
||||
if the colors will be opaque so we need to enabling
|
||||
blending. However when drawing from the journal we know what the
|
||||
contents of the color array is so we can override this by passing
|
||||
this flag. */
|
||||
COGL_DRAW_COLOR_ATTRIBUTE_IS_OPAQUE = 1 << 4
|
||||
} CoglDrawFlags;
|
||||
|
||||
CoglAttribute *
|
||||
_cogl_attribute_immutable_ref (CoglAttribute *attribute);
|
||||
|
||||
void
|
||||
_cogl_attribute_immutable_unref (CoglAttribute *attribute);
|
||||
|
||||
void
|
||||
_cogl_draw_attributes_array (CoglVerticesMode mode,
|
||||
int first_vertex,
|
||||
int n_vertices,
|
||||
CoglAttribute **attributes,
|
||||
CoglDrawFlags flags);
|
||||
|
||||
void
|
||||
_cogl_draw_indexed_attributes_array (CoglVerticesMode mode,
|
||||
int first_vertex,
|
||||
int n_vertices,
|
||||
CoglIndices *indices,
|
||||
CoglAttribute **attributes,
|
||||
CoglDrawFlags flags);
|
||||
|
||||
void
|
||||
_cogl_attribute_disable_cached_arrays (void);
|
||||
|
||||
#endif /* __COGL_ATTRIBUTE_PRIVATE_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,182 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_ATTRIBUTE_H__
|
||||
#define __COGL_ATTRIBUTE_H__
|
||||
|
||||
#include <cogl/cogl-vertex-array.h>
|
||||
#include <cogl/cogl-indices.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-attribute
|
||||
* @short_description: Functions for declaring and drawing vertex
|
||||
* attributes
|
||||
*
|
||||
* FIXME
|
||||
*/
|
||||
|
||||
typedef struct _CoglAttribute CoglAttribute;
|
||||
|
||||
/**
|
||||
* cogl_attribute_new:
|
||||
* @array: The #CoglVertexArray containing the actual attribute data
|
||||
* @name: The name of the attribute (used to reference it from GLSL)
|
||||
* @stride: The number of bytes to jump to get to the next attribute
|
||||
* value for the next vertex. (Usually
|
||||
* <pre>sizeof (MyVertex)</pre>)
|
||||
* @offset: The byte offset from the start of @array for the first
|
||||
* attribute value. (Usually
|
||||
* <pre>offsetof (MyVertex, component0)</pre>
|
||||
* @components: The number of components (e.g. 4 for an rgba color or
|
||||
* 3 for and (x,y,z) position)
|
||||
* @type: FIXME
|
||||
*
|
||||
* Describes the layout for a list of vertex attribute values (For
|
||||
* example, a list of texture coordinates or colors).
|
||||
*
|
||||
* The @name is used to access the attribute inside a GLSL vertex
|
||||
* shader and there are some special names you should use if they are
|
||||
* applicable:
|
||||
* <itemizedlist>
|
||||
* <listitem>"cogl_position_in" (used for vertex positions)</listitem>
|
||||
* <listitem>"cogl_color_in" (used for vertex colors)</listitem>
|
||||
* <listitem>"cogl_tex_coord0_in", "cogl_tex_coord1", ...
|
||||
* (used for vertex texture coordinates)</listitem>
|
||||
* <listitem>"cogl_normal_in" (used for vertex normals)</listitem>
|
||||
* </itemizedlist>
|
||||
*
|
||||
* The attribute values corresponding to different vertices can either
|
||||
* be tightly packed or interleaved with other attribute values. For
|
||||
* example it's common to define a structure for a single vertex like:
|
||||
* |[
|
||||
* typedef struct
|
||||
* {
|
||||
* float x, y, z; /<!-- -->* position attribute *<!-- -->/
|
||||
* float s, t; /<!-- -->* texture coordinate attribute *<!-- -->/
|
||||
* } MyVertex;
|
||||
* ]|
|
||||
*
|
||||
* And then create an array of vertex data something like:
|
||||
* |[
|
||||
* MyVertex vertices[100] = { .... }
|
||||
* ]|
|
||||
*
|
||||
* In this case, to describe either the position or texture coordinate
|
||||
* attribute you have to move <pre>sizeof (MyVertex)</pre> bytes to
|
||||
* move from one vertex to the next. This is called the attribute
|
||||
* @stride. If you weren't interleving attributes and you instead had
|
||||
* a packed array of float x, y pairs then the attribute stride would
|
||||
* be <pre>(2 * sizeof (float))</pre>. So the @stride is the number of
|
||||
* bytes to move to find the attribute value of the next vertex.
|
||||
*
|
||||
* Normally a list of attributes starts at the beginning of an array.
|
||||
* So for the <pre>MyVertex</pre> example above the @offset is the
|
||||
* offset inside the <pre>MyVertex</pre> structure to the first
|
||||
* component of the attribute. For the texture coordinate attribute
|
||||
* the offset would be <pre>offsetof (MyVertex, s)</pre> or instead of
|
||||
* using the offsetof macro you could use <pre>sizeof (float) * 3</pre>.
|
||||
* If you've divided your @array into blocks of non-interleved
|
||||
* attributes then you will need to calculate the @offset as the
|
||||
* number of bytes in blocks preceding the attribute you're
|
||||
* describing.
|
||||
*
|
||||
* An attribute often has more than one component. For example a color
|
||||
* is often comprised of 4 red, green, blue and alpha @components, and a
|
||||
* position may be comprised of 2 x and y @components. You should aim
|
||||
* to keep the number of components to a minimum as more components
|
||||
* means more data needs to be mapped into the GPU which can be a
|
||||
* bottlneck when dealing with a large number of vertices.
|
||||
*
|
||||
* Finally you need to specify the component data type. Here you
|
||||
* should aim to use the smallest type that meets your precision
|
||||
* requirements. Again the larger the type then more data needs to be
|
||||
* mapped into the GPU which can be a bottlneck when dealing with
|
||||
* a large number of vertices.
|
||||
*
|
||||
* Returns: A newly allocated #CoglAttribute describing the
|
||||
* layout for a list of attribute values stored in @array.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
/* XXX: look for a precedent to see if the stride/offset args should
|
||||
* have a different order. */
|
||||
CoglAttribute *
|
||||
cogl_attribute_new (CoglVertexArray *array,
|
||||
const char *name,
|
||||
gsize stride,
|
||||
gsize offset,
|
||||
int components,
|
||||
CoglAttributeType type);
|
||||
|
||||
/**
|
||||
* cogl_is_attribute:
|
||||
* @object: A #CoglObject
|
||||
*
|
||||
* Gets whether the given object references a #CoglAttribute.
|
||||
*
|
||||
* Return value: %TRUE if the handle references a #CoglAttribute,
|
||||
* %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
cogl_is_attribute (void *object);
|
||||
|
||||
void
|
||||
cogl_draw_attributes (CoglVerticesMode mode,
|
||||
int first_vertex,
|
||||
int n_vertices,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
void
|
||||
cogl_draw_attributes_array (CoglVerticesMode mode,
|
||||
int first_vertex,
|
||||
int n_vertices,
|
||||
CoglAttribute **attributes);
|
||||
|
||||
void
|
||||
cogl_draw_indexed_attributes (CoglVerticesMode mode,
|
||||
int first_vertex,
|
||||
int n_vertices,
|
||||
CoglIndices *indices,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
void
|
||||
cogl_draw_indexed_attributes_array (CoglVerticesMode mode,
|
||||
int first_vertex,
|
||||
int n_vertices,
|
||||
CoglIndices *indices,
|
||||
CoglAttribute **attributes);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_ATTRIBUTE_H__ */
|
||||
|
@ -1,582 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-bitmap-private.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* TO rgba */
|
||||
|
||||
inline static void
|
||||
_cogl_g_to_rgba (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[0];
|
||||
dst[2] = src[0];
|
||||
dst[3] = 255;
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_rgb_to_rgba (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[2];
|
||||
dst[3] = 255;
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_bgr_to_rgba (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[2];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[0];
|
||||
dst[3] = 255;
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_bgra_to_rgba (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[2];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[0];
|
||||
dst[3] = src[3];
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_argb_to_rgba (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[1];
|
||||
dst[1] = src[2];
|
||||
dst[2] = src[3];
|
||||
dst[3] = src[0];
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_abgr_to_rgba (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[3];
|
||||
dst[1] = src[2];
|
||||
dst[2] = src[1];
|
||||
dst[3] = src[0];
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_rgba_to_rgba (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[2];
|
||||
dst[3] = src[3];
|
||||
}
|
||||
|
||||
/* FROM rgba */
|
||||
|
||||
inline static void
|
||||
_cogl_rgba_to_g (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = (src[0] + src[1] + src[2]) / 3;
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_rgba_to_rgb (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[2];
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_rgba_to_bgr (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[2];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[0];
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_rgba_to_bgra (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[2];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[0];
|
||||
dst[3] = src[3];
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_rgba_to_argb (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[3];
|
||||
dst[1] = src[0];
|
||||
dst[2] = src[1];
|
||||
dst[3] = src[2];
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_rgba_to_abgr (const guint8 *src, guint8 *dst)
|
||||
{
|
||||
dst[0] = src[3];
|
||||
dst[1] = src[2];
|
||||
dst[2] = src[1];
|
||||
dst[3] = src[0];
|
||||
}
|
||||
|
||||
/* (Un)Premultiplication */
|
||||
|
||||
inline static void
|
||||
_cogl_unpremult_alpha_0 (guint8 *dst)
|
||||
{
|
||||
dst[0] = 0;
|
||||
dst[1] = 0;
|
||||
dst[2] = 0;
|
||||
dst[3] = 0;
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_unpremult_alpha_last (guint8 *dst)
|
||||
{
|
||||
guint8 alpha = dst[3];
|
||||
|
||||
dst[0] = (dst[0] * 255) / alpha;
|
||||
dst[1] = (dst[1] * 255) / alpha;
|
||||
dst[2] = (dst[2] * 255) / alpha;
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_unpremult_alpha_first (guint8 *dst)
|
||||
{
|
||||
guint8 alpha = dst[0];
|
||||
|
||||
dst[1] = (dst[1] * 255) / alpha;
|
||||
dst[2] = (dst[2] * 255) / alpha;
|
||||
dst[3] = (dst[3] * 255) / alpha;
|
||||
}
|
||||
|
||||
/* No division form of floor((c*a + 128)/255) (I first encountered
|
||||
* this in the RENDER implementation in the X server.) Being exact
|
||||
* is important for a == 255 - we want to get exactly c.
|
||||
*/
|
||||
#define MULT(d,a,t) \
|
||||
G_STMT_START { \
|
||||
t = d * a + 128; \
|
||||
d = ((t >> 8) + t) >> 8; \
|
||||
} G_STMT_END
|
||||
|
||||
inline static void
|
||||
_cogl_premult_alpha_last (guint8 *dst)
|
||||
{
|
||||
guint8 alpha = dst[3];
|
||||
/* Using a separate temporary per component has given slightly better
|
||||
* code generation with GCC in the past; it shouldn't do any worse in
|
||||
* any case.
|
||||
*/
|
||||
unsigned int t1, t2, t3;
|
||||
MULT(dst[0], alpha, t1);
|
||||
MULT(dst[1], alpha, t2);
|
||||
MULT(dst[2], alpha, t3);
|
||||
}
|
||||
|
||||
inline static void
|
||||
_cogl_premult_alpha_first (guint8 *dst)
|
||||
{
|
||||
guint8 alpha = dst[0];
|
||||
unsigned int t1, t2, t3;
|
||||
|
||||
MULT(dst[1], alpha, t1);
|
||||
MULT(dst[2], alpha, t2);
|
||||
MULT(dst[3], alpha, t3);
|
||||
}
|
||||
|
||||
#undef MULT
|
||||
|
||||
/* Use the SSE optimized version to premult four pixels at once when
|
||||
it is available. The same assembler code works for x86 and x86-64
|
||||
because it doesn't refer to any non-SSE registers directly */
|
||||
#if defined(__SSE2__) && defined(__GNUC__) \
|
||||
&& (defined(__x86_64) || defined(__i386))
|
||||
#define COGL_USE_PREMULT_SSE2
|
||||
#endif
|
||||
|
||||
#ifdef COGL_USE_PREMULT_SSE2
|
||||
|
||||
inline static void
|
||||
_cogl_premult_alpha_last_four_pixels_sse2 (guint8 *p)
|
||||
{
|
||||
/* 8 copies of 128 used below */
|
||||
static const gint16 eight_halves[8] __attribute__ ((aligned (16))) =
|
||||
{ 128, 128, 128, 128, 128, 128, 128, 128 };
|
||||
/* Mask of the rgb components of the four pixels */
|
||||
static const gint8 just_rgb[16] __attribute__ ((aligned (16))) =
|
||||
{ 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
|
||||
0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00 };
|
||||
/* Each SSE register only holds two pixels because we need to work
|
||||
with 16-bit intermediate values. We still do four pixels by
|
||||
interleaving two registers in the hope that it will pipeline
|
||||
better */
|
||||
asm (/* Load eight_halves into xmm5 for later */
|
||||
"movdqa (%1), %%xmm5\n"
|
||||
/* Clear xmm3 */
|
||||
"pxor %%xmm3, %%xmm3\n"
|
||||
/* Load two pixels from p into the low half of xmm0 */
|
||||
"movlps (%0), %%xmm0\n"
|
||||
/* Load the next set of two pixels from p into the low half of xmm1 */
|
||||
"movlps 8(%0), %%xmm1\n"
|
||||
/* Unpack 8 bytes from the low quad-words in each register to 8
|
||||
16-bit values */
|
||||
"punpcklbw %%xmm3, %%xmm0\n"
|
||||
"punpcklbw %%xmm3, %%xmm1\n"
|
||||
/* Copy alpha values of the first pixel in xmm0 to all
|
||||
components of the first pixel in xmm2 */
|
||||
"pshuflw $255, %%xmm0, %%xmm2\n"
|
||||
/* same for xmm1 and xmm3 */
|
||||
"pshuflw $255, %%xmm1, %%xmm3\n"
|
||||
/* The above also copies the second pixel directly so we now
|
||||
want to replace the RGB components with copies of the alpha
|
||||
components */
|
||||
"pshufhw $255, %%xmm2, %%xmm2\n"
|
||||
"pshufhw $255, %%xmm3, %%xmm3\n"
|
||||
/* Multiply the rgb components by the alpha */
|
||||
"pmullw %%xmm2, %%xmm0\n"
|
||||
"pmullw %%xmm3, %%xmm1\n"
|
||||
/* Add 128 to each component */
|
||||
"paddw %%xmm5, %%xmm0\n"
|
||||
"paddw %%xmm5, %%xmm1\n"
|
||||
/* Copy the results to temporary registers xmm4 and xmm5 */
|
||||
"movdqa %%xmm0, %%xmm4\n"
|
||||
"movdqa %%xmm1, %%xmm5\n"
|
||||
/* Divide the results by 256 */
|
||||
"psrlw $8, %%xmm0\n"
|
||||
"psrlw $8, %%xmm1\n"
|
||||
/* Add the temporaries back in */
|
||||
"paddw %%xmm4, %%xmm0\n"
|
||||
"paddw %%xmm5, %%xmm1\n"
|
||||
/* Divide again */
|
||||
"psrlw $8, %%xmm0\n"
|
||||
"psrlw $8, %%xmm1\n"
|
||||
/* Pack the results back as bytes */
|
||||
"packuswb %%xmm1, %%xmm0\n"
|
||||
/* Load just_rgb into xmm3 for later */
|
||||
"movdqa (%2), %%xmm3\n"
|
||||
/* Reload all four pixels into xmm2 */
|
||||
"movups (%0), %%xmm2\n"
|
||||
/* Mask out the alpha from the results */
|
||||
"andps %%xmm3, %%xmm0\n"
|
||||
/* Mask out the RGB from the original four pixels */
|
||||
"andnps %%xmm2, %%xmm3\n"
|
||||
/* Combine the two to get the right alpha values */
|
||||
"orps %%xmm3, %%xmm0\n"
|
||||
/* Write to memory */
|
||||
"movdqu %%xmm0, (%0)\n"
|
||||
: /* no outputs */
|
||||
: "r" (p), "r" (eight_halves), "r" (just_rgb)
|
||||
: "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5");
|
||||
}
|
||||
|
||||
#endif /* COGL_USE_PREMULT_SSE2 */
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_fallback_can_convert (CoglPixelFormat src, CoglPixelFormat dst)
|
||||
{
|
||||
if (src == dst)
|
||||
return FALSE;
|
||||
|
||||
switch (src & COGL_UNORDERED_MASK)
|
||||
{
|
||||
case COGL_PIXEL_FORMAT_G_8:
|
||||
case COGL_PIXEL_FORMAT_24:
|
||||
case COGL_PIXEL_FORMAT_32:
|
||||
|
||||
if ((dst & COGL_UNORDERED_MASK) != COGL_PIXEL_FORMAT_24 &&
|
||||
(dst & COGL_UNORDERED_MASK) != COGL_PIXEL_FORMAT_32 &&
|
||||
(dst & COGL_UNORDERED_MASK) != COGL_PIXEL_FORMAT_G_8)
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_fallback_can_unpremult (CoglPixelFormat format)
|
||||
{
|
||||
return ((format & COGL_UNORDERED_MASK) == COGL_PIXEL_FORMAT_32);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_fallback_can_premult (CoglPixelFormat format)
|
||||
{
|
||||
return ((format & COGL_UNORDERED_MASK) == COGL_PIXEL_FORMAT_32);
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_fallback_convert (CoglBitmap *src_bmp,
|
||||
CoglPixelFormat dst_format)
|
||||
{
|
||||
guint8 *src_data;
|
||||
guint8 *dst_data;
|
||||
guint8 *src;
|
||||
guint8 *dst;
|
||||
int src_bpp;
|
||||
int dst_bpp;
|
||||
int src_rowstride;
|
||||
int dst_rowstride;
|
||||
int x,y;
|
||||
guint8 temp_rgba[4] = {0,0,0,0};
|
||||
int width, height;
|
||||
CoglPixelFormat src_format;
|
||||
|
||||
src_format = _cogl_bitmap_get_format (src_bmp);
|
||||
src_rowstride = _cogl_bitmap_get_rowstride (src_bmp);
|
||||
width = _cogl_bitmap_get_width (src_bmp);
|
||||
height = _cogl_bitmap_get_height (src_bmp);
|
||||
|
||||
/* Make sure conversion supported */
|
||||
if (!_cogl_bitmap_fallback_can_convert (src_format, dst_format))
|
||||
return NULL;
|
||||
|
||||
src_data = _cogl_bitmap_map (src_bmp, COGL_BUFFER_ACCESS_READ, 0);
|
||||
if (src_data == NULL)
|
||||
return NULL;
|
||||
|
||||
src_bpp = _cogl_get_format_bpp (src_format);
|
||||
dst_bpp = _cogl_get_format_bpp (dst_format);
|
||||
|
||||
/* Initialize destination bitmap */
|
||||
dst_rowstride = sizeof(guint8) * dst_bpp * width;
|
||||
/* Copy the premult bit if the new format has an alpha channel */
|
||||
if ((dst_format & COGL_A_BIT))
|
||||
dst_format = ((src_format & COGL_PREMULT_BIT) |
|
||||
(dst_format & COGL_UNPREMULT_MASK));
|
||||
|
||||
/* Allocate a new buffer to hold converted data */
|
||||
dst_data = g_malloc (height * dst_rowstride);
|
||||
|
||||
/* FIXME: Optimize */
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
src = src_data + y * src_rowstride;
|
||||
dst = dst_data + y * dst_rowstride;
|
||||
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
/* FIXME: Would be nice to at least remove this inner
|
||||
* branching, but not sure it can be done without
|
||||
* rewriting of the whole loop */
|
||||
switch (src_format & COGL_UNPREMULT_MASK)
|
||||
{
|
||||
case COGL_PIXEL_FORMAT_G_8:
|
||||
_cogl_g_to_rgba (src, temp_rgba); break;
|
||||
case COGL_PIXEL_FORMAT_RGB_888:
|
||||
_cogl_rgb_to_rgba (src, temp_rgba); break;
|
||||
case COGL_PIXEL_FORMAT_BGR_888:
|
||||
_cogl_bgr_to_rgba (src, temp_rgba); break;
|
||||
case COGL_PIXEL_FORMAT_RGBA_8888:
|
||||
_cogl_rgba_to_rgba (src, temp_rgba); break;
|
||||
case COGL_PIXEL_FORMAT_BGRA_8888:
|
||||
_cogl_bgra_to_rgba (src, temp_rgba); break;
|
||||
case COGL_PIXEL_FORMAT_ARGB_8888:
|
||||
_cogl_argb_to_rgba (src, temp_rgba); break;
|
||||
case COGL_PIXEL_FORMAT_ABGR_8888:
|
||||
_cogl_abgr_to_rgba (src, temp_rgba); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (dst_format & COGL_UNPREMULT_MASK)
|
||||
{
|
||||
case COGL_PIXEL_FORMAT_G_8:
|
||||
_cogl_rgba_to_g (temp_rgba, dst); break;
|
||||
case COGL_PIXEL_FORMAT_RGB_888:
|
||||
_cogl_rgba_to_rgb (temp_rgba, dst); break;
|
||||
case COGL_PIXEL_FORMAT_BGR_888:
|
||||
_cogl_rgba_to_bgr (temp_rgba, dst); break;
|
||||
case COGL_PIXEL_FORMAT_RGBA_8888:
|
||||
_cogl_rgba_to_rgba (temp_rgba, dst); break;
|
||||
case COGL_PIXEL_FORMAT_BGRA_8888:
|
||||
_cogl_rgba_to_bgra (temp_rgba, dst); break;
|
||||
case COGL_PIXEL_FORMAT_ARGB_8888:
|
||||
_cogl_rgba_to_argb (temp_rgba, dst); break;
|
||||
case COGL_PIXEL_FORMAT_ABGR_8888:
|
||||
_cogl_rgba_to_abgr (temp_rgba, dst); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
src += src_bpp;
|
||||
dst += dst_bpp;
|
||||
}
|
||||
}
|
||||
|
||||
_cogl_bitmap_unmap (src_bmp);
|
||||
|
||||
return _cogl_bitmap_new_from_data (dst_data,
|
||||
dst_format,
|
||||
width, height, dst_rowstride,
|
||||
(CoglBitmapDestroyNotify) g_free,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_fallback_unpremult (CoglBitmap *bmp)
|
||||
{
|
||||
guint8 *p, *data;
|
||||
int x,y;
|
||||
CoglPixelFormat format;
|
||||
int width, height;
|
||||
int rowstride;
|
||||
|
||||
format = _cogl_bitmap_get_format (bmp);
|
||||
width = _cogl_bitmap_get_width (bmp);
|
||||
height = _cogl_bitmap_get_height (bmp);
|
||||
rowstride = _cogl_bitmap_get_rowstride (bmp);
|
||||
|
||||
/* Make sure format supported for un-premultiplication */
|
||||
if (!_cogl_bitmap_fallback_can_unpremult (format))
|
||||
return FALSE;
|
||||
|
||||
if ((data = _cogl_bitmap_map (bmp,
|
||||
COGL_BUFFER_ACCESS_READ |
|
||||
COGL_BUFFER_ACCESS_WRITE,
|
||||
0)) == NULL)
|
||||
return FALSE;
|
||||
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
p = (guint8*) data + y * rowstride;
|
||||
|
||||
if (format & COGL_AFIRST_BIT)
|
||||
{
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
if (p[0] == 0)
|
||||
_cogl_unpremult_alpha_0 (p);
|
||||
else
|
||||
_cogl_unpremult_alpha_first (p);
|
||||
p += 4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
if (p[3] == 0)
|
||||
_cogl_unpremult_alpha_0 (p);
|
||||
else
|
||||
_cogl_unpremult_alpha_last (p);
|
||||
p += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_cogl_bitmap_unmap (bmp);
|
||||
|
||||
_cogl_bitmap_set_format (bmp, format & ~COGL_PREMULT_BIT);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_fallback_premult (CoglBitmap *bmp)
|
||||
{
|
||||
guint8 *p, *data;
|
||||
int x,y;
|
||||
CoglPixelFormat format;
|
||||
int width, height;
|
||||
int rowstride;
|
||||
|
||||
format = _cogl_bitmap_get_format (bmp);
|
||||
width = _cogl_bitmap_get_width (bmp);
|
||||
height = _cogl_bitmap_get_height (bmp);
|
||||
rowstride = _cogl_bitmap_get_rowstride (bmp);
|
||||
|
||||
/* Make sure format supported for un-premultiplication */
|
||||
if (!_cogl_bitmap_fallback_can_premult (format))
|
||||
return FALSE;
|
||||
|
||||
if ((data = _cogl_bitmap_map (bmp,
|
||||
COGL_BUFFER_ACCESS_READ |
|
||||
COGL_BUFFER_ACCESS_WRITE,
|
||||
0)) == NULL)
|
||||
return FALSE;
|
||||
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
p = (guint8*) data + y * rowstride;
|
||||
|
||||
if (format & COGL_AFIRST_BIT)
|
||||
{
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
_cogl_premult_alpha_first (p);
|
||||
p += 4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x = width;
|
||||
|
||||
#ifdef COGL_USE_PREMULT_SSE2
|
||||
|
||||
/* Process 4 pixels at a time */
|
||||
while (x >= 4)
|
||||
{
|
||||
_cogl_premult_alpha_last_four_pixels_sse2 (p);
|
||||
p += 4 * 4;
|
||||
x -= 4;
|
||||
}
|
||||
|
||||
/* If there are any pixels left we will fall through and
|
||||
handle them below */
|
||||
|
||||
#endif /* COGL_USE_PREMULT_SSE2 */
|
||||
|
||||
while (x-- > 0)
|
||||
{
|
||||
_cogl_premult_alpha_last (p);
|
||||
p += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_cogl_bitmap_unmap (bmp);
|
||||
|
||||
_cogl_bitmap_set_format (bmp, format | COGL_PREMULT_BIT);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_fallback_from_file (const char *filename)
|
||||
{
|
||||
/* FIXME: use jpeglib, libpng, etc. manually maybe */
|
||||
return FALSE;
|
||||
}
|
@ -1,331 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-bitmap-private.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef USE_QUARTZ
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#elif defined(USE_GDKPIXBUF)
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#endif
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_can_unpremult (CoglPixelFormat format)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_can_premult (CoglPixelFormat format)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_convert (CoglBitmap *bmp,
|
||||
CoglPixelFormat dst_format)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_unpremult (CoglBitmap *dst_bmp)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_premult (CoglBitmap *dst_bmp)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef USE_QUARTZ
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_get_size_from_file (const char *filename,
|
||||
int *width,
|
||||
int *height)
|
||||
{
|
||||
if (width)
|
||||
*width = 0;
|
||||
|
||||
if (height)
|
||||
*height = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* the error does not contain the filename as the caller already has it */
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_from_file (const char *filename,
|
||||
GError **error)
|
||||
{
|
||||
CFURLRef url;
|
||||
CGImageSourceRef image_source;
|
||||
CGImageRef image;
|
||||
int save_errno;
|
||||
CFStringRef type;
|
||||
gsize width, height, rowstride;
|
||||
guint8 *out_data;
|
||||
CGColorSpaceRef color_space;
|
||||
CGContextRef bitmap_context;
|
||||
|
||||
g_assert (filename != NULL);
|
||||
g_assert (error == NULL || *error == NULL);
|
||||
|
||||
url = CFURLCreateFromFileSystemRepresentation (NULL,
|
||||
(guchar *) filename,
|
||||
strlen (filename),
|
||||
false);
|
||||
image_source = CGImageSourceCreateWithURL (url, NULL);
|
||||
save_errno = errno;
|
||||
CFRelease (url);
|
||||
|
||||
if (image_source == NULL)
|
||||
{
|
||||
/* doesn't exist, not readable, etc. */
|
||||
g_set_error_literal (error,
|
||||
COGL_BITMAP_ERROR,
|
||||
COGL_BITMAP_ERROR_FAILED,
|
||||
g_strerror (save_errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Unknown images would be cleanly caught as zero width/height below, but try
|
||||
* to provide better error message
|
||||
*/
|
||||
type = CGImageSourceGetType (image_source);
|
||||
if (type == NULL)
|
||||
{
|
||||
CFRelease (image_source);
|
||||
g_set_error_literal (error,
|
||||
COGL_BITMAP_ERROR,
|
||||
COGL_BITMAP_ERROR_UNKNOWN_TYPE,
|
||||
"Unknown image type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CFRelease (type);
|
||||
|
||||
image = CGImageSourceCreateImageAtIndex (image_source, 0, NULL);
|
||||
CFRelease (image_source);
|
||||
|
||||
width = CGImageGetWidth (image);
|
||||
height = CGImageGetHeight (image);
|
||||
if (width == 0 || height == 0)
|
||||
{
|
||||
/* incomplete or corrupt */
|
||||
CFRelease (image);
|
||||
g_set_error_literal (error,
|
||||
COGL_BITMAP_ERROR,
|
||||
COGL_BITMAP_ERROR_CORRUPT_IMAGE,
|
||||
"Image has zero width or height");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* allocate buffer big enough to hold pixel data */
|
||||
rowstride = 4 * width;
|
||||
out_data = g_malloc0 (height * rowstride);
|
||||
|
||||
/* render to buffer */
|
||||
color_space = CGColorSpaceCreateWithName (kCGColorSpaceGenericRGB);
|
||||
bitmap_context = CGBitmapContextCreate (out_data,
|
||||
width, height, 8,
|
||||
rowstride, color_space,
|
||||
kCGImageAlphaPremultipliedFirst);
|
||||
CGColorSpaceRelease (color_space);
|
||||
|
||||
{
|
||||
const CGRect rect = {{0, 0}, {width, height}};
|
||||
|
||||
CGContextDrawImage (bitmap_context, rect, image);
|
||||
}
|
||||
|
||||
CGImageRelease (image);
|
||||
CGContextRelease (bitmap_context);
|
||||
|
||||
/* store bitmap info */
|
||||
return _cogl_bitmap_new_from_data (out_data,
|
||||
COGL_PIXEL_FORMAT_ARGB_8888,
|
||||
width, height,
|
||||
rowstride,
|
||||
(CoglBitmapDestroyNotify) g_free,
|
||||
NULL);
|
||||
}
|
||||
|
||||
#elif defined(USE_GDKPIXBUF)
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_get_size_from_file (const char *filename,
|
||||
int *width,
|
||||
int *height)
|
||||
{
|
||||
g_return_val_if_fail (filename != NULL, FALSE);
|
||||
|
||||
if (gdk_pixbuf_get_file_info (filename, width, height) != NULL)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_bitmap_unref_pixbuf (guint8 *pixels,
|
||||
void *pixbuf)
|
||||
{
|
||||
g_object_unref (pixbuf);
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_from_file (const char *filename,
|
||||
GError **error)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
gboolean has_alpha;
|
||||
GdkColorspace color_space;
|
||||
CoglPixelFormat pixel_format;
|
||||
int width;
|
||||
int height;
|
||||
int rowstride;
|
||||
int bits_per_sample;
|
||||
int n_channels;
|
||||
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
/* Load from file using GdkPixbuf */
|
||||
pixbuf = gdk_pixbuf_new_from_file (filename, error);
|
||||
if (pixbuf == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* Get pixbuf properties */
|
||||
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
|
||||
color_space = gdk_pixbuf_get_colorspace (pixbuf);
|
||||
width = gdk_pixbuf_get_width (pixbuf);
|
||||
height = gdk_pixbuf_get_height (pixbuf);
|
||||
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
||||
bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf);
|
||||
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
|
||||
|
||||
/* According to current docs this should be true and so
|
||||
* the translation to cogl pixel format below valid */
|
||||
g_assert (bits_per_sample == 8);
|
||||
|
||||
if (has_alpha)
|
||||
g_assert (n_channels == 4);
|
||||
else
|
||||
g_assert (n_channels == 3);
|
||||
|
||||
/* Translate to cogl pixel format */
|
||||
switch (color_space)
|
||||
{
|
||||
case GDK_COLORSPACE_RGB:
|
||||
/* The only format supported by GdkPixbuf so far */
|
||||
pixel_format = has_alpha ?
|
||||
COGL_PIXEL_FORMAT_RGBA_8888 :
|
||||
COGL_PIXEL_FORMAT_RGB_888;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Ouch, spec changed! */
|
||||
g_object_unref (pixbuf);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* We just use the data directly from the pixbuf so that we don't
|
||||
have to copy to a seperate buffer. Note that Cogl is expected not
|
||||
to read past the end of bpp*width on the last row even if the
|
||||
rowstride is much larger so we don't need to worry about
|
||||
GdkPixbuf's semantics that it may under-allocate the buffer. */
|
||||
return _cogl_bitmap_new_from_data (gdk_pixbuf_get_pixels (pixbuf),
|
||||
pixel_format,
|
||||
width,
|
||||
height,
|
||||
rowstride,
|
||||
_cogl_bitmap_unref_pixbuf,
|
||||
pixbuf);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "stb_image.c"
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_get_size_from_file (const char *filename,
|
||||
int *width,
|
||||
int *height)
|
||||
{
|
||||
if (width)
|
||||
*width = 0;
|
||||
|
||||
if (height)
|
||||
*height = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_from_file (const char *filename,
|
||||
GError **error)
|
||||
{
|
||||
CoglBitmap *bmp;
|
||||
int stb_pixel_format;
|
||||
int width;
|
||||
int height;
|
||||
guint8 *pixels;
|
||||
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
/* Load from file using stb */
|
||||
pixels = stbi_load (filename,
|
||||
&width, &height, &stb_pixel_format,
|
||||
STBI_rgb_alpha);
|
||||
if (pixels == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* Store bitmap info */
|
||||
bmp = _cogl_bitmap_new_from_data (g_memdup (pixels, height * width * 4),
|
||||
COGL_PIXEL_FORMAT_RGBA_8888,
|
||||
width, height,
|
||||
width * 4,
|
||||
(CoglBitmapDestroyNotify) g_free,
|
||||
NULL);
|
||||
|
||||
free (pixels);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
#endif
|
@ -1,214 +0,0 @@
|
||||
/*
|
||||
* Clutter COGL
|
||||
*
|
||||
* A basic GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* Copyright (C) 2007 OpenedHand
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_BITMAP_H
|
||||
#define __COGL_BITMAP_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-buffer.h"
|
||||
#include "cogl-bitmap.h"
|
||||
|
||||
/*
|
||||
* CoglBitmapDestroyNotify:
|
||||
* @data: The image data
|
||||
* @destroy_data: The callback closure data that was given to
|
||||
* _cogl_bitmap_new_from_data().
|
||||
*
|
||||
* Function prototype that is used to destroy the bitmap data when
|
||||
* _cogl_bitmap_new_from_data() is called.
|
||||
*/
|
||||
typedef void (* CoglBitmapDestroyNotify) (guint8 *data, void *destroy_data);
|
||||
|
||||
/*
|
||||
* _cogl_bitmap_new_from_data:
|
||||
* @data: A pointer to the data. The bitmap will take ownership of this data.
|
||||
* @format: The format of the pixel data.
|
||||
* @width: The width of the bitmap.
|
||||
* @height: The height of the bitmap.
|
||||
* @rowstride: The rowstride of the bitmap (the number of bytes from
|
||||
* the start of one row of the bitmap to the next).
|
||||
* @destroy_fn: A function to be called when the bitmap is
|
||||
* destroyed. This should free @data. %NULL can be used instead if
|
||||
* no free is needed.
|
||||
* @destroy_fn_data: This pointer will get passed to @destroy_fn.
|
||||
*
|
||||
* Creates a bitmap using some existing data. The data is not copied
|
||||
* so the bitmap will take ownership of the data pointer. When the
|
||||
* bitmap is freed @destroy_fn will be called to free the data.
|
||||
*
|
||||
* Return value: A new %CoglBitmap.
|
||||
*/
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_new_from_data (guint8 *data,
|
||||
CoglPixelFormat format,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride,
|
||||
CoglBitmapDestroyNotify destroy_fn,
|
||||
gpointer destroy_fn_data);
|
||||
|
||||
/* The idea of this function is that it will create a bitmap that
|
||||
shares the actual data with another bitmap. This is needed for the
|
||||
atlas texture backend because it needs upload a bitmap to a sub
|
||||
texture but override the format so that it ignores the premult
|
||||
flag. */
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_new_shared (CoglBitmap *shared_bmp,
|
||||
CoglPixelFormat format,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride);
|
||||
|
||||
/* This creates a cogl bitmap that internally references a pixel
|
||||
array. The data is not copied. _cogl_bitmap_map will divert to
|
||||
mapping the pixel array */
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
|
||||
CoglPixelFormat format,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride,
|
||||
int offset);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_fallback_can_convert (CoglPixelFormat src, CoglPixelFormat dst);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_can_unpremult (CoglPixelFormat format);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_fallback_can_unpremult (CoglPixelFormat format);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_can_premult (CoglPixelFormat format);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_fallback_can_premult (CoglPixelFormat format);
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_convert (CoglBitmap *bmp,
|
||||
CoglPixelFormat dst_format);
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_fallback_convert (CoglBitmap *bmp,
|
||||
CoglPixelFormat dst_format);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_unpremult (CoglBitmap *dst_bmp);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_fallback_unpremult (CoglBitmap *dst_bmp);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_premult (CoglBitmap *dst_bmp);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_fallback_premult (CoglBitmap *dst_bmp);
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_from_file (const char *filename,
|
||||
GError **error);
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_fallback_from_file (const char *filename);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_convert_premult_status (CoglBitmap *bmp,
|
||||
CoglPixelFormat dst_format);
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_convert_format_and_premult (CoglBitmap *bmp,
|
||||
CoglPixelFormat dst_format);
|
||||
|
||||
void
|
||||
_cogl_bitmap_copy_subregion (CoglBitmap *src,
|
||||
CoglBitmap *dst,
|
||||
int src_x,
|
||||
int src_y,
|
||||
int dst_x,
|
||||
int dst_y,
|
||||
int width,
|
||||
int height);
|
||||
|
||||
/* Creates a deep copy of the source bitmap */
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_copy (CoglBitmap *src_bmp);
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_get_size_from_file (const char *filename,
|
||||
int *width,
|
||||
int *height);
|
||||
|
||||
CoglPixelFormat
|
||||
_cogl_bitmap_get_format (CoglBitmap *bitmap);
|
||||
|
||||
void
|
||||
_cogl_bitmap_set_format (CoglBitmap *bitmap,
|
||||
CoglPixelFormat format);
|
||||
|
||||
int
|
||||
_cogl_bitmap_get_width (CoglBitmap *bitmap);
|
||||
|
||||
int
|
||||
_cogl_bitmap_get_height (CoglBitmap *bitmap);
|
||||
|
||||
int
|
||||
_cogl_bitmap_get_rowstride (CoglBitmap *bitmap);
|
||||
|
||||
/* Maps the bitmap so that the pixels can be accessed directly or if
|
||||
the bitmap is just a memory bitmap then it just returns the pointer
|
||||
to memory. Note that the bitmap isn't guaranteed to allocated to
|
||||
the full size of rowstride*height so it is not safe to read up to
|
||||
the rowstride of the last row. This will be the case if the user
|
||||
uploads data using gdk_pixbuf_new_subpixbuf with a sub region
|
||||
containing the last row of the pixbuf because in that case the
|
||||
rowstride can be much larger than the width of the image */
|
||||
guint8 *
|
||||
_cogl_bitmap_map (CoglBitmap *bitmap,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints);
|
||||
|
||||
void
|
||||
_cogl_bitmap_unmap (CoglBitmap *bitmap);
|
||||
|
||||
/* These two are replacements for map and unmap that should used when
|
||||
the pointer is going to be passed to GL for pixel packing or
|
||||
unpacking. The address might not be valid for reading if the bitmap
|
||||
was created with new_from_buffer but it will however be good to
|
||||
pass to glTexImage2D for example. The access should be READ for
|
||||
unpacking and WRITE for packing. It can not be both */
|
||||
guint8 *
|
||||
_cogl_bitmap_bind (CoglBitmap *bitmap,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints);
|
||||
|
||||
void
|
||||
_cogl_bitmap_unbind (CoglBitmap *bitmap);
|
||||
|
||||
#endif /* __COGL_BITMAP_H */
|
@ -1,498 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-debug.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-bitmap-private.h"
|
||||
#include "cogl-buffer-private.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
struct _CoglBitmap
|
||||
{
|
||||
CoglHandleObject _parent;
|
||||
CoglPixelFormat format;
|
||||
int width;
|
||||
int height;
|
||||
int rowstride;
|
||||
|
||||
guint8 *data;
|
||||
CoglBitmapDestroyNotify destroy_fn;
|
||||
void *destroy_fn_data;
|
||||
|
||||
gboolean mapped;
|
||||
gboolean bound;
|
||||
|
||||
/* If this is non-null then 'data' is ignored and instead it is
|
||||
fetched from this shared bitmap. */
|
||||
CoglBitmap *shared_bmp;
|
||||
|
||||
/* If this is non-null then 'data' is treated as an offset into the
|
||||
buffer and map will divert to mapping the buffer */
|
||||
CoglBuffer *buffer;
|
||||
};
|
||||
|
||||
static void _cogl_bitmap_free (CoglBitmap *bmp);
|
||||
|
||||
COGL_OBJECT_DEFINE (Bitmap, bitmap);
|
||||
|
||||
static void
|
||||
_cogl_bitmap_free (CoglBitmap *bmp)
|
||||
{
|
||||
g_assert (!bmp->mapped);
|
||||
g_assert (!bmp->bound);
|
||||
|
||||
if (bmp->destroy_fn)
|
||||
bmp->destroy_fn (bmp->data, bmp->destroy_fn_data);
|
||||
|
||||
if (bmp->shared_bmp)
|
||||
cogl_object_unref (bmp->shared_bmp);
|
||||
|
||||
if (bmp->buffer)
|
||||
cogl_object_unref (bmp->buffer);
|
||||
|
||||
g_slice_free (CoglBitmap, bmp);
|
||||
}
|
||||
|
||||
int
|
||||
_cogl_get_format_bpp (CoglPixelFormat format)
|
||||
{
|
||||
int bpp_lut[] = {
|
||||
0, /* invalid */
|
||||
1, /* A_8 */
|
||||
3, /* 888 */
|
||||
4, /* 8888 */
|
||||
2, /* 565 */
|
||||
2, /* 4444 */
|
||||
2, /* 5551 */
|
||||
2, /* YUV */
|
||||
1 /* G_8 */
|
||||
};
|
||||
|
||||
return bpp_lut [format & COGL_UNORDERED_MASK];
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_bitmap_convert_premult_status (CoglBitmap *bmp,
|
||||
CoglPixelFormat dst_format)
|
||||
{
|
||||
/* Do we need to unpremultiply? */
|
||||
if ((bmp->format & COGL_PREMULT_BIT) > 0 &&
|
||||
(dst_format & COGL_PREMULT_BIT) == 0)
|
||||
/* Try unpremultiplying using imaging library */
|
||||
return (_cogl_bitmap_unpremult (bmp)
|
||||
/* ... or try fallback */
|
||||
|| _cogl_bitmap_fallback_unpremult (bmp));
|
||||
|
||||
/* Do we need to premultiply? */
|
||||
if ((bmp->format & COGL_PREMULT_BIT) == 0 &&
|
||||
(dst_format & COGL_PREMULT_BIT) > 0)
|
||||
/* Try premultiplying using imaging library */
|
||||
return (_cogl_bitmap_premult (bmp)
|
||||
/* ... or try fallback */
|
||||
|| _cogl_bitmap_fallback_premult (bmp));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_convert_format_and_premult (CoglBitmap *bmp,
|
||||
CoglPixelFormat dst_format)
|
||||
{
|
||||
CoglPixelFormat src_format = _cogl_bitmap_get_format (bmp);
|
||||
CoglBitmap *dst_bmp;
|
||||
|
||||
/* Is base format different (not considering premult status)? */
|
||||
if ((src_format & COGL_UNPREMULT_MASK) !=
|
||||
(dst_format & COGL_UNPREMULT_MASK))
|
||||
{
|
||||
/* Try converting using imaging library */
|
||||
if ((dst_bmp = _cogl_bitmap_convert (bmp, dst_format)) == NULL)
|
||||
{
|
||||
/* ... or try fallback */
|
||||
if ((dst_bmp = _cogl_bitmap_fallback_convert (bmp,
|
||||
dst_format)) == NULL)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int rowstride = _cogl_bitmap_get_rowstride (bmp);
|
||||
int height = _cogl_bitmap_get_height (bmp);
|
||||
guint8 *data;
|
||||
|
||||
/* Copy the bitmap so that we can premultiply in-place */
|
||||
|
||||
if ((data = _cogl_bitmap_map (bmp, COGL_BUFFER_ACCESS_READ, 0)) == NULL)
|
||||
return NULL;
|
||||
|
||||
dst_bmp = _cogl_bitmap_new_from_data (g_memdup (data, height * rowstride),
|
||||
src_format,
|
||||
_cogl_bitmap_get_width (bmp),
|
||||
height,
|
||||
rowstride,
|
||||
(CoglBitmapDestroyNotify) g_free,
|
||||
NULL);
|
||||
|
||||
_cogl_bitmap_unmap (bmp);
|
||||
}
|
||||
|
||||
src_format = _cogl_bitmap_get_format (dst_bmp);
|
||||
|
||||
/* We only need to do a premult conversion if both formats have an
|
||||
alpha channel. If we're converting from RGB to RGBA then the
|
||||
alpha will have been filled with 255 so the premult won't do
|
||||
anything or if we are converting from RGBA to RGB we're losing
|
||||
information so either converting or not will be wrong for
|
||||
transparent pixels */
|
||||
if ((src_format & COGL_A_BIT) == COGL_A_BIT &&
|
||||
(dst_format & COGL_A_BIT) == COGL_A_BIT &&
|
||||
!_cogl_bitmap_convert_premult_status (dst_bmp, dst_format))
|
||||
{
|
||||
cogl_object_unref (dst_bmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dst_bmp;
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_copy (CoglBitmap *src_bmp)
|
||||
{
|
||||
CoglBitmap *dst_bmp;
|
||||
CoglPixelFormat src_format = _cogl_bitmap_get_format (src_bmp);
|
||||
int bpp = _cogl_get_format_bpp (src_format);
|
||||
int width = _cogl_bitmap_get_width (src_bmp);
|
||||
int height = _cogl_bitmap_get_height (src_bmp);
|
||||
int dst_rowstride = width * bpp;
|
||||
|
||||
/* Round the rowstride up to the next nearest multiple of 4 bytes */
|
||||
dst_rowstride = (dst_rowstride + 3) & ~3;
|
||||
|
||||
dst_bmp = _cogl_bitmap_new_from_data (g_malloc (dst_rowstride * height),
|
||||
src_format,
|
||||
width, height,
|
||||
dst_rowstride,
|
||||
(CoglBitmapDestroyNotify) g_free,
|
||||
NULL);
|
||||
|
||||
_cogl_bitmap_copy_subregion (src_bmp,
|
||||
dst_bmp,
|
||||
0, 0, /* src_x/y */
|
||||
0, 0, /* dst_x/y */
|
||||
width, height);
|
||||
|
||||
return dst_bmp;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_bitmap_copy_subregion (CoglBitmap *src,
|
||||
CoglBitmap *dst,
|
||||
int src_x,
|
||||
int src_y,
|
||||
int dst_x,
|
||||
int dst_y,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
guint8 *srcdata;
|
||||
guint8 *dstdata;
|
||||
int bpp;
|
||||
int line;
|
||||
|
||||
/* Intended only for fast copies when format is equal! */
|
||||
g_assert (src->format == dst->format);
|
||||
bpp = _cogl_get_format_bpp (src->format);
|
||||
|
||||
if ((srcdata = _cogl_bitmap_map (src, COGL_BUFFER_ACCESS_READ, 0)))
|
||||
{
|
||||
if ((dstdata = _cogl_bitmap_map (dst, COGL_BUFFER_ACCESS_WRITE, 0)))
|
||||
{
|
||||
srcdata += src_y * src->rowstride + src_x * bpp;
|
||||
dstdata += dst_y * dst->rowstride + dst_x * bpp;
|
||||
|
||||
for (line=0; line<height; ++line)
|
||||
{
|
||||
memcpy (dstdata, srcdata, width * bpp);
|
||||
srcdata += src->rowstride;
|
||||
dstdata += dst->rowstride;
|
||||
}
|
||||
|
||||
_cogl_bitmap_unmap (dst);
|
||||
}
|
||||
|
||||
_cogl_bitmap_unmap (src);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_bitmap_get_size_from_file (const char *filename,
|
||||
int *width,
|
||||
int *height)
|
||||
{
|
||||
return _cogl_bitmap_get_size_from_file (filename, width, height);
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_new_from_data (guint8 *data,
|
||||
CoglPixelFormat format,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride,
|
||||
CoglBitmapDestroyNotify destroy_fn,
|
||||
void *destroy_fn_data)
|
||||
{
|
||||
CoglBitmap *bmp = g_slice_new (CoglBitmap);
|
||||
|
||||
bmp->format = format;
|
||||
bmp->width = width;
|
||||
bmp->height = height;
|
||||
bmp->rowstride = rowstride;
|
||||
bmp->data = data;
|
||||
bmp->destroy_fn = destroy_fn;
|
||||
bmp->destroy_fn_data = destroy_fn_data;
|
||||
bmp->mapped = FALSE;
|
||||
bmp->bound = FALSE;
|
||||
bmp->shared_bmp = NULL;
|
||||
bmp->buffer = NULL;
|
||||
|
||||
return _cogl_bitmap_object_new (bmp);
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_new_shared (CoglBitmap *shared_bmp,
|
||||
CoglPixelFormat format,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride)
|
||||
{
|
||||
CoglBitmap *bmp = _cogl_bitmap_new_from_data (NULL, /* data */
|
||||
format,
|
||||
width,
|
||||
height,
|
||||
rowstride,
|
||||
NULL, /* destroy_fn */
|
||||
NULL /* destroy_fn_data */);
|
||||
|
||||
bmp->shared_bmp = cogl_object_ref (shared_bmp);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
cogl_bitmap_new_from_file (const char *filename,
|
||||
GError **error)
|
||||
{
|
||||
CoglBitmap *bmp;
|
||||
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE);
|
||||
|
||||
if ((bmp = _cogl_bitmap_from_file (filename, error)) == NULL)
|
||||
{
|
||||
/* Try fallback */
|
||||
if ((bmp = _cogl_bitmap_fallback_from_file (filename))
|
||||
&& error && *error)
|
||||
{
|
||||
g_error_free (*error);
|
||||
*error = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
CoglBitmap *
|
||||
_cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
|
||||
CoglPixelFormat format,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride,
|
||||
int offset)
|
||||
{
|
||||
CoglBitmap *bmp;
|
||||
|
||||
g_return_val_if_fail (cogl_is_buffer (buffer), NULL);
|
||||
|
||||
bmp = _cogl_bitmap_new_from_data (NULL, /* data */
|
||||
format,
|
||||
width,
|
||||
height,
|
||||
rowstride,
|
||||
NULL, /* destroy_fn */
|
||||
NULL /* destroy_fn_data */);
|
||||
|
||||
bmp->buffer = cogl_object_ref (buffer);
|
||||
bmp->data = GINT_TO_POINTER (offset);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
CoglPixelFormat
|
||||
_cogl_bitmap_get_format (CoglBitmap *bitmap)
|
||||
{
|
||||
return bitmap->format;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_bitmap_set_format (CoglBitmap *bitmap,
|
||||
CoglPixelFormat format)
|
||||
{
|
||||
bitmap->format = format;
|
||||
}
|
||||
|
||||
int
|
||||
_cogl_bitmap_get_width (CoglBitmap *bitmap)
|
||||
{
|
||||
return bitmap->width;
|
||||
}
|
||||
|
||||
GQuark
|
||||
cogl_bitmap_error_quark (void)
|
||||
{
|
||||
return g_quark_from_static_string ("cogl-bitmap-error-quark");
|
||||
}
|
||||
|
||||
int
|
||||
_cogl_bitmap_get_height (CoglBitmap *bitmap)
|
||||
{
|
||||
return bitmap->height;
|
||||
}
|
||||
|
||||
int
|
||||
_cogl_bitmap_get_rowstride (CoglBitmap *bitmap)
|
||||
{
|
||||
return bitmap->rowstride;
|
||||
}
|
||||
|
||||
guint8 *
|
||||
_cogl_bitmap_map (CoglBitmap *bitmap,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints)
|
||||
{
|
||||
/* Divert to another bitmap if this data is shared */
|
||||
if (bitmap->shared_bmp)
|
||||
return _cogl_bitmap_map (bitmap->shared_bmp, access, hints);
|
||||
|
||||
g_assert (!bitmap->mapped);
|
||||
|
||||
if (bitmap->buffer)
|
||||
{
|
||||
guint8 *data = cogl_buffer_map (bitmap->buffer,
|
||||
access,
|
||||
hints);
|
||||
|
||||
COGL_NOTE (BITMAP, "A pixel array is being mapped from a bitmap. This "
|
||||
"usually means that some conversion on the pixel array is "
|
||||
"needed so a sub-optimal format is being used.");
|
||||
|
||||
if (data)
|
||||
{
|
||||
bitmap->mapped = TRUE;
|
||||
|
||||
return data + GPOINTER_TO_INT (bitmap->data);
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitmap->mapped = TRUE;
|
||||
|
||||
return bitmap->data;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_bitmap_unmap (CoglBitmap *bitmap)
|
||||
{
|
||||
/* Divert to another bitmap if this data is shared */
|
||||
if (bitmap->shared_bmp)
|
||||
return _cogl_bitmap_unmap (bitmap->shared_bmp);
|
||||
|
||||
g_assert (bitmap->mapped);
|
||||
bitmap->mapped = FALSE;
|
||||
|
||||
if (bitmap->buffer)
|
||||
cogl_buffer_unmap (bitmap->buffer);
|
||||
}
|
||||
|
||||
guint8 *
|
||||
_cogl_bitmap_bind (CoglBitmap *bitmap,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints)
|
||||
{
|
||||
guint8 *ptr;
|
||||
|
||||
/* Divert to another bitmap if this data is shared */
|
||||
if (bitmap->shared_bmp)
|
||||
return _cogl_bitmap_bind (bitmap->shared_bmp, access, hints);
|
||||
|
||||
g_assert (!bitmap->bound);
|
||||
|
||||
/* If the bitmap wasn't created from a buffer then the
|
||||
implementation of bind is the same as map */
|
||||
if (bitmap->buffer == NULL)
|
||||
{
|
||||
guint8 *data = _cogl_bitmap_map (bitmap, access, hints);
|
||||
if (data)
|
||||
bitmap->bound = TRUE;
|
||||
return data;
|
||||
}
|
||||
|
||||
bitmap->bound = TRUE;
|
||||
|
||||
if (access == COGL_BUFFER_ACCESS_READ)
|
||||
ptr = _cogl_buffer_bind (bitmap->buffer,
|
||||
COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK);
|
||||
else if (access == COGL_BUFFER_ACCESS_WRITE)
|
||||
ptr = _cogl_buffer_bind (bitmap->buffer,
|
||||
COGL_BUFFER_BIND_TARGET_PIXEL_PACK);
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
||||
/* The data pointer actually stores the offset */
|
||||
return GPOINTER_TO_INT (bitmap->data) + ptr;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_bitmap_unbind (CoglBitmap *bitmap)
|
||||
{
|
||||
/* Divert to another bitmap if this data is shared */
|
||||
if (bitmap->shared_bmp)
|
||||
return _cogl_bitmap_unbind (bitmap->shared_bmp);
|
||||
|
||||
g_assert (bitmap->bound);
|
||||
bitmap->bound = FALSE;
|
||||
|
||||
/* If the bitmap wasn't created from a pixel array then the
|
||||
implementation of unbind is the same as unmap */
|
||||
if (bitmap->buffer)
|
||||
_cogl_buffer_unbind (bitmap->buffer);
|
||||
else
|
||||
_cogl_bitmap_unmap (bitmap);
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_BITMAP_H__
|
||||
#define __COGL_BITMAP_H__
|
||||
|
||||
#include <cogl/cogl-types.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _CoglBitmap CoglBitmap;
|
||||
|
||||
/**
|
||||
* SECTION:cogl-bitmap
|
||||
* @short_description: Fuctions for loading images
|
||||
*
|
||||
* Cogl allows loading image data into memory as CoglBitmaps without
|
||||
* loading them immediately into GPU textures.
|
||||
*
|
||||
* #CoglBitmap is available since Cogl 1.0
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* cogl_bitmap_new_from_file:
|
||||
* @filename: the file to load.
|
||||
* @error: a #GError or %NULL.
|
||||
*
|
||||
* Loads an image file from disk. This function can be safely called from
|
||||
* within a thread.
|
||||
*
|
||||
* Return value: a #CoglBitmap to the new loaded image data, or
|
||||
* %NULL if loading the image failed.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglBitmap *
|
||||
cogl_bitmap_new_from_file (const char *filename,
|
||||
GError **error);
|
||||
|
||||
/**
|
||||
* cogl_bitmap_get_size_from_file:
|
||||
* @filename: the file to check
|
||||
* @width: (out): return location for the bitmap width, or %NULL
|
||||
* @height: (out): return location for the bitmap height, or %NULL
|
||||
*
|
||||
* Parses an image file enough to extract the width and height
|
||||
* of the bitmap.
|
||||
*
|
||||
* Return value: %TRUE if the image was successfully parsed
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
gboolean
|
||||
cogl_bitmap_get_size_from_file (const char *filename,
|
||||
int *width,
|
||||
int *height);
|
||||
|
||||
/**
|
||||
* cogl_is_bitmap:
|
||||
* @handle: a #CoglHandle for a bitmap
|
||||
*
|
||||
* Checks whether @handle is a #CoglHandle for a bitmap
|
||||
*
|
||||
* Return value: %TRUE if the passed handle represents a bitmap,
|
||||
* and %FALSE otherwise
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
gboolean
|
||||
cogl_is_bitmap (CoglHandle handle);
|
||||
|
||||
/**
|
||||
* COGL_BITMAP_ERROR:
|
||||
*
|
||||
* #GError domain for bitmap errors.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
#define COGL_BITMAP_ERROR (cogl_bitmap_error_quark ())
|
||||
|
||||
/**
|
||||
* CoglBitmapError:
|
||||
* @COGL_BITMAP_ERROR_FAILED: Generic failure code, something went
|
||||
* wrong.
|
||||
* @COGL_BITMAP_ERROR_UNKNOWN_TYPE: Unknown image type.
|
||||
* @COGL_BITMAP_ERROR_CORRUPT_IMAGE: An image file was broken somehow.
|
||||
*
|
||||
* Error codes that can be thrown when performing bitmap
|
||||
* operations. Note that gdk_pixbuf_new_from_file() can also throw
|
||||
* errors directly from the underlying image loading library. For
|
||||
* example, if GdkPixbuf is used then errors #GdkPixbufError<!-- -->s
|
||||
* will be used directly.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
typedef enum {
|
||||
COGL_BITMAP_ERROR_FAILED,
|
||||
COGL_BITMAP_ERROR_UNKNOWN_TYPE,
|
||||
COGL_BITMAP_ERROR_CORRUPT_IMAGE
|
||||
} CoglBitmapError;
|
||||
|
||||
GQuark cogl_bitmap_error_quark (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_BITMAP_H__ */
|
@ -1,257 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Neil Roberts <neil@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cogl-bitmask.h"
|
||||
|
||||
gboolean
|
||||
_cogl_bitmask_get_from_array (const CoglBitmask *bitmask,
|
||||
unsigned int bit_num)
|
||||
{
|
||||
GArray *array = (GArray *) *bitmask;
|
||||
|
||||
/* If the index is off the end of the array then assume the bit is
|
||||
not set */
|
||||
if (bit_num >= sizeof (unsigned int) * 8 * array->len)
|
||||
return FALSE;
|
||||
else
|
||||
return !!(g_array_index (array, unsigned int,
|
||||
bit_num / (sizeof (unsigned int) * 8)) &
|
||||
(1 << (bit_num % (sizeof (unsigned int) * 8))));
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_bitmask_convert_to_array (CoglBitmask *bitmask)
|
||||
{
|
||||
GArray *array;
|
||||
/* Fetch the old values, ignoring the least significant bit */
|
||||
unsigned int old_values = GPOINTER_TO_UINT (*bitmask) >> 1;
|
||||
|
||||
array = g_array_new (FALSE, TRUE, sizeof (unsigned int));
|
||||
/* Copy the old values back in */
|
||||
g_array_append_val (array, old_values);
|
||||
|
||||
*bitmask = (struct _CoglBitmaskImaginaryType *) array;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_bitmask_set_in_array (CoglBitmask *bitmask,
|
||||
unsigned int bit_num,
|
||||
gboolean value)
|
||||
{
|
||||
GArray *array;
|
||||
unsigned int array_index, new_value_mask;
|
||||
|
||||
/* If the bitmask is not already an array then we need to allocate one */
|
||||
if (!_cogl_bitmask_has_array (bitmask))
|
||||
_cogl_bitmask_convert_to_array (bitmask);
|
||||
|
||||
array = (GArray *) *bitmask;
|
||||
|
||||
array_index = bit_num / (sizeof (unsigned int) * 8);
|
||||
/* Grow the array if necessary. This will clear the new data */
|
||||
if (array_index >= array->len)
|
||||
g_array_set_size (array, array_index + 1);
|
||||
|
||||
new_value_mask = 1 << (bit_num % (sizeof (unsigned int) * 8));
|
||||
|
||||
if (value)
|
||||
g_array_index (array, unsigned int, array_index) |= new_value_mask;
|
||||
else
|
||||
g_array_index (array, unsigned int, array_index) &= ~new_value_mask;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_bitmask_set_bits (CoglBitmask *dst,
|
||||
const CoglBitmask *src)
|
||||
{
|
||||
if (_cogl_bitmask_has_array (src))
|
||||
{
|
||||
GArray *src_array, *dst_array;
|
||||
int i;
|
||||
|
||||
if (!_cogl_bitmask_has_array (dst))
|
||||
_cogl_bitmask_convert_to_array (dst);
|
||||
|
||||
dst_array = (GArray *) *dst;
|
||||
src_array = (GArray *) *src;
|
||||
|
||||
if (dst_array->len < src_array->len)
|
||||
g_array_set_size (dst_array, src_array->len);
|
||||
|
||||
for (i = 0; i < src_array->len; i++)
|
||||
g_array_index (dst_array, unsigned int, i) |=
|
||||
g_array_index (src_array, unsigned int, i);
|
||||
}
|
||||
else if (_cogl_bitmask_has_array (dst))
|
||||
{
|
||||
GArray *dst_array;
|
||||
|
||||
dst_array = (GArray *) *dst;
|
||||
|
||||
g_array_index (dst_array, unsigned int, 0) |=
|
||||
(GPOINTER_TO_UINT (*src) >> 1);
|
||||
}
|
||||
else
|
||||
*dst = GUINT_TO_POINTER (GPOINTER_TO_UINT (*dst) |
|
||||
GPOINTER_TO_UINT (*src));
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_bitmask_set_range_in_array (CoglBitmask *bitmask,
|
||||
unsigned int n_bits,
|
||||
gboolean value)
|
||||
{
|
||||
GArray *array;
|
||||
unsigned int array_index, bit_index;
|
||||
|
||||
if (n_bits == 0)
|
||||
return;
|
||||
|
||||
/* If the bitmask is not already an array then we need to allocate one */
|
||||
if (!_cogl_bitmask_has_array (bitmask))
|
||||
_cogl_bitmask_convert_to_array (bitmask);
|
||||
|
||||
array = (GArray *) *bitmask;
|
||||
|
||||
/* Get the array index of the top most value that will be touched */
|
||||
array_index = (n_bits - 1) / (sizeof (unsigned int) * 8);
|
||||
/* Get the bit index of the top most value */
|
||||
bit_index = (n_bits - 1) % (sizeof (unsigned int) * 8);
|
||||
/* Grow the array if necessary. This will clear the new data */
|
||||
if (array_index >= array->len)
|
||||
g_array_set_size (array, array_index + 1);
|
||||
|
||||
if (value)
|
||||
{
|
||||
/* Set the bits that are touching this index */
|
||||
g_array_index (array, unsigned int, array_index) |=
|
||||
~(unsigned int) 0 >> (sizeof (unsigned int) * 8 - 1 - bit_index);
|
||||
|
||||
/* Set all of the bits in any lesser indices */
|
||||
memset (array->data, 0xff, sizeof (unsigned int) * array_index);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear the bits that are touching this index */
|
||||
g_array_index (array, unsigned int, array_index) &=
|
||||
~(unsigned int) 1 << bit_index;
|
||||
|
||||
/* Clear all of the bits in any lesser indices */
|
||||
memset (array->data, 0x00, sizeof (unsigned int) * array_index);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_bitmask_xor_bits (CoglBitmask *dst,
|
||||
const CoglBitmask *src)
|
||||
{
|
||||
if (_cogl_bitmask_has_array (src))
|
||||
{
|
||||
GArray *src_array, *dst_array;
|
||||
int i;
|
||||
|
||||
if (!_cogl_bitmask_has_array (dst))
|
||||
_cogl_bitmask_convert_to_array (dst);
|
||||
|
||||
dst_array = (GArray *) *dst;
|
||||
src_array = (GArray *) *src;
|
||||
|
||||
if (dst_array->len < src_array->len)
|
||||
g_array_set_size (dst_array, src_array->len);
|
||||
|
||||
for (i = 0; i < src_array->len; i++)
|
||||
g_array_index (dst_array, unsigned int, i) ^=
|
||||
g_array_index (src_array, unsigned int, i);
|
||||
}
|
||||
else if (_cogl_bitmask_has_array (dst))
|
||||
{
|
||||
GArray *dst_array;
|
||||
|
||||
dst_array = (GArray *) *dst;
|
||||
|
||||
g_array_index (dst_array, unsigned int, 0) ^=
|
||||
(GPOINTER_TO_UINT (*src) >> 1);
|
||||
}
|
||||
else
|
||||
*dst = GUINT_TO_POINTER ((GPOINTER_TO_UINT (*dst) ^
|
||||
GPOINTER_TO_UINT (*src)) | 1);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_bitmask_clear_all_in_array (CoglBitmask *bitmask)
|
||||
{
|
||||
GArray *array = (GArray *) *bitmask;
|
||||
|
||||
memset (array->data, 0, sizeof (unsigned int) * array->len);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_bitmask_foreach (const CoglBitmask *bitmask,
|
||||
CoglBitmaskForeachFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (_cogl_bitmask_has_array (bitmask))
|
||||
{
|
||||
GArray *array = (GArray *) *bitmask;
|
||||
int array_index;
|
||||
|
||||
for (array_index = 0; array_index < array->len; array_index++)
|
||||
{
|
||||
unsigned int mask = g_array_index (array, unsigned int, array_index);
|
||||
int bit = 0;
|
||||
|
||||
while (mask)
|
||||
{
|
||||
if (mask & 1)
|
||||
func (array_index * sizeof (unsigned int) * 8 + bit, user_data);
|
||||
|
||||
bit++;
|
||||
mask >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int mask = GPOINTER_TO_UINT (*bitmask) >> 1;
|
||||
int bit = 0;
|
||||
|
||||
while (mask)
|
||||
{
|
||||
if (mask & 1)
|
||||
func (bit, user_data);
|
||||
|
||||
bit++;
|
||||
mask >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,227 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Neil Roberts <neil@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_BITMASK_H
|
||||
#define __COGL_BITMASK_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* CoglBitmask implements a growable array of bits. A CoglBitmask can
|
||||
* be allocated on the stack but it must be initialised with
|
||||
* _cogl_bitmask_init() before use and then destroyed with
|
||||
* _cogl_bitmask_destroy(). A CoglBitmask will try to avoid allocating
|
||||
* any memory unless more than 31 bits are needed.
|
||||
*
|
||||
* Internally a CoglBitmask is a pointer. If the least significant bit
|
||||
* of the pointer is 1 then the rest of the bits are directly used as
|
||||
* part of the bitmask, otherwise it is a pointer to a GArray of
|
||||
* unsigned ints. This relies on the fact the g_malloc will return a
|
||||
* pointer aligned to at least two bytes (so that the least
|
||||
* significant bit of the address is always 0)
|
||||
*
|
||||
* If the maximum possible bit number in the set is known at compile
|
||||
* time, it may make more sense to use the macros in cogl-flags.h
|
||||
* instead of this type.
|
||||
*/
|
||||
|
||||
typedef struct _CoglBitmaskImaginaryType *CoglBitmask;
|
||||
|
||||
/* Internal helper macro to determine whether this bitmask has a
|
||||
GArray allocated or whether the pointer is just used directly */
|
||||
#define _cogl_bitmask_has_array(bitmask) \
|
||||
(!(GPOINTER_TO_UINT (*bitmask) & 1))
|
||||
|
||||
/* Number of bits we can use before needing to allocate an array */
|
||||
#define COGL_BITMASK_MAX_DIRECT_BITS (sizeof (unsigned int) * 8 - 1)
|
||||
|
||||
/*
|
||||
* _cogl_bitmask_init:
|
||||
* @bitmask: A pointer to a bitmask
|
||||
*
|
||||
* Initialises the cogl bitmask. This must be called before any other
|
||||
* bitmask functions are called. Initially all of the values are
|
||||
* zero
|
||||
*/
|
||||
/* Set the last significant bit to mark that no array has been
|
||||
allocated yet */
|
||||
#define _cogl_bitmask_init(bitmask) \
|
||||
G_STMT_START { *(bitmask) = GUINT_TO_POINTER (1); } G_STMT_END
|
||||
|
||||
gboolean
|
||||
_cogl_bitmask_get_from_array (const CoglBitmask *bitmask,
|
||||
unsigned int bit_num);
|
||||
|
||||
void
|
||||
_cogl_bitmask_set_in_array (CoglBitmask *bitmask,
|
||||
unsigned int bit_num,
|
||||
gboolean value);
|
||||
|
||||
void
|
||||
_cogl_bitmask_set_range_in_array (CoglBitmask *bitmask,
|
||||
unsigned int n_bits,
|
||||
gboolean value);
|
||||
|
||||
void
|
||||
_cogl_bitmask_clear_all_in_array (CoglBitmask *bitmask);
|
||||
|
||||
/*
|
||||
* cogl_bitmask_set_bits:
|
||||
* @dst: The bitmask to modify
|
||||
* @src: The bitmask to copy bits from
|
||||
*
|
||||
* This makes sure that all of the bits that are set in @src are also
|
||||
* set in @dst. Any unset bits in @src are left alone in @dst.
|
||||
*/
|
||||
void
|
||||
_cogl_bitmask_set_bits (CoglBitmask *dst,
|
||||
const CoglBitmask *src);
|
||||
|
||||
/*
|
||||
* cogl_bitmask_xor_bits:
|
||||
* @dst: The bitmask to modify
|
||||
* @src: The bitmask to copy bits from
|
||||
*
|
||||
* For every bit that is set in src, the corresponding bit in dst is
|
||||
* inverted.
|
||||
*/
|
||||
void
|
||||
_cogl_bitmask_xor_bits (CoglBitmask *dst,
|
||||
const CoglBitmask *src);
|
||||
|
||||
typedef void (* CoglBitmaskForeachFunc) (int bit_num, gpointer user_data);
|
||||
|
||||
/*
|
||||
* cogl_bitmask_foreach:
|
||||
* @bitmask: A pointer to a bitmask
|
||||
* @func: A callback function
|
||||
* @user_data: A pointer to pass to the callback
|
||||
*
|
||||
* This calls @func for each bit that is set in @bitmask.
|
||||
*/
|
||||
void
|
||||
_cogl_bitmask_foreach (const CoglBitmask *bitmask,
|
||||
CoglBitmaskForeachFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
/*
|
||||
* _cogl_bitmask_get:
|
||||
* @bitmask: A pointer to a bitmask
|
||||
* @bit_num: A bit number
|
||||
*
|
||||
* Return value: whether bit number @bit_num is set in @bitmask
|
||||
*/
|
||||
static inline gboolean
|
||||
_cogl_bitmask_get (const CoglBitmask *bitmask, unsigned int bit_num)
|
||||
{
|
||||
if (_cogl_bitmask_has_array (bitmask))
|
||||
return _cogl_bitmask_get_from_array (bitmask, bit_num);
|
||||
else if (bit_num >= COGL_BITMASK_MAX_DIRECT_BITS)
|
||||
return FALSE;
|
||||
else
|
||||
return !!(GPOINTER_TO_UINT (*bitmask) & (1 << (bit_num + 1)));
|
||||
}
|
||||
|
||||
/*
|
||||
* _cogl_bitmask_set:
|
||||
* @bitmask: A pointer to a bitmask
|
||||
* @bit_num: A bit number
|
||||
* @value: The new value
|
||||
*
|
||||
* Sets or resets a bit number @bit_num in @bitmask according to @value.
|
||||
*/
|
||||
static inline void
|
||||
_cogl_bitmask_set (CoglBitmask *bitmask, unsigned int bit_num, gboolean value)
|
||||
{
|
||||
if (_cogl_bitmask_has_array (bitmask) ||
|
||||
bit_num >= COGL_BITMASK_MAX_DIRECT_BITS)
|
||||
_cogl_bitmask_set_in_array (bitmask, bit_num, value);
|
||||
else if (value)
|
||||
*bitmask = GUINT_TO_POINTER (GPOINTER_TO_UINT (*bitmask) |
|
||||
(1 << (bit_num + 1)));
|
||||
else
|
||||
*bitmask = GUINT_TO_POINTER (GPOINTER_TO_UINT (*bitmask) &
|
||||
~(1 << (bit_num + 1)));
|
||||
}
|
||||
|
||||
/*
|
||||
* _cogl_bitmask_set_range:
|
||||
* @bitmask: A pointer to a bitmask
|
||||
* @n_bits: The number of bits to set
|
||||
* @value: The value to set
|
||||
*
|
||||
* Sets the first @n_bits in @bitmask to @value.
|
||||
*/
|
||||
static inline void
|
||||
_cogl_bitmask_set_range (CoglBitmask *bitmask,
|
||||
unsigned int n_bits,
|
||||
gboolean value)
|
||||
{
|
||||
if (_cogl_bitmask_has_array (bitmask) ||
|
||||
n_bits > COGL_BITMASK_MAX_DIRECT_BITS)
|
||||
_cogl_bitmask_set_range_in_array (bitmask, n_bits, value);
|
||||
else if (value)
|
||||
*bitmask = GUINT_TO_POINTER (GPOINTER_TO_UINT (*bitmask) |
|
||||
~(~(unsigned int) 1 << n_bits));
|
||||
else
|
||||
*bitmask = GUINT_TO_POINTER (GPOINTER_TO_UINT (*bitmask) &
|
||||
((~(unsigned int) 1 << n_bits) | 1));
|
||||
}
|
||||
|
||||
/*
|
||||
* _cogl_bitmask_destroy:
|
||||
* @bitmask: A pointer to a bitmask
|
||||
*
|
||||
* Destroys any resources allocated by the bitmask
|
||||
*/
|
||||
static inline void
|
||||
_cogl_bitmask_destroy (CoglBitmask *bitmask)
|
||||
{
|
||||
if (_cogl_bitmask_has_array (bitmask))
|
||||
g_array_free ((GArray *) *bitmask, TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* _cogl_bitmask_clear_all:
|
||||
* @bitmask: A pointer to a bitmask
|
||||
*
|
||||
* Clears all the bits in a bitmask without destroying any resources.
|
||||
*/
|
||||
static inline void
|
||||
_cogl_bitmask_clear_all (CoglBitmask *bitmask)
|
||||
{
|
||||
if (_cogl_bitmask_has_array (bitmask))
|
||||
_cogl_bitmask_clear_all_in_array (bitmask);
|
||||
else
|
||||
*bitmask = GUINT_TO_POINTER (1);
|
||||
}
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_BITMASK_H */
|
||||
|
@ -1,984 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-debug.h"
|
||||
#include "cogl-blend-string.h"
|
||||
|
||||
typedef enum _ParserState
|
||||
{
|
||||
PARSER_STATE_EXPECT_DEST_CHANNELS,
|
||||
PARSER_STATE_SCRAPING_DEST_CHANNELS,
|
||||
PARSER_STATE_EXPECT_FUNCTION_NAME,
|
||||
PARSER_STATE_SCRAPING_FUNCTION_NAME,
|
||||
PARSER_STATE_EXPECT_ARG_START,
|
||||
PARSER_STATE_EXPECT_STATEMENT_END
|
||||
} ParserState;
|
||||
|
||||
typedef enum _ParserArgState
|
||||
{
|
||||
PARSER_ARG_STATE_START,
|
||||
PARSER_ARG_STATE_EXPECT_MINUS,
|
||||
PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME,
|
||||
PARSER_ARG_STATE_SCRAPING_COLOR_SRC_NAME,
|
||||
PARSER_ARG_STATE_MAYBE_COLOR_MASK,
|
||||
PARSER_ARG_STATE_SCRAPING_MASK,
|
||||
PARSER_ARG_STATE_MAYBE_MULT,
|
||||
PARSER_ARG_STATE_EXPECT_OPEN_PAREN,
|
||||
PARSER_ARG_STATE_EXPECT_FACTOR,
|
||||
PARSER_ARG_STATE_MAYBE_SRC_ALPHA_SATURATE,
|
||||
PARSER_ARG_STATE_MAYBE_MINUS,
|
||||
PARSER_ARG_STATE_EXPECT_CLOSE_PAREN,
|
||||
PARSER_ARG_STATE_EXPECT_END
|
||||
} ParserArgState;
|
||||
|
||||
|
||||
#define DEFINE_COLOR_SOURCE(NAME, NAME_LEN) \
|
||||
{/*.type = */COGL_BLEND_STRING_COLOR_SOURCE_ ## NAME, \
|
||||
/*.name = */#NAME, \
|
||||
/*.name_len = */NAME_LEN}
|
||||
|
||||
static CoglBlendStringColorSourceInfo blending_color_sources[] = {
|
||||
DEFINE_COLOR_SOURCE (SRC_COLOR, 9),
|
||||
DEFINE_COLOR_SOURCE (DST_COLOR, 9),
|
||||
DEFINE_COLOR_SOURCE (CONSTANT, 8)
|
||||
};
|
||||
|
||||
static CoglBlendStringColorSourceInfo tex_combine_color_sources[] = {
|
||||
DEFINE_COLOR_SOURCE (TEXTURE, 7),
|
||||
/* DEFINE_COLOR_SOURCE (TEXTURE_N, *) - handled manually */
|
||||
DEFINE_COLOR_SOURCE (PRIMARY, 7),
|
||||
DEFINE_COLOR_SOURCE (CONSTANT, 8),
|
||||
DEFINE_COLOR_SOURCE (PREVIOUS, 8)
|
||||
};
|
||||
|
||||
static CoglBlendStringColorSourceInfo tex_combine_texture_n_color_source = {
|
||||
/*.type = */COGL_BLEND_STRING_COLOR_SOURCE_TEXTURE_N,
|
||||
/*.name = */"TEXTURE_N",
|
||||
/*.name_len = */0
|
||||
};
|
||||
|
||||
#undef DEFINE_COLOR_SOURCE
|
||||
|
||||
#define DEFINE_FUNCTION(NAME, NAME_LEN, ARGC) \
|
||||
{ /*.type = */COGL_BLEND_STRING_FUNCTION_ ## NAME, \
|
||||
/*.name = */#NAME, \
|
||||
/*.name_len = */NAME_LEN, \
|
||||
/*.argc = */ARGC }
|
||||
|
||||
/* NB: These must be sorted so any name that's a subset of another
|
||||
* comes later than the longer name. */
|
||||
static CoglBlendStringFunctionInfo tex_combine_functions[] = {
|
||||
DEFINE_FUNCTION (REPLACE, 7, 1),
|
||||
DEFINE_FUNCTION (MODULATE, 8, 2),
|
||||
DEFINE_FUNCTION (ADD_SIGNED, 10, 2),
|
||||
DEFINE_FUNCTION (ADD, 3, 2),
|
||||
DEFINE_FUNCTION (INTERPOLATE, 11, 3),
|
||||
DEFINE_FUNCTION (SUBTRACT, 8, 2),
|
||||
DEFINE_FUNCTION (DOT3_RGBA, 9, 2),
|
||||
DEFINE_FUNCTION (DOT3_RGB, 8, 2)
|
||||
};
|
||||
|
||||
static CoglBlendStringFunctionInfo blend_functions[] = {
|
||||
DEFINE_FUNCTION (ADD, 3, 2)
|
||||
};
|
||||
|
||||
#undef DEFINE_FUNCTION
|
||||
|
||||
GQuark
|
||||
cogl_blend_string_error_quark (void)
|
||||
{
|
||||
return g_quark_from_static_string ("cogl-blend-string-error-quark");
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_blend_string_split_rgba_statement (CoglBlendStringStatement *statement,
|
||||
CoglBlendStringStatement *rgb,
|
||||
CoglBlendStringStatement *a)
|
||||
{
|
||||
int i;
|
||||
|
||||
memcpy (rgb, statement, sizeof (CoglBlendStringStatement));
|
||||
memcpy (a, statement, sizeof (CoglBlendStringStatement));
|
||||
|
||||
rgb->mask = COGL_BLEND_STRING_CHANNEL_MASK_RGB;
|
||||
a->mask = COGL_BLEND_STRING_CHANNEL_MASK_ALPHA;
|
||||
|
||||
for (i = 0; i < statement->function->argc; i++)
|
||||
{
|
||||
CoglBlendStringArgument *arg = &statement->args[i];
|
||||
CoglBlendStringArgument *rgb_arg = &rgb->args[i];
|
||||
CoglBlendStringArgument *a_arg = &a->args[i];
|
||||
|
||||
if (arg->source.mask == COGL_BLEND_STRING_CHANNEL_MASK_RGBA)
|
||||
{
|
||||
rgb_arg->source.mask = COGL_BLEND_STRING_CHANNEL_MASK_RGB;
|
||||
a_arg->source.mask = COGL_BLEND_STRING_CHANNEL_MASK_ALPHA;
|
||||
}
|
||||
|
||||
if (arg->factor.is_color &&
|
||||
arg->factor.source.mask == COGL_BLEND_STRING_CHANNEL_MASK_RGBA)
|
||||
{
|
||||
rgb_arg->factor.source.mask = COGL_BLEND_STRING_CHANNEL_MASK_RGB;
|
||||
a_arg->factor.source.mask = COGL_BLEND_STRING_CHANNEL_MASK_ALPHA;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
validate_tex_combine_statements (CoglBlendStringStatement *statements,
|
||||
int n_statements,
|
||||
GError **error)
|
||||
{
|
||||
int i, j;
|
||||
const char *error_string;
|
||||
CoglBlendStringError detail = COGL_BLEND_STRING_ERROR_INVALID_ERROR;
|
||||
|
||||
for (i = 0; i < n_statements; i++)
|
||||
{
|
||||
for (j = 0; j < statements[i].function->argc; j++)
|
||||
{
|
||||
CoglBlendStringArgument *arg = &statements[i].args[j];
|
||||
if (arg->source.is_zero)
|
||||
{
|
||||
error_string = "You can't use the constant '0' as a texture "
|
||||
"combine argument";
|
||||
goto error;
|
||||
}
|
||||
if (!arg->factor.is_one)
|
||||
{
|
||||
error_string = "Argument factors are only relevant to blending "
|
||||
"not texture combining";
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
error:
|
||||
g_set_error (error,
|
||||
COGL_BLEND_STRING_ERROR,
|
||||
detail,
|
||||
"Invalid texture combine string: %s",
|
||||
error_string);
|
||||
|
||||
if (COGL_DEBUG_ENABLED (COGL_DEBUG_BLEND_STRINGS))
|
||||
{
|
||||
g_debug ("Invalid texture combine string: %s",
|
||||
error_string);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
validate_blend_statements (CoglBlendStringStatement *statements,
|
||||
int n_statements,
|
||||
GError **error)
|
||||
{
|
||||
int i, j;
|
||||
const char *error_string;
|
||||
CoglBlendStringError detail = COGL_BLEND_STRING_ERROR_INVALID_ERROR;
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
_COGL_GET_CONTEXT (ctx, 0);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
if (n_statements == 2)
|
||||
{
|
||||
/* glBlendEquationSeperate is GL 2.0 only */
|
||||
if (!ctx->drv.pf_glBlendEquationSeparate &&
|
||||
statements[0].function->type != statements[1].function->type)
|
||||
{
|
||||
error_string = "Separate blend functions for the RGB an A "
|
||||
"channels isn't supported by the driver";
|
||||
detail = COGL_BLEND_STRING_ERROR_GPU_UNSUPPORTED_ERROR;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
#elif defined(HAVE_COGL_GLES)
|
||||
if (n_statements != 1)
|
||||
{
|
||||
error_string = "Separate blend functions for the RGB an A "
|
||||
"channels isn't supported by the GLES 1";
|
||||
detail = COGL_BLEND_STRING_ERROR_GPU_UNSUPPORTED_ERROR;
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < n_statements; i++)
|
||||
for (j = 0; j < statements[i].function->argc; j++)
|
||||
{
|
||||
CoglBlendStringArgument *arg = &statements[i].args[j];
|
||||
|
||||
if (arg->source.is_zero)
|
||||
continue;
|
||||
|
||||
if ((j == 0 &&
|
||||
arg->source.info->type !=
|
||||
COGL_BLEND_STRING_COLOR_SOURCE_SRC_COLOR)
|
||||
|| (j == 1 &&
|
||||
arg->source.info->type !=
|
||||
COGL_BLEND_STRING_COLOR_SOURCE_DST_COLOR))
|
||||
{
|
||||
error_string = "For blending you must always use SRC_COLOR "
|
||||
"for arg0 and DST_COLOR for arg1";
|
||||
goto error;
|
||||
}
|
||||
|
||||
#ifdef HAVE_COGL_GLES
|
||||
if (arg->factor.is_color &&
|
||||
arg->factor.source.info->type == COGL_BLEND_STRING_COLOR_SOURCE_CONSTANT)
|
||||
{
|
||||
error_string = "GLES Doesn't support constant blend factors";
|
||||
detail = COGL_BLEND_STRING_ERROR_GPU_UNSUPPORTED_ERROR;
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
error:
|
||||
g_set_error (error,
|
||||
COGL_BLEND_STRING_ERROR,
|
||||
detail,
|
||||
"Invalid blend string: %s",
|
||||
error_string);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
validate_statements_for_context (CoglBlendStringStatement *statements,
|
||||
int n_statements,
|
||||
CoglBlendStringContext context,
|
||||
GError **error)
|
||||
{
|
||||
const char *error_string;
|
||||
|
||||
if (n_statements == 1)
|
||||
{
|
||||
if (statements[0].mask == COGL_BLEND_STRING_CHANNEL_MASK_ALPHA)
|
||||
{
|
||||
error_string = "You need to also give a blend statement for the RGB"
|
||||
"channels";
|
||||
goto error;
|
||||
}
|
||||
else if (statements[0].mask == COGL_BLEND_STRING_CHANNEL_MASK_RGB)
|
||||
{
|
||||
error_string = "You need to also give a blend statement for the "
|
||||
"Alpha channel";
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
if (context == COGL_BLEND_STRING_CONTEXT_BLENDING)
|
||||
return validate_blend_statements (statements, n_statements, error);
|
||||
else
|
||||
return validate_tex_combine_statements (statements, n_statements, error);
|
||||
|
||||
error:
|
||||
g_set_error (error,
|
||||
COGL_BLEND_STRING_ERROR,
|
||||
COGL_BLEND_STRING_ERROR_INVALID_ERROR,
|
||||
"Invalid %s string: %s",
|
||||
context == COGL_BLEND_STRING_CONTEXT_BLENDING ?
|
||||
"blend" : "texture combine",
|
||||
error_string);
|
||||
|
||||
if (COGL_DEBUG_ENABLED (COGL_DEBUG_BLEND_STRINGS))
|
||||
{
|
||||
g_debug ("Invalid %s string: %s",
|
||||
context == COGL_BLEND_STRING_CONTEXT_BLENDING ?
|
||||
"blend" : "texture combine",
|
||||
error_string);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
print_argument (CoglBlendStringArgument *arg)
|
||||
{
|
||||
const char *mask_names[] = {
|
||||
"RGB",
|
||||
"A",
|
||||
"RGBA"
|
||||
};
|
||||
|
||||
g_print (" Arg:\n");
|
||||
g_print (" is zero = %s\n", arg->source.is_zero ? "yes" : "no");
|
||||
if (!arg->source.is_zero)
|
||||
{
|
||||
g_print (" color source = %s\n", arg->source.info->name);
|
||||
g_print (" one minus = %s\n", arg->source.one_minus ? "yes" : "no");
|
||||
g_print (" mask = %s\n", mask_names[arg->source.mask]);
|
||||
g_print (" texture = %d\n", arg->source.texture);
|
||||
g_print ("\n");
|
||||
g_print (" factor is_one = %s\n", arg->factor.is_one ? "yes" : "no");
|
||||
g_print (" factor is_src_alpha_saturate = %s\n",
|
||||
arg->factor.is_src_alpha_saturate ? "yes" : "no");
|
||||
g_print (" factor is_color = %s\n", arg->factor.is_color ? "yes" : "no");
|
||||
if (arg->factor.is_color)
|
||||
{
|
||||
g_print (" factor color:is zero = %s\n",
|
||||
arg->factor.source.is_zero ? "yes" : "no");
|
||||
g_print (" factor color:color source = %s\n",
|
||||
arg->factor.source.info->name);
|
||||
g_print (" factor color:one minus = %s\n",
|
||||
arg->factor.source.one_minus ? "yes" : "no");
|
||||
g_print (" factor color:mask = %s\n",
|
||||
mask_names[arg->factor.source.mask]);
|
||||
g_print (" factor color:texture = %d\n",
|
||||
arg->factor.source.texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_statement (int num, CoglBlendStringStatement *statement)
|
||||
{
|
||||
const char *mask_names[] = {
|
||||
"RGB",
|
||||
"A",
|
||||
"RGBA"
|
||||
};
|
||||
int i;
|
||||
g_print ("Statement %d:\n", num);
|
||||
g_print (" Destination channel mask = %s\n",
|
||||
mask_names[statement->mask]);
|
||||
g_print (" Function = %s\n", statement->function->name);
|
||||
for (i = 0; i < statement->function->argc; i++)
|
||||
print_argument (&statement->args[i]);
|
||||
}
|
||||
|
||||
static const CoglBlendStringFunctionInfo *
|
||||
get_function_info (const char *mark,
|
||||
const char *p,
|
||||
CoglBlendStringContext context)
|
||||
{
|
||||
gsize len = p - mark;
|
||||
CoglBlendStringFunctionInfo *functions;
|
||||
gsize array_len;
|
||||
int i;
|
||||
|
||||
if (context == COGL_BLEND_STRING_CONTEXT_BLENDING)
|
||||
{
|
||||
functions = blend_functions;
|
||||
array_len = G_N_ELEMENTS (blend_functions);
|
||||
}
|
||||
else
|
||||
{
|
||||
functions = tex_combine_functions;
|
||||
array_len = G_N_ELEMENTS (tex_combine_functions);
|
||||
}
|
||||
|
||||
for (i = 0; i < array_len; i++)
|
||||
{
|
||||
if (len >= functions[i].name_len
|
||||
&& strncmp (mark, functions[i].name, functions[i].name_len) == 0)
|
||||
return &functions[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const CoglBlendStringColorSourceInfo *
|
||||
get_color_src_info (const char *mark,
|
||||
const char *p,
|
||||
CoglBlendStringContext context)
|
||||
{
|
||||
gsize len = p - mark;
|
||||
CoglBlendStringColorSourceInfo *sources;
|
||||
gsize array_len;
|
||||
int i;
|
||||
|
||||
if (context == COGL_BLEND_STRING_CONTEXT_BLENDING)
|
||||
{
|
||||
sources = blending_color_sources;
|
||||
array_len = G_N_ELEMENTS (blending_color_sources);
|
||||
}
|
||||
else
|
||||
{
|
||||
sources = tex_combine_color_sources;
|
||||
array_len = G_N_ELEMENTS (tex_combine_color_sources);
|
||||
}
|
||||
|
||||
for (i = 0; i < array_len; i++)
|
||||
{
|
||||
if (len >= sources[i].name_len
|
||||
&& strncmp (mark, sources[i].name, sources[i].name_len) == 0)
|
||||
return &sources[i];
|
||||
}
|
||||
|
||||
if (len >= 9 &&
|
||||
strncmp (mark, "TEXTURE_", 8) == 0 &&
|
||||
g_ascii_isdigit (mark[8]))
|
||||
{
|
||||
return &tex_combine_texture_n_color_source;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_symbol_char (const char c)
|
||||
{
|
||||
return (g_ascii_isalpha (c) || c == '_') ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_alphanum_char (const char c)
|
||||
{
|
||||
return (g_ascii_isalnum (c) || c == '_') ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_argument (const char *string, /* original user string */
|
||||
const char **ret_p, /* start of argument IN:OUT */
|
||||
const CoglBlendStringStatement *statement,
|
||||
int current_arg,
|
||||
CoglBlendStringArgument *arg, /* OUT */
|
||||
CoglBlendStringContext context,
|
||||
GError **error)
|
||||
{
|
||||
const char *p = *ret_p;
|
||||
const char *mark = NULL;
|
||||
const char *error_string = NULL;
|
||||
ParserArgState state = PARSER_ARG_STATE_START;
|
||||
gboolean parsing_factor = FALSE;
|
||||
|
||||
arg->source.is_zero = FALSE;
|
||||
arg->source.info = NULL;
|
||||
arg->source.texture = 0;
|
||||
arg->source.one_minus = FALSE;
|
||||
arg->source.mask = statement->mask;
|
||||
|
||||
arg->factor.is_one = FALSE;
|
||||
arg->factor.is_color = FALSE;
|
||||
arg->factor.is_src_alpha_saturate = FALSE;
|
||||
|
||||
arg->factor.source.is_zero = FALSE;
|
||||
arg->factor.source.info = NULL;
|
||||
arg->factor.source.texture = 0;
|
||||
arg->factor.source.one_minus = FALSE;
|
||||
arg->factor.source.mask = statement->mask;
|
||||
|
||||
do
|
||||
{
|
||||
if (g_ascii_isspace (*p))
|
||||
continue;
|
||||
|
||||
if (*p == '\0')
|
||||
{
|
||||
error_string = "Unexpected end of string while parsing argument";
|
||||
goto error;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case PARSER_ARG_STATE_START:
|
||||
if (*p == '1')
|
||||
state = PARSER_ARG_STATE_EXPECT_MINUS;
|
||||
else if (*p == '0')
|
||||
{
|
||||
arg->source.is_zero = TRUE;
|
||||
state = PARSER_ARG_STATE_EXPECT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
p--; /* backtrack */
|
||||
state = PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME;
|
||||
}
|
||||
continue;
|
||||
|
||||
case PARSER_ARG_STATE_EXPECT_MINUS:
|
||||
if (*p != '-')
|
||||
{
|
||||
error_string = "expected a '-' following the 1";
|
||||
goto error;
|
||||
}
|
||||
arg->source.one_minus = TRUE;
|
||||
state = PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME;
|
||||
continue;
|
||||
|
||||
case PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME:
|
||||
if (!is_symbol_char (*p))
|
||||
{
|
||||
error_string = "expected a color source name";
|
||||
goto error;
|
||||
}
|
||||
state = PARSER_ARG_STATE_SCRAPING_COLOR_SRC_NAME;
|
||||
mark = p;
|
||||
if (parsing_factor)
|
||||
arg->factor.is_color = TRUE;
|
||||
|
||||
/* fall through */
|
||||
case PARSER_ARG_STATE_SCRAPING_COLOR_SRC_NAME:
|
||||
if (!is_symbol_char (*p))
|
||||
{
|
||||
CoglBlendStringColorSource *source =
|
||||
parsing_factor ? &arg->factor.source : &arg->source;
|
||||
source->info = get_color_src_info (mark, p, context);
|
||||
if (!source->info)
|
||||
{
|
||||
error_string = "Unknown color source name";
|
||||
goto error;
|
||||
}
|
||||
if (source->info->type ==
|
||||
COGL_BLEND_STRING_COLOR_SOURCE_TEXTURE_N)
|
||||
{
|
||||
char *endp;
|
||||
source->texture =
|
||||
strtoul (&mark[strlen ("TEXTURE_")], &endp, 10);
|
||||
if (mark == endp)
|
||||
{
|
||||
error_string = "invalid texture number given with "
|
||||
"TEXTURE_N color source";
|
||||
goto error;
|
||||
}
|
||||
p = endp;
|
||||
}
|
||||
state = PARSER_ARG_STATE_MAYBE_COLOR_MASK;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
/* fall through */
|
||||
case PARSER_ARG_STATE_MAYBE_COLOR_MASK:
|
||||
if (*p != '[')
|
||||
{
|
||||
p--; /* backtrack */
|
||||
if (!parsing_factor)
|
||||
state = PARSER_ARG_STATE_MAYBE_MULT;
|
||||
else
|
||||
state = PARSER_ARG_STATE_EXPECT_END;
|
||||
continue;
|
||||
}
|
||||
state = PARSER_ARG_STATE_SCRAPING_MASK;
|
||||
mark = p;
|
||||
|
||||
/* fall through */
|
||||
case PARSER_ARG_STATE_SCRAPING_MASK:
|
||||
if (*p == ']')
|
||||
{
|
||||
gsize len = p - mark;
|
||||
CoglBlendStringColorSource *source =
|
||||
parsing_factor ? &arg->factor.source : &arg->source;
|
||||
|
||||
if (len == 5 && strncmp (mark, "[RGBA", len) == 0)
|
||||
{
|
||||
if (statement->mask != COGL_BLEND_STRING_CHANNEL_MASK_RGBA)
|
||||
{
|
||||
error_string = "You can't use an RGBA color mask if the "
|
||||
"statement hasn't also got an RGBA= mask";
|
||||
goto error;
|
||||
}
|
||||
source->mask = COGL_BLEND_STRING_CHANNEL_MASK_RGBA;
|
||||
}
|
||||
else if (len == 4 && strncmp (mark, "[RGB", len) == 0)
|
||||
source->mask = COGL_BLEND_STRING_CHANNEL_MASK_RGB;
|
||||
else if (len == 2 && strncmp (mark, "[A", len) == 0)
|
||||
source->mask = COGL_BLEND_STRING_CHANNEL_MASK_ALPHA;
|
||||
else
|
||||
{
|
||||
error_string = "Expected a channel mask of [RGBA]"
|
||||
"[RGB] or [A]";
|
||||
goto error;
|
||||
}
|
||||
if (parsing_factor)
|
||||
state = PARSER_ARG_STATE_EXPECT_CLOSE_PAREN;
|
||||
else
|
||||
state = PARSER_ARG_STATE_MAYBE_MULT;
|
||||
}
|
||||
continue;
|
||||
|
||||
case PARSER_ARG_STATE_EXPECT_OPEN_PAREN:
|
||||
if (*p != '(')
|
||||
{
|
||||
error_string = "Expected '(' before blend factor - the parser "
|
||||
"currently requires that all blend factors "
|
||||
"following a '*' be surrounded in brackets";
|
||||
goto error;
|
||||
}
|
||||
parsing_factor = TRUE;
|
||||
state = PARSER_ARG_STATE_EXPECT_FACTOR;
|
||||
continue;
|
||||
|
||||
case PARSER_ARG_STATE_EXPECT_FACTOR:
|
||||
if (*p == '1')
|
||||
state = PARSER_ARG_STATE_MAYBE_MINUS;
|
||||
else if (*p == '0')
|
||||
{
|
||||
arg->source.is_zero = TRUE;
|
||||
state = PARSER_ARG_STATE_EXPECT_CLOSE_PAREN;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = PARSER_ARG_STATE_MAYBE_SRC_ALPHA_SATURATE;
|
||||
mark = p;
|
||||
}
|
||||
continue;
|
||||
|
||||
case PARSER_ARG_STATE_MAYBE_SRC_ALPHA_SATURATE:
|
||||
if (!is_symbol_char (*p))
|
||||
{
|
||||
gsize len = p - mark;
|
||||
if (len >= strlen ("SRC_ALPHA_SATURATE") &&
|
||||
strncmp (mark, "SRC_ALPHA_SATURATE", len) == 0)
|
||||
{
|
||||
arg->factor.is_src_alpha_saturate = TRUE;
|
||||
state = PARSER_ARG_STATE_EXPECT_CLOSE_PAREN;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME;
|
||||
p = mark - 1; /* backtrack */
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
||||
case PARSER_ARG_STATE_MAYBE_MINUS:
|
||||
if (*p == '-')
|
||||
{
|
||||
arg->factor.source.one_minus = TRUE;
|
||||
state = PARSER_ARG_STATE_EXPECT_COLOR_SRC_NAME;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg->factor.is_one = TRUE;
|
||||
state = PARSER_ARG_STATE_EXPECT_CLOSE_PAREN;
|
||||
}
|
||||
continue;
|
||||
|
||||
case PARSER_ARG_STATE_EXPECT_CLOSE_PAREN:
|
||||
if (*p != ')')
|
||||
{
|
||||
error_string = "Expected closing parenthesis after blend factor";
|
||||
goto error;
|
||||
}
|
||||
state = PARSER_ARG_STATE_EXPECT_END;
|
||||
continue;
|
||||
|
||||
case PARSER_ARG_STATE_MAYBE_MULT:
|
||||
if (*p == '*')
|
||||
{
|
||||
state = PARSER_ARG_STATE_EXPECT_OPEN_PAREN;
|
||||
continue;
|
||||
}
|
||||
arg->factor.is_one = TRUE;
|
||||
state = PARSER_ARG_STATE_EXPECT_END;
|
||||
|
||||
/* fall through */
|
||||
case PARSER_ARG_STATE_EXPECT_END:
|
||||
if (*p != ',' && *p != ')')
|
||||
{
|
||||
error_string = "expected , or )";
|
||||
goto error;
|
||||
}
|
||||
|
||||
*ret_p = p - 1;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
while (p++);
|
||||
|
||||
error:
|
||||
{
|
||||
int offset = p - string;
|
||||
g_set_error (error,
|
||||
COGL_BLEND_STRING_ERROR,
|
||||
COGL_BLEND_STRING_ERROR_ARGUMENT_PARSE_ERROR,
|
||||
"Syntax error for argument %d at offset %d: %s",
|
||||
current_arg,
|
||||
offset,
|
||||
error_string);
|
||||
|
||||
if (COGL_DEBUG_ENABLED (COGL_DEBUG_BLEND_STRINGS))
|
||||
{
|
||||
g_debug ("Syntax error for argument %d at offset %d: %s",
|
||||
current_arg, offset, error_string);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
_cogl_blend_string_compile (const char *string,
|
||||
CoglBlendStringContext context,
|
||||
CoglBlendStringStatement *statements,
|
||||
GError **error)
|
||||
{
|
||||
const char *p = string;
|
||||
const char *mark = NULL;
|
||||
const char *error_string;
|
||||
ParserState state = PARSER_STATE_EXPECT_DEST_CHANNELS;
|
||||
CoglBlendStringStatement *statement = statements;
|
||||
int current_statement = 0;
|
||||
int current_arg = 0;
|
||||
int remaining_argc = 0;
|
||||
|
||||
#if 0
|
||||
COGL_DEBUG_SET_FLAG (COGL_DEBUG_BLEND_STRINGS);
|
||||
#endif
|
||||
|
||||
if (COGL_DEBUG_ENABLED (COGL_DEBUG_BLEND_STRINGS))
|
||||
{
|
||||
COGL_NOTE (BLEND_STRINGS, "Compiling %s string:\n%s\n",
|
||||
context == COGL_BLEND_STRING_CONTEXT_BLENDING ?
|
||||
"blend" : "texture combine",
|
||||
string);
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (g_ascii_isspace (*p))
|
||||
continue;
|
||||
|
||||
if (*p == '\0')
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case PARSER_STATE_EXPECT_DEST_CHANNELS:
|
||||
if (current_statement != 0)
|
||||
goto finished;
|
||||
error_string = "Empty statement";
|
||||
goto error;
|
||||
case PARSER_STATE_SCRAPING_DEST_CHANNELS:
|
||||
error_string = "Expected an '=' following the destination "
|
||||
"channel mask";
|
||||
goto error;
|
||||
case PARSER_STATE_EXPECT_FUNCTION_NAME:
|
||||
error_string = "Expected a function name";
|
||||
goto error;
|
||||
case PARSER_STATE_SCRAPING_FUNCTION_NAME:
|
||||
error_string = "Expected parenthesis after the function name";
|
||||
goto error;
|
||||
case PARSER_STATE_EXPECT_ARG_START:
|
||||
error_string = "Expected to find the start of an argument";
|
||||
goto error;
|
||||
case PARSER_STATE_EXPECT_STATEMENT_END:
|
||||
error_string = "Expected closing parenthesis for statement";
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case PARSER_STATE_EXPECT_DEST_CHANNELS:
|
||||
mark = p;
|
||||
state = PARSER_STATE_SCRAPING_DEST_CHANNELS;
|
||||
|
||||
/* fall through */
|
||||
case PARSER_STATE_SCRAPING_DEST_CHANNELS:
|
||||
if (*p != '=')
|
||||
continue;
|
||||
if (strncmp (mark, "RGBA", 4) == 0)
|
||||
statement->mask = COGL_BLEND_STRING_CHANNEL_MASK_RGBA;
|
||||
else if (strncmp (mark, "RGB", 3) == 0)
|
||||
statement->mask = COGL_BLEND_STRING_CHANNEL_MASK_RGB;
|
||||
else if (strncmp (mark, "A", 1) == 0)
|
||||
statement->mask = COGL_BLEND_STRING_CHANNEL_MASK_ALPHA;
|
||||
else
|
||||
{
|
||||
error_string = "Unknown destination channel mask; "
|
||||
"expected RGBA=, RGB= or A=";
|
||||
goto error;
|
||||
}
|
||||
state = PARSER_STATE_EXPECT_FUNCTION_NAME;
|
||||
continue;
|
||||
|
||||
case PARSER_STATE_EXPECT_FUNCTION_NAME:
|
||||
mark = p;
|
||||
state = PARSER_STATE_SCRAPING_FUNCTION_NAME;
|
||||
|
||||
/* fall through */
|
||||
case PARSER_STATE_SCRAPING_FUNCTION_NAME:
|
||||
if (*p != '(')
|
||||
{
|
||||
if (!is_alphanum_char (*p))
|
||||
{
|
||||
error_string = "non alpha numeric character in function"
|
||||
"name";
|
||||
goto error;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
statement->function = get_function_info (mark, p, context);
|
||||
if (!statement->function)
|
||||
{
|
||||
error_string = "Unknown function name";
|
||||
goto error;
|
||||
}
|
||||
remaining_argc = statement->function->argc;
|
||||
current_arg = 0;
|
||||
state = PARSER_STATE_EXPECT_ARG_START;
|
||||
|
||||
/* fall through */
|
||||
case PARSER_STATE_EXPECT_ARG_START:
|
||||
if (*p != '(' && *p != ',')
|
||||
continue;
|
||||
if (remaining_argc)
|
||||
{
|
||||
p++; /* parse_argument expects to see the first char of the arg */
|
||||
if (!parse_argument (string, &p, statement,
|
||||
current_arg, &statement->args[current_arg],
|
||||
context, error))
|
||||
return 0;
|
||||
current_arg++;
|
||||
remaining_argc--;
|
||||
}
|
||||
if (!remaining_argc)
|
||||
state = PARSER_STATE_EXPECT_STATEMENT_END;
|
||||
continue;
|
||||
|
||||
case PARSER_STATE_EXPECT_STATEMENT_END:
|
||||
if (*p != ')')
|
||||
{
|
||||
error_string = "Expected end of statement";
|
||||
goto error;
|
||||
}
|
||||
state = PARSER_STATE_EXPECT_DEST_CHANNELS;
|
||||
if (current_statement++ == 1)
|
||||
goto finished;
|
||||
statement = &statements[current_statement];
|
||||
}
|
||||
}
|
||||
while (p++);
|
||||
|
||||
finished:
|
||||
|
||||
if (COGL_DEBUG_ENABLED (COGL_DEBUG_BLEND_STRINGS))
|
||||
{
|
||||
if (current_statement > 0)
|
||||
print_statement (0, &statements[0]);
|
||||
if (current_statement > 1)
|
||||
print_statement (1, &statements[1]);
|
||||
}
|
||||
|
||||
if (!validate_statements_for_context (statements,
|
||||
current_statement,
|
||||
context,
|
||||
error))
|
||||
return 0;
|
||||
|
||||
return current_statement;
|
||||
|
||||
error:
|
||||
{
|
||||
int offset = p - string;
|
||||
g_set_error (error,
|
||||
COGL_BLEND_STRING_ERROR,
|
||||
COGL_BLEND_STRING_ERROR_PARSE_ERROR,
|
||||
"Syntax error at offset %d: %s",
|
||||
offset,
|
||||
error_string);
|
||||
|
||||
if (COGL_DEBUG_ENABLED (COGL_DEBUG_BLEND_STRINGS))
|
||||
{
|
||||
g_debug ("Syntax error at offset %d: %s",
|
||||
offset, error_string);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* INTERNAL TESTING CODE ...
|
||||
*/
|
||||
|
||||
struct _TestString
|
||||
{
|
||||
const char *string;
|
||||
CoglBlendStringContext context;
|
||||
};
|
||||
|
||||
int
|
||||
_cogl_blend_string_test (void)
|
||||
{
|
||||
struct _TestString strings[] = {
|
||||
{" A = MODULATE ( TEXTURE[RGB], PREVIOUS[A], PREVIOUS[A] ) ",
|
||||
COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE },
|
||||
{" RGB = MODULATE ( TEXTURE[RGB], PREVIOUS[A] ) ",
|
||||
COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE },
|
||||
{"A=ADD(TEXTURE[A],PREVIOUS[RGB])",
|
||||
COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE },
|
||||
{"A=ADD(TEXTURE[A],PREVIOUS[RGB])",
|
||||
COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE },
|
||||
|
||||
{"RGBA = ADD(SRC_COLOR*(SRC_COLOR[A]), DST_COLOR*(1-SRC_COLOR[A]))",
|
||||
COGL_BLEND_STRING_CONTEXT_BLENDING },
|
||||
{"RGB = ADD(SRC_COLOR, DST_COLOR*(0))",
|
||||
COGL_BLEND_STRING_CONTEXT_BLENDING },
|
||||
{"RGB = ADD(SRC_COLOR, 0)",
|
||||
COGL_BLEND_STRING_CONTEXT_BLENDING },
|
||||
{"RGB = ADD()",
|
||||
COGL_BLEND_STRING_CONTEXT_BLENDING },
|
||||
{"RGB = ADD(SRC_COLOR, 0, DST_COLOR)",
|
||||
COGL_BLEND_STRING_CONTEXT_BLENDING },
|
||||
{NULL}
|
||||
};
|
||||
int i;
|
||||
|
||||
GError *error = NULL;
|
||||
for (i = 0; strings[i].string; i++)
|
||||
{
|
||||
CoglBlendStringStatement statements[2];
|
||||
int count = _cogl_blend_string_compile (strings[i].string,
|
||||
strings[i].context,
|
||||
statements,
|
||||
&error);
|
||||
if (!count)
|
||||
{
|
||||
g_print ("Failed to parse string:\n%s\n%s\n",
|
||||
strings[i].string,
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
error = NULL;
|
||||
continue;
|
||||
}
|
||||
g_print ("Original:\n");
|
||||
g_print ("%s\n", strings[i].string);
|
||||
if (count > 0)
|
||||
print_statement (0, &statements[0]);
|
||||
if (count > 1)
|
||||
print_statement (1, &statements[1]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef COGL_BLEND_STRING_H
|
||||
#define COGL_BLEND_STRING_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <glib.h>
|
||||
|
||||
typedef enum _CoglBlendStringContext
|
||||
{
|
||||
COGL_BLEND_STRING_CONTEXT_BLENDING,
|
||||
COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE
|
||||
} CoglBlendStringContext;
|
||||
|
||||
/* NB: debug stringify code will get upset if these
|
||||
* are re-ordered */
|
||||
typedef enum _CoglBlendStringChannelMask
|
||||
{
|
||||
COGL_BLEND_STRING_CHANNEL_MASK_RGB,
|
||||
COGL_BLEND_STRING_CHANNEL_MASK_ALPHA,
|
||||
COGL_BLEND_STRING_CHANNEL_MASK_RGBA
|
||||
} CoglBlendStringChannelMask;
|
||||
|
||||
typedef enum _CoglBlendStringColorSourceType
|
||||
{
|
||||
/* blending */
|
||||
COGL_BLEND_STRING_COLOR_SOURCE_SRC_COLOR,
|
||||
COGL_BLEND_STRING_COLOR_SOURCE_DST_COLOR,
|
||||
|
||||
/* shared */
|
||||
COGL_BLEND_STRING_COLOR_SOURCE_CONSTANT,
|
||||
|
||||
/* texture combining */
|
||||
COGL_BLEND_STRING_COLOR_SOURCE_TEXTURE,
|
||||
COGL_BLEND_STRING_COLOR_SOURCE_TEXTURE_N,
|
||||
COGL_BLEND_STRING_COLOR_SOURCE_PRIMARY,
|
||||
COGL_BLEND_STRING_COLOR_SOURCE_PREVIOUS
|
||||
} CoglBlendStringColorSourceType;
|
||||
|
||||
typedef struct _CoglBlendStringColorSourceInfo
|
||||
{
|
||||
CoglBlendStringColorSourceType type;
|
||||
const char *name;
|
||||
gsize name_len;
|
||||
} CoglBlendStringColorSourceInfo;
|
||||
|
||||
typedef struct _CoglBlendStringColorSource
|
||||
{
|
||||
gboolean is_zero;
|
||||
const CoglBlendStringColorSourceInfo *info;
|
||||
int texture; /* for the TEXTURE_N color source */
|
||||
gboolean one_minus;
|
||||
CoglBlendStringChannelMask mask;
|
||||
} CoglBlendStringColorSource;
|
||||
|
||||
typedef struct _CoglBlendStringFactor
|
||||
{
|
||||
gboolean is_one;
|
||||
gboolean is_src_alpha_saturate;
|
||||
gboolean is_color;
|
||||
CoglBlendStringColorSource source;
|
||||
} CoglBlendStringFactor;
|
||||
|
||||
typedef struct _CoglBlendStringArgument
|
||||
{
|
||||
CoglBlendStringColorSource source;
|
||||
CoglBlendStringFactor factor;
|
||||
} CoglBlendStringArgument;
|
||||
|
||||
typedef enum _CoglBlendStringFunctionType
|
||||
{
|
||||
/* shared */
|
||||
COGL_BLEND_STRING_FUNCTION_ADD,
|
||||
|
||||
/* texture combine only */
|
||||
COGL_BLEND_STRING_FUNCTION_REPLACE,
|
||||
COGL_BLEND_STRING_FUNCTION_MODULATE,
|
||||
COGL_BLEND_STRING_FUNCTION_ADD_SIGNED,
|
||||
COGL_BLEND_STRING_FUNCTION_INTERPOLATE,
|
||||
COGL_BLEND_STRING_FUNCTION_SUBTRACT,
|
||||
COGL_BLEND_STRING_FUNCTION_DOT3_RGB,
|
||||
COGL_BLEND_STRING_FUNCTION_DOT3_RGBA
|
||||
} CoglBlendStringFunctionType;
|
||||
|
||||
typedef struct _CoglBlendStringFunctionInfo
|
||||
{
|
||||
enum _CoglBlendStringFunctionType type;
|
||||
const char *name;
|
||||
gsize name_len;
|
||||
int argc;
|
||||
} CoglBlendStringFunctionInfo;
|
||||
|
||||
typedef struct _CoglBlendStringStatement
|
||||
{
|
||||
CoglBlendStringChannelMask mask;
|
||||
const CoglBlendStringFunctionInfo *function;
|
||||
CoglBlendStringArgument args[3];
|
||||
} CoglBlendStringStatement;
|
||||
|
||||
|
||||
gboolean
|
||||
_cogl_blend_string_compile (const char *string,
|
||||
CoglBlendStringContext context,
|
||||
CoglBlendStringStatement *statements,
|
||||
GError **error);
|
||||
|
||||
void
|
||||
_cogl_blend_string_split_rgba_statement (CoglBlendStringStatement *statement,
|
||||
CoglBlendStringStatement *rgb,
|
||||
CoglBlendStringStatement *a);
|
||||
|
||||
#endif /* COGL_BLEND_STRING_H */
|
||||
|
@ -1,395 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Neil Roberts <neil@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-blit.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-framebuffer-private.h"
|
||||
#include "cogl-texture-2d-private.h"
|
||||
|
||||
static const CoglBlitMode *_cogl_blit_default_mode = NULL;
|
||||
|
||||
static gboolean
|
||||
_cogl_blit_texture_render_begin (CoglBlitData *data)
|
||||
{
|
||||
CoglHandle fbo;
|
||||
CoglPipeline *pipeline;
|
||||
unsigned int dst_width, dst_height;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
fbo = _cogl_offscreen_new_to_texture_full
|
||||
(data->dst_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
|
||||
|
||||
if (fbo == COGL_INVALID_HANDLE)
|
||||
return FALSE;
|
||||
|
||||
cogl_push_framebuffer (fbo);
|
||||
cogl_handle_unref (fbo);
|
||||
|
||||
dst_width = cogl_texture_get_width (data->dst_tex);
|
||||
dst_height = cogl_texture_get_height (data->dst_tex);
|
||||
|
||||
/* Set up an orthographic projection so we can use pixel
|
||||
coordinates to render to the texture */
|
||||
cogl_ortho (0, /* left */
|
||||
dst_width, /* right */
|
||||
dst_height, /* bottom */
|
||||
0, /* top */
|
||||
-1, /* near */
|
||||
1 /* far */);
|
||||
|
||||
/* We cache a pipeline used for migrating on to the context so
|
||||
that it doesn't have to continuously regenerate a shader
|
||||
program */
|
||||
if (ctx->blit_texture_pipeline == NULL)
|
||||
{
|
||||
ctx->blit_texture_pipeline = cogl_pipeline_new ();
|
||||
|
||||
cogl_pipeline_set_layer_filters (ctx->blit_texture_pipeline, 0,
|
||||
COGL_PIPELINE_FILTER_NEAREST,
|
||||
COGL_PIPELINE_FILTER_NEAREST);
|
||||
|
||||
/* Disable blending by just directly taking the contents of the
|
||||
source texture */
|
||||
cogl_pipeline_set_blend (ctx->blit_texture_pipeline,
|
||||
"RGBA = ADD(SRC_COLOR, 0)",
|
||||
NULL);
|
||||
}
|
||||
|
||||
pipeline = ctx->blit_texture_pipeline;
|
||||
|
||||
cogl_pipeline_set_layer_texture (pipeline, 0, data->src_tex);
|
||||
|
||||
cogl_push_source (pipeline);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_blit_texture_render_blit (CoglBlitData *data,
|
||||
unsigned int src_x,
|
||||
unsigned int src_y,
|
||||
unsigned int dst_x,
|
||||
unsigned int dst_y,
|
||||
unsigned int width,
|
||||
unsigned int height)
|
||||
{
|
||||
cogl_rectangle_with_texture_coords (dst_x, dst_y,
|
||||
dst_x + width,
|
||||
dst_y + height,
|
||||
src_x / (float) data->src_width,
|
||||
src_y / (float) data->src_height,
|
||||
(src_x + width) /
|
||||
(float) data->src_width,
|
||||
(src_y + height) /
|
||||
(float) data->src_height);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_blit_texture_render_end (CoglBlitData *data)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl_pop_source ();
|
||||
cogl_pop_framebuffer ();
|
||||
|
||||
/* Attach the target texture to the texture render pipeline so that
|
||||
we don't keep a reference to the source texture forever. This is
|
||||
assuming that the destination texture will live for a long time
|
||||
which is currently the case when cogl_blit_* is used from the
|
||||
atlas code. It may be better in future to keep around a set of
|
||||
dummy 1x1 textures for each texture target that we could bind
|
||||
instead. This would also be useful when using a pipeline as a
|
||||
hash table key such as for the ARBfp program cache. */
|
||||
cogl_pipeline_set_layer_texture (ctx->blit_texture_pipeline, 0,
|
||||
data->dst_tex);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_blit_framebuffer_begin (CoglBlitData *data)
|
||||
{
|
||||
CoglHandle dst_fbo, src_fbo;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
/* We can only blit between FBOs if both textures are the same
|
||||
format and the blit framebuffer extension is supported */
|
||||
if ((cogl_texture_get_format (data->src_tex) & ~COGL_A_BIT) !=
|
||||
(cogl_texture_get_format (data->dst_tex) & ~COGL_A_BIT) ||
|
||||
!cogl_features_available (COGL_FEATURE_OFFSCREEN_BLIT))
|
||||
return FALSE;
|
||||
|
||||
dst_fbo = _cogl_offscreen_new_to_texture_full
|
||||
(data->dst_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
|
||||
|
||||
if (dst_fbo == COGL_INVALID_HANDLE)
|
||||
return FALSE;
|
||||
|
||||
src_fbo = _cogl_offscreen_new_to_texture_full
|
||||
(data->src_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
|
||||
|
||||
if (src_fbo == COGL_INVALID_HANDLE)
|
||||
{
|
||||
cogl_handle_unref (dst_fbo);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_cogl_push_framebuffers (dst_fbo, src_fbo);
|
||||
cogl_handle_unref (src_fbo);
|
||||
cogl_handle_unref (dst_fbo);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_blit_framebuffer_blit (CoglBlitData *data,
|
||||
unsigned int src_x,
|
||||
unsigned int src_y,
|
||||
unsigned int dst_x,
|
||||
unsigned int dst_y,
|
||||
unsigned int width,
|
||||
unsigned int height)
|
||||
{
|
||||
_cogl_blit_framebuffer (src_x, src_y,
|
||||
dst_x, dst_y,
|
||||
width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_blit_framebuffer_end (CoglBlitData *data)
|
||||
{
|
||||
cogl_pop_framebuffer ();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_blit_copy_tex_sub_image_begin (CoglBlitData *data)
|
||||
{
|
||||
CoglHandle fbo;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
/* This will only work if the target texture is a CoglTexture2D */
|
||||
if (!_cogl_is_texture_2d (data->dst_tex))
|
||||
return FALSE;
|
||||
|
||||
fbo = _cogl_offscreen_new_to_texture_full
|
||||
(data->src_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
|
||||
|
||||
if (fbo == COGL_INVALID_HANDLE)
|
||||
return FALSE;
|
||||
|
||||
cogl_push_framebuffer (fbo);
|
||||
cogl_handle_unref (fbo);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_blit_copy_tex_sub_image_blit (CoglBlitData *data,
|
||||
unsigned int src_x,
|
||||
unsigned int src_y,
|
||||
unsigned int dst_x,
|
||||
unsigned int dst_y,
|
||||
unsigned int width,
|
||||
unsigned int height)
|
||||
{
|
||||
_cogl_texture_2d_copy_from_framebuffer (data->dst_tex,
|
||||
dst_x, dst_y,
|
||||
src_x, src_y,
|
||||
width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_blit_copy_tex_sub_image_end (CoglBlitData *data)
|
||||
{
|
||||
cogl_pop_framebuffer ();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_blit_get_tex_data_begin (CoglBlitData *data)
|
||||
{
|
||||
data->format = cogl_texture_get_format (data->src_tex);
|
||||
data->bpp = _cogl_get_format_bpp (data->format);
|
||||
|
||||
data->image_data = g_malloc (data->bpp * data->src_width *
|
||||
data->src_height);
|
||||
cogl_texture_get_data (data->src_tex, data->format,
|
||||
data->src_width * data->bpp, data->image_data);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_blit_get_tex_data_blit (CoglBlitData *data,
|
||||
unsigned int src_x,
|
||||
unsigned int src_y,
|
||||
unsigned int dst_x,
|
||||
unsigned int dst_y,
|
||||
unsigned int width,
|
||||
unsigned int height)
|
||||
{
|
||||
cogl_texture_set_region (data->dst_tex,
|
||||
src_x, src_y,
|
||||
dst_x, dst_y,
|
||||
width, height,
|
||||
data->src_width, data->src_height,
|
||||
data->format,
|
||||
data->src_width * data->bpp,
|
||||
data->image_data);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_blit_get_tex_data_end (CoglBlitData *data)
|
||||
{
|
||||
g_free (data->image_data);
|
||||
}
|
||||
|
||||
/* These should be specified in order of preference */
|
||||
static const CoglBlitMode
|
||||
_cogl_blit_modes[] =
|
||||
{
|
||||
{
|
||||
"texture-render",
|
||||
_cogl_blit_texture_render_begin,
|
||||
_cogl_blit_texture_render_blit,
|
||||
_cogl_blit_texture_render_end
|
||||
},
|
||||
{
|
||||
"framebuffer",
|
||||
_cogl_blit_framebuffer_begin,
|
||||
_cogl_blit_framebuffer_blit,
|
||||
_cogl_blit_framebuffer_end
|
||||
},
|
||||
{
|
||||
"copy-tex-sub-image",
|
||||
_cogl_blit_copy_tex_sub_image_begin,
|
||||
_cogl_blit_copy_tex_sub_image_blit,
|
||||
_cogl_blit_copy_tex_sub_image_end
|
||||
},
|
||||
{
|
||||
"get-tex-data",
|
||||
_cogl_blit_get_tex_data_begin,
|
||||
_cogl_blit_get_tex_data_blit,
|
||||
_cogl_blit_get_tex_data_end
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
_cogl_blit_begin (CoglBlitData *data,
|
||||
CoglHandle dst_tex,
|
||||
CoglHandle src_tex)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (_cogl_blit_default_mode == NULL)
|
||||
{
|
||||
const char *default_mode_string;
|
||||
|
||||
/* Allow the default to be specified with an environment
|
||||
variable. For the time being these functions are only used
|
||||
when blitting between atlas textures so the environment
|
||||
variable is named to be specific to the atlas code. If we
|
||||
want to use the code in other places we should create another
|
||||
environment variable for each specific use case */
|
||||
if ((default_mode_string = g_getenv ("COGL_ATLAS_DEFAULT_BLIT_MODE")))
|
||||
{
|
||||
for (i = 0; i < G_N_ELEMENTS (_cogl_blit_modes); i++)
|
||||
if (!strcmp (_cogl_blit_modes[i].name, default_mode_string))
|
||||
{
|
||||
_cogl_blit_default_mode = _cogl_blit_modes + i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i >= G_N_ELEMENTS (_cogl_blit_modes))
|
||||
{
|
||||
g_warning ("Unknown blit mode %s", default_mode_string);
|
||||
_cogl_blit_default_mode = _cogl_blit_modes;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* Default to the first blit mode */
|
||||
_cogl_blit_default_mode = _cogl_blit_modes;
|
||||
}
|
||||
|
||||
data->dst_tex = dst_tex;
|
||||
data->src_tex = src_tex;
|
||||
|
||||
data->src_width = cogl_texture_get_width (src_tex);
|
||||
data->src_height = cogl_texture_get_height (src_tex);
|
||||
|
||||
/* Try the default blit mode first */
|
||||
if (!_cogl_blit_default_mode->begin_func (data))
|
||||
{
|
||||
COGL_NOTE (ATLAS, "Failed to set up blit mode %s",
|
||||
_cogl_blit_default_mode->name);
|
||||
|
||||
/* Try all of the other modes in order */
|
||||
for (i = 0; i < G_N_ELEMENTS (_cogl_blit_modes); i++)
|
||||
if (_cogl_blit_modes + i != _cogl_blit_default_mode &&
|
||||
_cogl_blit_modes[i].begin_func (data))
|
||||
{
|
||||
/* Use this mode as the default from now on */
|
||||
_cogl_blit_default_mode = _cogl_blit_modes + i;
|
||||
break;
|
||||
}
|
||||
else
|
||||
COGL_NOTE (ATLAS,
|
||||
"Failed to set up blit mode %s",
|
||||
_cogl_blit_modes[i].name);
|
||||
|
||||
/* The last blit mode can't fail so this should never happen */
|
||||
g_return_if_fail (i < G_N_ELEMENTS (_cogl_blit_modes));
|
||||
}
|
||||
|
||||
data->blit_mode = _cogl_blit_default_mode;
|
||||
|
||||
COGL_NOTE (ATLAS, "Setup blit using %s", _cogl_blit_default_mode->name);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_blit (CoglBlitData *data,
|
||||
unsigned int src_x,
|
||||
unsigned int src_y,
|
||||
unsigned int dst_x,
|
||||
unsigned int dst_y,
|
||||
unsigned int width,
|
||||
unsigned int height)
|
||||
{
|
||||
data->blit_mode->blit_func (data, src_x, src_y, dst_x, dst_y, width, height);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_blit_end (CoglBlitData *data)
|
||||
{
|
||||
data->blit_mode->end_func (data);
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __COGL_BLIT_H
|
||||
#define __COGL_BLIT_H
|
||||
|
||||
#include <glib.h>
|
||||
#include "cogl-handle.h"
|
||||
|
||||
/* This structures and functions are used when a series of blits needs
|
||||
to be performed between two textures. In this case there are
|
||||
multiple methods we can use, most of which involve transferring
|
||||
between an FBO bound to the texture. */
|
||||
|
||||
typedef struct _CoglBlitData CoglBlitData;
|
||||
|
||||
typedef gboolean (* CoglBlitBeginFunc) (CoglBlitData *data);
|
||||
typedef void (* CoglBlitEndFunc) (CoglBlitData *data);
|
||||
|
||||
typedef void (* CoglBlitFunc) (CoglBlitData *data,
|
||||
unsigned int src_x,
|
||||
unsigned int src_y,
|
||||
unsigned int dst_x,
|
||||
unsigned int dst_y,
|
||||
unsigned int width,
|
||||
unsigned int height);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *name;
|
||||
CoglBlitBeginFunc begin_func;
|
||||
CoglBlitFunc blit_func;
|
||||
CoglBlitEndFunc end_func;
|
||||
} CoglBlitMode;
|
||||
|
||||
struct _CoglBlitData
|
||||
{
|
||||
CoglHandle src_tex, dst_tex;
|
||||
|
||||
unsigned int src_width;
|
||||
unsigned int src_height;
|
||||
|
||||
const CoglBlitMode *blit_mode;
|
||||
|
||||
/* If we're not using an FBO then we g_malloc a buffer and copy the
|
||||
complete texture data in */
|
||||
unsigned char *image_data;
|
||||
CoglPixelFormat format;
|
||||
int bpp;
|
||||
};
|
||||
|
||||
void
|
||||
_cogl_blit_begin (CoglBlitData *data,
|
||||
CoglHandle dst_tex,
|
||||
CoglHandle src_tex);
|
||||
|
||||
void
|
||||
_cogl_blit (CoglBlitData *data,
|
||||
unsigned int src_x,
|
||||
unsigned int src_y,
|
||||
unsigned int dst_x,
|
||||
unsigned int dst_y,
|
||||
unsigned int width,
|
||||
unsigned int height);
|
||||
|
||||
void
|
||||
_cogl_blit_end (CoglBlitData *data);
|
||||
|
||||
#endif /* __COGL_BLIT_H */
|
@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Damien Lespiau <damien.lespiau@intel.com>
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_BUFFER_PRIVATE_H__
|
||||
#define __COGL_BUFFER_PRIVATE_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-object-private.h"
|
||||
#include "cogl-buffer.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define COGL_BUFFER(buffer) ((CoglBuffer *)(buffer))
|
||||
|
||||
typedef struct _CoglBufferVtable CoglBufferVtable;
|
||||
|
||||
struct _CoglBufferVtable
|
||||
{
|
||||
void * (* map) (CoglBuffer *buffer,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints);
|
||||
|
||||
void (* unmap) (CoglBuffer *buffer);
|
||||
|
||||
gboolean (* set_data) (CoglBuffer *buffer,
|
||||
unsigned int offset,
|
||||
const void *data,
|
||||
unsigned int size);
|
||||
};
|
||||
|
||||
typedef enum _CoglBufferFlags
|
||||
{
|
||||
COGL_BUFFER_FLAG_NONE = 0,
|
||||
COGL_BUFFER_FLAG_BUFFER_OBJECT = 1UL << 0, /* real openGL buffer object */
|
||||
COGL_BUFFER_FLAG_MAPPED = 1UL << 1,
|
||||
COGL_BUFFER_FLAG_MAPPED_FALLBACK = 1UL << 2
|
||||
} CoglBufferFlags;
|
||||
|
||||
typedef enum {
|
||||
COGL_BUFFER_USAGE_HINT_TEXTURE,
|
||||
COGL_BUFFER_USAGE_HINT_VERTEX_ARRAY,
|
||||
COGL_BUFFER_USAGE_HINT_INDEX_ARRAY
|
||||
} CoglBufferUsageHint;
|
||||
|
||||
typedef enum {
|
||||
COGL_BUFFER_BIND_TARGET_PIXEL_PACK,
|
||||
COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK,
|
||||
COGL_BUFFER_BIND_TARGET_VERTEX_ARRAY,
|
||||
COGL_BUFFER_BIND_TARGET_INDEX_ARRAY,
|
||||
|
||||
COGL_BUFFER_BIND_TARGET_COUNT
|
||||
} CoglBufferBindTarget;
|
||||
|
||||
struct _CoglBuffer
|
||||
{
|
||||
CoglObject _parent;
|
||||
CoglBufferVtable vtable;
|
||||
|
||||
CoglBufferBindTarget last_target;
|
||||
|
||||
CoglBufferFlags flags;
|
||||
|
||||
GLuint gl_handle; /* OpenGL handle */
|
||||
unsigned int size; /* size of the buffer, in bytes */
|
||||
CoglBufferUsageHint usage_hint;
|
||||
CoglBufferUpdateHint update_hint;
|
||||
|
||||
guint8 *data; /* points to the mapped memory when
|
||||
* the CoglBuffer is a VBO, PBO, ... or
|
||||
* points to allocated memory in the
|
||||
* fallback paths */
|
||||
|
||||
int immutable_ref;
|
||||
|
||||
guint store_created:1;
|
||||
};
|
||||
|
||||
/* This is used to register a type to the list of handle types that
|
||||
will be considered a texture in cogl_is_texture() */
|
||||
void
|
||||
_cogl_buffer_register_buffer_type (GQuark type);
|
||||
|
||||
#define COGL_BUFFER_DEFINE(TypeName, type_name) \
|
||||
COGL_OBJECT_DEFINE_WITH_CODE \
|
||||
(TypeName, type_name, \
|
||||
_cogl_buffer_register_buffer_type (_cogl_object_ \
|
||||
## type_name ## _get_type ()))
|
||||
|
||||
void
|
||||
_cogl_buffer_initialize (CoglBuffer *buffer,
|
||||
unsigned int size,
|
||||
gboolean use_malloc,
|
||||
CoglBufferBindTarget default_target,
|
||||
CoglBufferUsageHint usage_hint,
|
||||
CoglBufferUpdateHint update_hint);
|
||||
|
||||
void
|
||||
_cogl_buffer_fini (CoglBuffer *buffer);
|
||||
|
||||
void *
|
||||
_cogl_buffer_bind (CoglBuffer *buffer,
|
||||
CoglBufferBindTarget target);
|
||||
|
||||
void
|
||||
_cogl_buffer_unbind (CoglBuffer *buffer);
|
||||
|
||||
CoglBufferUsageHint
|
||||
_cogl_buffer_get_usage_hint (CoglBuffer *buffer);
|
||||
|
||||
GLenum
|
||||
_cogl_buffer_access_to_gl_enum (CoglBufferAccess access);
|
||||
|
||||
GLenum
|
||||
_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
|
||||
CoglBufferUpdateHint update_hint);
|
||||
|
||||
CoglBuffer *
|
||||
_cogl_buffer_immutable_ref (CoglBuffer *buffer);
|
||||
|
||||
void
|
||||
_cogl_buffer_immutable_unref (CoglBuffer *buffer);
|
||||
|
||||
/* This is a wrapper around cogl_buffer_map for internal use when we
|
||||
want to map the buffer for write only to replace the entire
|
||||
contents. If the map fails then it will fallback to writing to a
|
||||
temporary buffer. When _cogl_buffer_unmap_for_fill_or_fallback is
|
||||
called the temporary buffer will be copied into the array. Note
|
||||
that these calls share a global array so they can not be nested. */
|
||||
void *
|
||||
_cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer);
|
||||
|
||||
void
|
||||
_cogl_buffer_unmap_for_fill_or_fallback (CoglBuffer *buffer);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_BUFFER_PRIVATE_H__ */
|
@ -1,556 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Damien Lespiau <damien.lespiau@intel.com>
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
/* For an overview of the functionality implemented here, please see
|
||||
* cogl-buffer.h, which contains the gtk-doc section overview for the
|
||||
* Pixel Buffers API.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-util.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-pixel-array-private.h"
|
||||
|
||||
/*
|
||||
* GL/GLES compatibility defines for the buffer API:
|
||||
*/
|
||||
|
||||
#if defined (HAVE_COGL_GL)
|
||||
|
||||
#define glGenBuffers ctx->drv.pf_glGenBuffers
|
||||
#define glBindBuffer ctx->drv.pf_glBindBuffer
|
||||
#define glBufferData ctx->drv.pf_glBufferData
|
||||
#define glBufferSubData ctx->drv.pf_glBufferSubData
|
||||
#define glGetBufferSubData ctx->drv.pf_glGetBufferSubData
|
||||
#define glDeleteBuffers ctx->drv.pf_glDeleteBuffers
|
||||
|
||||
#endif
|
||||
|
||||
/* These two are always accessed through an extension, even on GLES */
|
||||
#define glMapBuffer ctx->drv.pf_glMapBuffer
|
||||
#define glUnmapBuffer ctx->drv.pf_glUnmapBuffer
|
||||
|
||||
#ifndef GL_PIXEL_PACK_BUFFER
|
||||
#define GL_PIXEL_PACK_BUFFER 0x88EB
|
||||
#endif
|
||||
#ifndef GL_PIXEL_UNPACK_BUFFER
|
||||
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
|
||||
#endif
|
||||
#ifndef GL_ARRAY_BUFFER
|
||||
#define GL_ARRAY_BUFFER 0x8892
|
||||
#endif
|
||||
#ifndef GL_ELEMENT_ARRAY_BUFFER
|
||||
#define GL_ARRAY_BUFFER 0x8893
|
||||
#endif
|
||||
#ifndef GL_READ_ONLY
|
||||
#define GL_READ_ONLY 0x88B8
|
||||
#endif
|
||||
#ifndef GL_WRITE_ONLY
|
||||
#define GL_WRITE_ONLY 0x88B9
|
||||
#endif
|
||||
#ifndef GL_READ_WRITE
|
||||
#define GL_READ_WRITE 0x88BA
|
||||
#endif
|
||||
|
||||
/* XXX:
|
||||
* The CoglHandle macros don't support any form of inheritance, so for
|
||||
* now we implement the CoglObject support for the CoglBuffer
|
||||
* abstract class manually.
|
||||
*/
|
||||
|
||||
void
|
||||
_cogl_buffer_register_buffer_type (GQuark type)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
ctx->buffer_types = g_slist_prepend (ctx->buffer_types,
|
||||
GINT_TO_POINTER (type));
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_is_buffer (const void *object)
|
||||
{
|
||||
const CoglHandleObject *obj = object;
|
||||
GSList *l;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
if (object == NULL)
|
||||
return FALSE;
|
||||
|
||||
for (l = ctx->buffer_types; l; l = l->next)
|
||||
if (GPOINTER_TO_INT (l->data) == obj->klass->type)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GLenum
|
||||
convert_bind_target_to_gl_target (CoglBufferBindTarget target)
|
||||
{
|
||||
switch (target)
|
||||
{
|
||||
case COGL_BUFFER_BIND_TARGET_PIXEL_PACK:
|
||||
return GL_PIXEL_PACK_BUFFER;
|
||||
case COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK:
|
||||
return GL_PIXEL_UNPACK_BUFFER;
|
||||
case COGL_BUFFER_BIND_TARGET_VERTEX_ARRAY:
|
||||
return GL_ARRAY_BUFFER;
|
||||
case COGL_BUFFER_BIND_TARGET_INDEX_ARRAY:
|
||||
return GL_ELEMENT_ARRAY_BUFFER;
|
||||
default:
|
||||
g_return_val_if_reached (COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK);
|
||||
}
|
||||
}
|
||||
|
||||
static void *
|
||||
bo_map (CoglBuffer *buffer,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints)
|
||||
{
|
||||
guint8 *data;
|
||||
CoglBufferBindTarget target;
|
||||
GLenum gl_target;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
|
||||
if ((access & COGL_BUFFER_ACCESS_READ) &&
|
||||
!cogl_features_available (COGL_FEATURE_MAP_BUFFER_FOR_READ))
|
||||
return NULL;
|
||||
if ((access & COGL_BUFFER_ACCESS_WRITE) &&
|
||||
!cogl_features_available (COGL_FEATURE_MAP_BUFFER_FOR_WRITE))
|
||||
return NULL;
|
||||
|
||||
target = buffer->last_target;
|
||||
_cogl_buffer_bind (buffer, target);
|
||||
|
||||
gl_target = convert_bind_target_to_gl_target (target);
|
||||
|
||||
/* create an empty store if we don't have one yet. creating the store
|
||||
* lazily allows the user of the CoglBuffer to set a hint before the
|
||||
* store is created. */
|
||||
if (!buffer->store_created || (hints & COGL_BUFFER_MAP_HINT_DISCARD))
|
||||
{
|
||||
GE( glBufferData (gl_target,
|
||||
buffer->size,
|
||||
NULL,
|
||||
_cogl_buffer_hints_to_gl_enum (buffer->usage_hint,
|
||||
buffer->update_hint)) );
|
||||
buffer->store_created = TRUE;
|
||||
}
|
||||
|
||||
GE_RET( data, glMapBuffer (gl_target,
|
||||
_cogl_buffer_access_to_gl_enum (access)) );
|
||||
if (data)
|
||||
buffer->flags |= COGL_BUFFER_FLAG_MAPPED;
|
||||
|
||||
_cogl_buffer_unbind (buffer);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static void
|
||||
bo_unmap (CoglBuffer *buffer)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
_cogl_buffer_bind (buffer, buffer->last_target);
|
||||
|
||||
GE( glUnmapBuffer (convert_bind_target_to_gl_target (buffer->last_target)) );
|
||||
buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED;
|
||||
|
||||
_cogl_buffer_unbind (buffer);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
bo_set_data (CoglBuffer *buffer,
|
||||
unsigned int offset,
|
||||
const void *data,
|
||||
unsigned int size)
|
||||
{
|
||||
CoglBufferBindTarget target;
|
||||
GLenum gl_target;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
target = buffer->last_target;
|
||||
_cogl_buffer_bind (buffer, target);
|
||||
|
||||
gl_target = convert_bind_target_to_gl_target (target);
|
||||
|
||||
/* create an empty store if we don't have one yet. creating the store
|
||||
* lazily allows the user of the CoglBuffer to set a hint before the
|
||||
* store is created. */
|
||||
if (!buffer->store_created)
|
||||
{
|
||||
GE( glBufferData (gl_target,
|
||||
buffer->size,
|
||||
NULL,
|
||||
_cogl_buffer_hints_to_gl_enum (buffer->usage_hint,
|
||||
buffer->update_hint)) );
|
||||
buffer->store_created = TRUE;
|
||||
}
|
||||
|
||||
GE( glBufferSubData (gl_target, offset, size, data) );
|
||||
|
||||
_cogl_buffer_unbind (buffer);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fallback path, buffer->data points to a malloc'ed buffer.
|
||||
*/
|
||||
|
||||
static void *
|
||||
malloc_map (CoglBuffer *buffer,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints)
|
||||
{
|
||||
buffer->flags |= COGL_BUFFER_FLAG_MAPPED;
|
||||
return buffer->data;
|
||||
}
|
||||
|
||||
static void
|
||||
malloc_unmap (CoglBuffer *buffer)
|
||||
{
|
||||
buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
malloc_set_data (CoglBuffer *buffer,
|
||||
unsigned int offset,
|
||||
const void *data,
|
||||
unsigned int size)
|
||||
{
|
||||
memcpy (buffer->data + offset, data, size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_buffer_initialize (CoglBuffer *buffer,
|
||||
unsigned int size,
|
||||
gboolean use_malloc,
|
||||
CoglBufferBindTarget default_target,
|
||||
CoglBufferUsageHint usage_hint,
|
||||
CoglBufferUpdateHint update_hint)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
buffer->flags = COGL_BUFFER_FLAG_NONE;
|
||||
buffer->store_created = FALSE;
|
||||
buffer->size = size;
|
||||
buffer->last_target = default_target;
|
||||
buffer->usage_hint = usage_hint;
|
||||
buffer->update_hint = update_hint;
|
||||
buffer->data = NULL;
|
||||
buffer->immutable_ref = 0;
|
||||
|
||||
if (use_malloc)
|
||||
{
|
||||
buffer->vtable.map = malloc_map;
|
||||
buffer->vtable.unmap = malloc_unmap;
|
||||
buffer->vtable.set_data = malloc_set_data;
|
||||
|
||||
buffer->data = g_malloc (size);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer->vtable.map = bo_map;
|
||||
buffer->vtable.unmap = bo_unmap;
|
||||
buffer->vtable.set_data = bo_set_data;
|
||||
|
||||
GE( glGenBuffers (1, &buffer->gl_handle) );
|
||||
buffer->flags |= COGL_BUFFER_FLAG_BUFFER_OBJECT;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_buffer_fini (CoglBuffer *buffer)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
g_return_if_fail (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED));
|
||||
g_return_if_fail (buffer->immutable_ref == 0);
|
||||
|
||||
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
||||
GE( glDeleteBuffers (1, &buffer->gl_handle) );
|
||||
else
|
||||
g_free (buffer->data);
|
||||
}
|
||||
|
||||
GLenum
|
||||
_cogl_buffer_access_to_gl_enum (CoglBufferAccess access)
|
||||
{
|
||||
if ((access & COGL_BUFFER_ACCESS_READ_WRITE) == COGL_BUFFER_ACCESS_READ_WRITE)
|
||||
return GL_READ_WRITE;
|
||||
else if (access & COGL_BUFFER_ACCESS_WRITE)
|
||||
return GL_WRITE_ONLY;
|
||||
else
|
||||
return GL_READ_ONLY;
|
||||
}
|
||||
|
||||
/* OpenGL ES 1.1 and 2 only know about STATIC_DRAW and DYNAMIC_DRAW */
|
||||
#if defined (COGL_HAS_GLES)
|
||||
GLenum
|
||||
_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
|
||||
CoglBufferUpdateHint update_hint)
|
||||
{
|
||||
/* usage hint is always TEXTURE for now */
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_STATIC)
|
||||
return GL_STATIC_DRAW;
|
||||
return GL_DYNAMIC_DRAW;
|
||||
}
|
||||
#else
|
||||
GLenum
|
||||
_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
|
||||
CoglBufferUpdateHint update_hint)
|
||||
{
|
||||
/* usage hint is always TEXTURE for now */
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_STATIC)
|
||||
return GL_STATIC_DRAW;
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_DYNAMIC)
|
||||
return GL_DYNAMIC_DRAW;
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_STREAM)
|
||||
return GL_STREAM_DRAW;
|
||||
|
||||
return GL_STATIC_DRAW;
|
||||
}
|
||||
#endif
|
||||
|
||||
void *
|
||||
_cogl_buffer_bind (CoglBuffer *buffer, CoglBufferBindTarget target)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
|
||||
g_return_val_if_fail (buffer != NULL, NULL);
|
||||
|
||||
/* Don't allow binding the buffer to multiple targets at the same time */
|
||||
g_return_val_if_fail (ctx->current_buffer[buffer->last_target] != buffer,
|
||||
NULL);
|
||||
|
||||
/* Don't allow nesting binds to the same target */
|
||||
g_return_val_if_fail (ctx->current_buffer[target] == NULL, NULL);
|
||||
|
||||
buffer->last_target = target;
|
||||
ctx->current_buffer[target] = buffer;
|
||||
|
||||
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
||||
{
|
||||
GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target);
|
||||
GE( glBindBuffer (gl_target, buffer->gl_handle) );
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
return buffer->data;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_buffer_unbind (CoglBuffer *buffer)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
g_return_if_fail (buffer != NULL);
|
||||
|
||||
/* the unbind should pair up with a previous bind */
|
||||
g_return_if_fail (ctx->current_buffer[buffer->last_target] == buffer);
|
||||
|
||||
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
||||
{
|
||||
GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target);
|
||||
GE( glBindBuffer (gl_target, 0) );
|
||||
}
|
||||
|
||||
ctx->current_buffer[buffer->last_target] = NULL;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
cogl_buffer_get_size (CoglBuffer *buffer)
|
||||
{
|
||||
if (!cogl_is_buffer (buffer))
|
||||
return 0;
|
||||
|
||||
return COGL_BUFFER (buffer)->size;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_buffer_set_update_hint (CoglBuffer *buffer,
|
||||
CoglBufferUpdateHint hint)
|
||||
{
|
||||
if (!cogl_is_buffer (buffer))
|
||||
return;
|
||||
|
||||
if (G_UNLIKELY (hint > COGL_BUFFER_UPDATE_HINT_STREAM))
|
||||
hint = COGL_BUFFER_UPDATE_HINT_STATIC;
|
||||
|
||||
buffer->update_hint = hint;
|
||||
}
|
||||
|
||||
CoglBufferUpdateHint
|
||||
cogl_buffer_get_update_hint (CoglBuffer *buffer)
|
||||
{
|
||||
if (!cogl_is_buffer (buffer))
|
||||
return FALSE;
|
||||
|
||||
return buffer->update_hint;
|
||||
}
|
||||
|
||||
static void
|
||||
warn_about_midscene_changes (void)
|
||||
{
|
||||
static gboolean seen = FALSE;
|
||||
if (!seen)
|
||||
{
|
||||
g_warning ("Mid-scene modification of buffers has "
|
||||
"undefined results\n");
|
||||
seen = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void *
|
||||
cogl_buffer_map (CoglBuffer *buffer,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints)
|
||||
{
|
||||
g_return_val_if_fail (cogl_is_buffer (buffer), NULL);
|
||||
|
||||
if (G_UNLIKELY (buffer->immutable_ref))
|
||||
warn_about_midscene_changes ();
|
||||
|
||||
if (buffer->flags & COGL_BUFFER_FLAG_MAPPED)
|
||||
return buffer->data;
|
||||
|
||||
buffer->data = buffer->vtable.map (buffer, access, hints);
|
||||
return buffer->data;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_buffer_unmap (CoglBuffer *buffer)
|
||||
{
|
||||
if (!cogl_is_buffer (buffer))
|
||||
return;
|
||||
|
||||
if (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED))
|
||||
return;
|
||||
|
||||
buffer->vtable.unmap (buffer);
|
||||
}
|
||||
|
||||
void *
|
||||
_cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
|
||||
g_return_val_if_fail (!ctx->buffer_map_fallback_in_use, NULL);
|
||||
|
||||
ctx->buffer_map_fallback_in_use = TRUE;
|
||||
|
||||
ret = cogl_buffer_map (buffer,
|
||||
COGL_BUFFER_ACCESS_WRITE,
|
||||
COGL_BUFFER_MAP_HINT_DISCARD);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
else
|
||||
{
|
||||
/* If the map fails then we'll use a temporary buffer to fill
|
||||
the data and then upload it using cogl_buffer_set_data when
|
||||
the buffer is unmapped. The temporary buffer is shared to
|
||||
avoid reallocating it every time */
|
||||
g_byte_array_set_size (ctx->buffer_map_fallback_array, buffer->size);
|
||||
|
||||
buffer->flags |= COGL_BUFFER_FLAG_MAPPED_FALLBACK;
|
||||
|
||||
return ctx->buffer_map_fallback_array->data;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_buffer_unmap_for_fill_or_fallback (CoglBuffer *buffer)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
g_return_if_fail (ctx->buffer_map_fallback_in_use);
|
||||
|
||||
ctx->buffer_map_fallback_in_use = FALSE;
|
||||
|
||||
if ((buffer->flags & COGL_BUFFER_FLAG_MAPPED_FALLBACK))
|
||||
{
|
||||
cogl_buffer_set_data (buffer, 0,
|
||||
ctx->buffer_map_fallback_array->data,
|
||||
buffer->size);
|
||||
buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED_FALLBACK;
|
||||
}
|
||||
else
|
||||
cogl_buffer_unmap (buffer);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_buffer_set_data (CoglBuffer *buffer,
|
||||
gsize offset,
|
||||
const void *data,
|
||||
gsize size)
|
||||
{
|
||||
g_return_val_if_fail (cogl_is_buffer (buffer), FALSE);
|
||||
g_return_val_if_fail ((offset + size) <= buffer->size, FALSE);
|
||||
|
||||
if (G_UNLIKELY (buffer->immutable_ref))
|
||||
warn_about_midscene_changes ();
|
||||
|
||||
return buffer->vtable.set_data (buffer, offset, data, size);
|
||||
}
|
||||
|
||||
CoglBuffer *
|
||||
_cogl_buffer_immutable_ref (CoglBuffer *buffer)
|
||||
{
|
||||
g_return_val_if_fail (cogl_is_buffer (buffer), NULL);
|
||||
|
||||
buffer->immutable_ref++;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_buffer_immutable_unref (CoglBuffer *buffer)
|
||||
{
|
||||
g_return_if_fail (cogl_is_buffer (buffer));
|
||||
g_return_if_fail (buffer->immutable_ref > 0);
|
||||
|
||||
buffer->immutable_ref--;
|
||||
}
|
||||
|
@ -1,242 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C)2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Damien Lespiau <damien.lespiau@intel.com>
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_BUFFER_H__
|
||||
#define __COGL_BUFFER_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <cogl/cogl-types.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-buffer
|
||||
* @short_description: Buffer creation and manipulation
|
||||
* @stability: Unstable
|
||||
*
|
||||
* COGL allows the creation and the manipulation of buffers. If the underlying
|
||||
* OpenGL implementation allows it, COGL will use Pixel Buffer Objects.
|
||||
*/
|
||||
|
||||
/* All of the cogl-buffer API is currently experimental so we suffix
|
||||
* the actual symbols with _EXP so if somone is monitoring for ABI
|
||||
* changes it will hopefully be clearer to them what's going on if any
|
||||
* of the symbols dissapear at a later date.
|
||||
*/
|
||||
#define cogl_is_buffer cogl_is_buffer_EXP
|
||||
#define cogl_buffer_get_size cogl_buffer_get_size_EXP
|
||||
#define cogl_buffer_set_usage_hint cogl_buffer_set_usage_hint_EXP
|
||||
#define cogl_buffer_get_usage_hint cogl_buffer_get_usage_hint_EXP
|
||||
#define cogl_buffer_set_update_hint cogl_buffer_set_update_hint_EXP
|
||||
#define cogl_buffer_get_update_hint cogl_buffer_get_update_hint_EXP
|
||||
#define cogl_buffer_map cogl_buffer_map_EXP
|
||||
#define cogl_buffer_unmap cogl_buffer_unmap_EXP
|
||||
#define cogl_buffer_set_data cogl_buffer_set_data_EXP
|
||||
|
||||
typedef struct _CoglBuffer CoglBuffer;
|
||||
|
||||
/**
|
||||
* cogl_is_buffer:
|
||||
* @buffer: a buffer object
|
||||
*
|
||||
* Checks whether @buffer is a buffer object.
|
||||
*
|
||||
* Return value: %TRUE if the handle is a CoglBuffer, and %FALSE otherwise
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
gboolean
|
||||
cogl_is_buffer (const void *object);
|
||||
|
||||
/**
|
||||
* cogl_buffer_get_size:
|
||||
* @buffer: a buffer object
|
||||
*
|
||||
* Retrieves the size of buffer
|
||||
*
|
||||
* Return value: the size of the buffer in bytes
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
unsigned int
|
||||
cogl_buffer_get_size (CoglBuffer *buffer);
|
||||
|
||||
/**
|
||||
* CoglBufferUpdateHint:
|
||||
* @COGL_BUFFER_UPDATE_HINT_STATIC: the buffer will not change over time
|
||||
* @COGL_BUFFER_UPDATE_HINT_DYNAMIC: the buffer will change from time to time
|
||||
* @COGL_BUFFER_UPDATE_HINT_STREAM: the buffer will be used once or a couple of
|
||||
* times
|
||||
*
|
||||
* The update hint on a buffer allows the user to give some detail on how often
|
||||
* the buffer data is going to be updated.
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
typedef enum { /*< prefix=COGL_BUFFER_UPDATE_HINT >*/
|
||||
COGL_BUFFER_UPDATE_HINT_STATIC,
|
||||
COGL_BUFFER_UPDATE_HINT_DYNAMIC,
|
||||
COGL_BUFFER_UPDATE_HINT_STREAM
|
||||
} CoglBufferUpdateHint;
|
||||
|
||||
/**
|
||||
* cogl_buffer_set_update_hint:
|
||||
* @buffer: a buffer object
|
||||
* @hint: the new hint
|
||||
*
|
||||
* Sets the update hint on a buffer. See #CoglBufferUpdateHint for a description
|
||||
* of the available hints.
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_buffer_set_update_hint (CoglBuffer *buffer,
|
||||
CoglBufferUpdateHint hint);
|
||||
|
||||
/**
|
||||
* cogl_buffer_get_update_hint:
|
||||
* @buffer: a buffer object
|
||||
*
|
||||
* Retrieves the update hints set using cogl_buffer_set_update_hint()
|
||||
*
|
||||
* Return value: the #CoglBufferUpdateHint currently used by the buffer
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
CoglBufferUpdateHint
|
||||
cogl_buffer_get_update_hint (CoglBuffer *buffer);
|
||||
|
||||
/**
|
||||
* CoglBufferAccess:
|
||||
* @COGL_BUFFER_ACCESS_READ: the buffer will be read
|
||||
* @COGL_BUFFER_ACCESS_WRITE: the buffer will written to
|
||||
* @COGL_BUFFER_ACCESS_READ_WRITE: the buffer will be used for both reading and
|
||||
* writing
|
||||
*
|
||||
* The access hints for cogl_buffer_set_update_hint()
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
typedef enum { /*< prefix=COGL_BUFFER_ACCESS >*/
|
||||
COGL_BUFFER_ACCESS_READ = 1 << 0,
|
||||
COGL_BUFFER_ACCESS_WRITE = 1 << 1,
|
||||
COGL_BUFFER_ACCESS_READ_WRITE = COGL_BUFFER_ACCESS_READ | COGL_BUFFER_ACCESS_WRITE
|
||||
} CoglBufferAccess;
|
||||
|
||||
|
||||
/**
|
||||
* CoglBufferMapHint:
|
||||
* @COGL_BUFFER_MAP_HINT_DISCARD: Tells Cogl that you plan to replace
|
||||
* all the buffer's contents.
|
||||
*
|
||||
* Hints to Cogl about how you are planning to modify the data once it
|
||||
* is mapped.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
typedef enum { /*< prefix=COGL_BUFFER_MAP_HINT >*/
|
||||
COGL_BUFFER_MAP_HINT_DISCARD = 1 << 0
|
||||
} CoglBufferMapHint;
|
||||
|
||||
/**
|
||||
* cogl_buffer_map:
|
||||
* @buffer: a buffer object
|
||||
* @access: how the mapped buffer will be used by the application
|
||||
* @hints: A mask of #CoglBufferMapHint<!-- -->s that tell Cogl how
|
||||
* the data will be modified once mapped.
|
||||
*
|
||||
* Maps the buffer into the application address space for direct access.
|
||||
*
|
||||
* It is strongly recommended that you pass
|
||||
* %COGL_BUFFER_MAP_HINT_DISCARD as a hint if you are going to replace
|
||||
* all the buffer's data. This way if the buffer is currently being
|
||||
* used by the GPU then the driver won't have to stall the CPU and
|
||||
* wait for the hardware to finish because it can instead allocate a
|
||||
* new buffer to map.
|
||||
*
|
||||
* The behaviour is undefined if you access the buffer in a way
|
||||
* conflicting with the @access mask you pass. It is also an error to
|
||||
* release your last reference while the buffer is mapped.
|
||||
*
|
||||
* Return value: A pointer to the mapped memory or %NULL is the call fails
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void *
|
||||
cogl_buffer_map (CoglBuffer *buffer,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints);
|
||||
|
||||
/**
|
||||
* cogl_buffer_unmap:
|
||||
* @buffer: a buffer object
|
||||
*
|
||||
* Unmaps a buffer previously mapped by cogl_buffer_map().
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_buffer_unmap (CoglBuffer *buffer);
|
||||
|
||||
/**
|
||||
* cogl_buffer_set_data:
|
||||
* @buffer: a buffer object
|
||||
* @offset: destination offset (in bytes) in the buffer
|
||||
* @data: a pointer to the data to be copied into the buffer
|
||||
* @size: number of bytes to copy
|
||||
*
|
||||
* Updates part of the buffer with new data from @data. Where to put this new
|
||||
* data is controlled by @offset and @offset + @data should be less than the
|
||||
* buffer size.
|
||||
*
|
||||
* Return value: %TRUE is the operation succeeded, %FALSE otherwise
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
gboolean
|
||||
cogl_buffer_set_data (CoglBuffer *buffer,
|
||||
gsize offset,
|
||||
const void *data,
|
||||
gsize size);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_BUFFER_H__ */
|
@ -1,748 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-clip-stack.h"
|
||||
#include "cogl-primitives.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-framebuffer-private.h"
|
||||
#include "cogl-journal-private.h"
|
||||
#include "cogl-util.h"
|
||||
#include "cogl-path-private.h"
|
||||
#include "cogl-matrix-private.h"
|
||||
#include "cogl-primitives-private.h"
|
||||
|
||||
#ifndef GL_CLIP_PLANE0
|
||||
#define GL_CLIP_PLANE0 0x3000
|
||||
#define GL_CLIP_PLANE1 0x3001
|
||||
#define GL_CLIP_PLANE2 0x3002
|
||||
#define GL_CLIP_PLANE3 0x3003
|
||||
#define GL_CLIP_PLANE4 0x3004
|
||||
#define GL_CLIP_PLANE5 0x3005
|
||||
#endif
|
||||
|
||||
static void
|
||||
project_vertex (const CoglMatrix *modelview_projection,
|
||||
float *vertex)
|
||||
{
|
||||
int i;
|
||||
|
||||
cogl_matrix_transform_point (modelview_projection,
|
||||
&vertex[0], &vertex[1],
|
||||
&vertex[2], &vertex[3]);
|
||||
|
||||
/* Convert from homogenized coordinates */
|
||||
for (i = 0; i < 4; i++)
|
||||
vertex[i] /= vertex[3];
|
||||
}
|
||||
|
||||
static void
|
||||
set_clip_plane (GLint plane_num,
|
||||
const float *vertex_a,
|
||||
const float *vertex_b)
|
||||
{
|
||||
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
|
||||
GLfloat plane[4];
|
||||
#else
|
||||
GLdouble plane[4];
|
||||
#endif
|
||||
GLfloat angle;
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglMatrixStack *modelview_stack =
|
||||
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
||||
CoglMatrixStack *projection_stack =
|
||||
_cogl_framebuffer_get_projection_stack (framebuffer);
|
||||
CoglMatrix inverse_projection;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
_cogl_matrix_stack_get_inverse (projection_stack, &inverse_projection);
|
||||
|
||||
/* Calculate the angle between the axes and the line crossing the
|
||||
two points */
|
||||
angle = atan2f (vertex_b[1] - vertex_a[1],
|
||||
vertex_b[0] - vertex_a[0]) * (180.0/G_PI);
|
||||
|
||||
_cogl_matrix_stack_push (modelview_stack);
|
||||
|
||||
/* Load the inverse of the projection matrix so we can specify the plane
|
||||
* in screen coordinates */
|
||||
_cogl_matrix_stack_set (modelview_stack, &inverse_projection);
|
||||
|
||||
/* Rotate about point a */
|
||||
_cogl_matrix_stack_translate (modelview_stack,
|
||||
vertex_a[0], vertex_a[1], vertex_a[2]);
|
||||
/* Rotate the plane by the calculated angle so that it will connect
|
||||
the two points */
|
||||
_cogl_matrix_stack_rotate (modelview_stack, angle, 0.0f, 0.0f, 1.0f);
|
||||
_cogl_matrix_stack_translate (modelview_stack,
|
||||
-vertex_a[0], -vertex_a[1], -vertex_a[2]);
|
||||
|
||||
_cogl_matrix_stack_flush_to_gl (modelview_stack, COGL_MATRIX_MODELVIEW);
|
||||
|
||||
plane[0] = 0;
|
||||
plane[1] = -1.0;
|
||||
plane[2] = 0;
|
||||
plane[3] = vertex_a[1];
|
||||
#if defined (HAVE_COGL_GLES2)
|
||||
g_assert_not_reached ();
|
||||
#elif defined (HAVE_COGL_GLES)
|
||||
GE( glClipPlanef (plane_num, plane) );
|
||||
#else
|
||||
GE( glClipPlane (plane_num, plane) );
|
||||
#endif
|
||||
|
||||
_cogl_matrix_stack_pop (modelview_stack);
|
||||
}
|
||||
|
||||
static void
|
||||
set_clip_planes (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2)
|
||||
{
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglMatrixStack *modelview_stack =
|
||||
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
||||
CoglMatrix modelview_matrix;
|
||||
CoglMatrixStack *projection_stack =
|
||||
_cogl_framebuffer_get_projection_stack (framebuffer);
|
||||
CoglMatrix projection_matrix;
|
||||
CoglMatrix modelview_projection;
|
||||
float signed_area;
|
||||
|
||||
float vertex_tl[4] = { x_1, y_1, 0, 1.0 };
|
||||
float vertex_tr[4] = { x_2, y_1, 0, 1.0 };
|
||||
float vertex_bl[4] = { x_1, y_2, 0, 1.0 };
|
||||
float vertex_br[4] = { x_2, y_2, 0, 1.0 };
|
||||
|
||||
_cogl_matrix_stack_get (projection_stack, &projection_matrix);
|
||||
_cogl_matrix_stack_get (modelview_stack, &modelview_matrix);
|
||||
|
||||
cogl_matrix_multiply (&modelview_projection,
|
||||
&projection_matrix,
|
||||
&modelview_matrix);
|
||||
|
||||
project_vertex (&modelview_projection, vertex_tl);
|
||||
project_vertex (&modelview_projection, vertex_tr);
|
||||
project_vertex (&modelview_projection, vertex_bl);
|
||||
project_vertex (&modelview_projection, vertex_br);
|
||||
|
||||
/* Calculate the signed area of the polygon formed by the four
|
||||
vertices so that we can know its orientation */
|
||||
signed_area = (vertex_tl[0] * (vertex_tr[1] - vertex_bl[1])
|
||||
+ vertex_tr[0] * (vertex_br[1] - vertex_tl[1])
|
||||
+ vertex_br[0] * (vertex_bl[1] - vertex_tr[1])
|
||||
+ vertex_bl[0] * (vertex_tl[1] - vertex_br[1]));
|
||||
|
||||
/* Set the clip planes to form lines between all of the vertices
|
||||
using the same orientation as we calculated */
|
||||
if (signed_area > 0.0f)
|
||||
{
|
||||
/* counter-clockwise */
|
||||
set_clip_plane (GL_CLIP_PLANE0, vertex_tl, vertex_bl);
|
||||
set_clip_plane (GL_CLIP_PLANE1, vertex_bl, vertex_br);
|
||||
set_clip_plane (GL_CLIP_PLANE2, vertex_br, vertex_tr);
|
||||
set_clip_plane (GL_CLIP_PLANE3, vertex_tr, vertex_tl);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* clockwise */
|
||||
set_clip_plane (GL_CLIP_PLANE0, vertex_tl, vertex_tr);
|
||||
set_clip_plane (GL_CLIP_PLANE1, vertex_tr, vertex_br);
|
||||
set_clip_plane (GL_CLIP_PLANE2, vertex_br, vertex_bl);
|
||||
set_clip_plane (GL_CLIP_PLANE3, vertex_bl, vertex_tl);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
add_stencil_clip_rectangle (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2,
|
||||
gboolean first)
|
||||
{
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglMatrixStack *modelview_stack =
|
||||
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
||||
CoglMatrixStack *projection_stack =
|
||||
_cogl_framebuffer_get_projection_stack (framebuffer);
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
/* temporarily swap in our special stenciling pipeline */
|
||||
cogl_push_source (ctx->stencil_pipeline);
|
||||
|
||||
/* This can be called from the journal code which doesn't flush
|
||||
the matrix stacks between calls so we need to ensure they're
|
||||
flushed now */
|
||||
_cogl_matrix_stack_flush_to_gl (modelview_stack,
|
||||
COGL_MATRIX_MODELVIEW);
|
||||
_cogl_matrix_stack_flush_to_gl (projection_stack,
|
||||
COGL_MATRIX_PROJECTION);
|
||||
|
||||
if (first)
|
||||
{
|
||||
GE( glEnable (GL_STENCIL_TEST) );
|
||||
|
||||
/* Initially disallow everything */
|
||||
GE( glClearStencil (0) );
|
||||
GE( glClear (GL_STENCIL_BUFFER_BIT) );
|
||||
|
||||
/* Punch out a hole to allow the rectangle */
|
||||
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
|
||||
GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );
|
||||
|
||||
_cogl_rectangle_immediate (x_1, y_1, x_2, y_2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add one to every pixel of the stencil buffer in the
|
||||
rectangle */
|
||||
GE( glStencilFunc (GL_NEVER, 0x1, 0x3) );
|
||||
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
|
||||
_cogl_rectangle_immediate (x_1, y_1, x_2, y_2);
|
||||
|
||||
/* Subtract one from all pixels in the stencil buffer so that
|
||||
only pixels where both the original stencil buffer and the
|
||||
rectangle are set will be valid */
|
||||
GE( glStencilOp (GL_DECR, GL_DECR, GL_DECR) );
|
||||
|
||||
_cogl_matrix_stack_push (projection_stack);
|
||||
_cogl_matrix_stack_load_identity (projection_stack);
|
||||
|
||||
_cogl_matrix_stack_push (modelview_stack);
|
||||
_cogl_matrix_stack_load_identity (modelview_stack);
|
||||
|
||||
_cogl_matrix_stack_flush_to_gl (modelview_stack,
|
||||
COGL_MATRIX_MODELVIEW);
|
||||
_cogl_matrix_stack_flush_to_gl (projection_stack,
|
||||
COGL_MATRIX_PROJECTION);
|
||||
|
||||
_cogl_rectangle_immediate (-1.0, -1.0, 1.0, 1.0);
|
||||
|
||||
_cogl_matrix_stack_pop (modelview_stack);
|
||||
_cogl_matrix_stack_pop (projection_stack);
|
||||
}
|
||||
|
||||
/* Restore the stencil mode */
|
||||
GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
|
||||
GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
|
||||
|
||||
/* restore the original source pipeline */
|
||||
cogl_pop_source ();
|
||||
}
|
||||
|
||||
static void
|
||||
disable_stencil_buffer (void)
|
||||
{
|
||||
GE( glDisable (GL_STENCIL_TEST) );
|
||||
}
|
||||
|
||||
static void
|
||||
enable_clip_planes (void)
|
||||
{
|
||||
GE( glEnable (GL_CLIP_PLANE0) );
|
||||
GE( glEnable (GL_CLIP_PLANE1) );
|
||||
GE( glEnable (GL_CLIP_PLANE2) );
|
||||
GE( glEnable (GL_CLIP_PLANE3) );
|
||||
}
|
||||
|
||||
static void
|
||||
disable_clip_planes (void)
|
||||
{
|
||||
GE( glDisable (GL_CLIP_PLANE3) );
|
||||
GE( glDisable (GL_CLIP_PLANE2) );
|
||||
GE( glDisable (GL_CLIP_PLANE1) );
|
||||
GE( glDisable (GL_CLIP_PLANE0) );
|
||||
}
|
||||
|
||||
static gpointer
|
||||
_cogl_clip_stack_push_entry (CoglClipStack *clip_stack,
|
||||
size_t size,
|
||||
CoglClipStackType type)
|
||||
{
|
||||
CoglClipStack *entry = g_slice_alloc (size);
|
||||
|
||||
/* The new entry starts with a ref count of 1 because the stack
|
||||
holds a reference to it as it is the top entry */
|
||||
entry->ref_count = 1;
|
||||
entry->type = type;
|
||||
entry->parent = clip_stack;
|
||||
|
||||
/* We don't need to take a reference to the parent from the entry
|
||||
because the we are stealing the ref in the new stack top */
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/* Sets the window-space bounds of the entry based on the projected
|
||||
coordinates of the given rectangle */
|
||||
static void
|
||||
_cogl_clip_stack_entry_set_bounds (CoglClipStack *entry,
|
||||
float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2,
|
||||
const CoglMatrix *modelview)
|
||||
{
|
||||
CoglMatrix projection;
|
||||
float viewport[4];
|
||||
float verts[4 * 2] = { x_1, y_1, x_2, y_1, x_2, y_2, x_1, y_2 };
|
||||
float min_x = G_MAXFLOAT, min_y = G_MAXFLOAT;
|
||||
float max_x = -G_MAXFLOAT, max_y = -G_MAXFLOAT;
|
||||
int i;
|
||||
|
||||
cogl_get_projection_matrix (&projection);
|
||||
cogl_get_viewport (viewport);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
float *v = verts + i * 2;
|
||||
|
||||
/* Project the coordinates to window space coordinates */
|
||||
_cogl_transform_point (modelview, &projection, viewport, v, v + 1);
|
||||
|
||||
if (v[0] > max_x)
|
||||
max_x = v[0];
|
||||
if (v[0] < min_x)
|
||||
min_x = v[0];
|
||||
if (v[1] > max_y)
|
||||
max_y = v[1];
|
||||
if (v[1] < min_y)
|
||||
min_y = v[1];
|
||||
}
|
||||
|
||||
entry->bounds_x0 = floorf (min_x);
|
||||
entry->bounds_x1 = ceilf (max_x);
|
||||
entry->bounds_y0 = floorf (min_y);
|
||||
entry->bounds_y1 = ceilf (max_y);
|
||||
}
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_stack_push_window_rectangle (CoglClipStack *stack,
|
||||
int x_offset,
|
||||
int y_offset,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
CoglClipStack *entry;
|
||||
|
||||
entry = _cogl_clip_stack_push_entry (stack,
|
||||
sizeof (CoglClipStackWindowRect),
|
||||
COGL_CLIP_STACK_WINDOW_RECT);
|
||||
|
||||
entry->bounds_x0 = x_offset;
|
||||
entry->bounds_x1 = x_offset + width;
|
||||
entry->bounds_y0 = y_offset;
|
||||
entry->bounds_y1 = y_offset + height;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_stack_push_rectangle (CoglClipStack *stack,
|
||||
float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2,
|
||||
const CoglMatrix *modelview_matrix)
|
||||
{
|
||||
CoglClipStackRect *entry;
|
||||
CoglMatrix matrix_p;
|
||||
float v[4];
|
||||
|
||||
/* Make a new entry */
|
||||
entry = _cogl_clip_stack_push_entry (stack,
|
||||
sizeof (CoglClipStackRect),
|
||||
COGL_CLIP_STACK_RECT);
|
||||
|
||||
entry->x0 = x_1;
|
||||
entry->y0 = y_1;
|
||||
entry->x1 = x_2;
|
||||
entry->y1 = y_2;
|
||||
|
||||
entry->matrix = *modelview_matrix;
|
||||
|
||||
/* If the modelview meets these constraints then a transformed rectangle
|
||||
* should still be a rectangle when it reaches screen coordinates.
|
||||
*
|
||||
* FIXME: we are are making certain assumptions about the projection
|
||||
* matrix a.t.m and should really be looking at the combined modelview
|
||||
* and projection matrix.
|
||||
* FIXME: we don't consider rotations that are a multiple of 90 degrees
|
||||
* which could be quite common.
|
||||
*/
|
||||
if (modelview_matrix->xy != 0 || modelview_matrix->xz != 0 ||
|
||||
modelview_matrix->yx != 0 || modelview_matrix->yz != 0 ||
|
||||
modelview_matrix->zx != 0 || modelview_matrix->zy != 0)
|
||||
{
|
||||
entry->can_be_scissor = FALSE;
|
||||
_cogl_clip_stack_entry_set_bounds ((CoglClipStack *) entry,
|
||||
x_1, y_1, x_2, y_2, modelview_matrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
CoglClipStack *base_entry = (CoglClipStack *) entry;
|
||||
|
||||
cogl_get_projection_matrix (&matrix_p);
|
||||
cogl_get_viewport (v);
|
||||
|
||||
_cogl_transform_point (modelview_matrix, &matrix_p, v, &x_1, &y_1);
|
||||
_cogl_transform_point (modelview_matrix, &matrix_p, v, &x_2, &y_2);
|
||||
|
||||
/* Consider that the modelview matrix may flip the rectangle
|
||||
* along the x or y axis... */
|
||||
#define SWAP(A,B) do { float tmp = B; B = A; A = tmp; } while (0)
|
||||
if (x_1 > x_2)
|
||||
SWAP (x_1, x_2);
|
||||
if (y_1 > y_2)
|
||||
SWAP (y_1, y_2);
|
||||
#undef SWAP
|
||||
|
||||
base_entry->bounds_x0 = COGL_UTIL_NEARBYINT (x_1);
|
||||
base_entry->bounds_y0 = COGL_UTIL_NEARBYINT (y_1);
|
||||
base_entry->bounds_x1 = COGL_UTIL_NEARBYINT (x_2);
|
||||
base_entry->bounds_y1 = COGL_UTIL_NEARBYINT (y_2);
|
||||
entry->can_be_scissor = TRUE;
|
||||
}
|
||||
|
||||
return (CoglClipStack *) entry;
|
||||
}
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_stack_push_from_path (CoglClipStack *stack,
|
||||
CoglPath *path,
|
||||
const CoglMatrix *modelview_matrix)
|
||||
{
|
||||
float x_1, y_1, x_2, y_2;
|
||||
|
||||
_cogl_path_get_bounds (path, &x_1, &y_1, &x_2, &y_2);
|
||||
|
||||
/* If the path is a simple rectangle then we can divert to pushing a
|
||||
rectangle clip instead which usually won't involve the stencil
|
||||
buffer */
|
||||
if (_cogl_path_is_rectangle (path))
|
||||
return _cogl_clip_stack_push_rectangle (stack,
|
||||
x_1, y_1,
|
||||
x_2, y_2,
|
||||
modelview_matrix);
|
||||
else
|
||||
{
|
||||
CoglClipStackPath *entry;
|
||||
|
||||
entry = _cogl_clip_stack_push_entry (stack,
|
||||
sizeof (CoglClipStackPath),
|
||||
COGL_CLIP_STACK_PATH);
|
||||
|
||||
entry->path = cogl_path_copy (path);
|
||||
|
||||
entry->matrix = *modelview_matrix;
|
||||
|
||||
_cogl_clip_stack_entry_set_bounds ((CoglClipStack *) entry,
|
||||
x_1, y_1, x_2, y_2, modelview_matrix);
|
||||
|
||||
return (CoglClipStack *) entry;
|
||||
}
|
||||
}
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_stack_ref (CoglClipStack *entry)
|
||||
{
|
||||
/* A NULL pointer is considered a valid stack so we should accept
|
||||
that as an argument */
|
||||
if (entry)
|
||||
entry->ref_count++;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_clip_stack_unref (CoglClipStack *entry)
|
||||
{
|
||||
/* Unref all of the entries until we hit the root of the list or the
|
||||
entry still has a remaining reference */
|
||||
while (entry && --entry->ref_count <= 0)
|
||||
{
|
||||
CoglClipStack *parent = entry->parent;
|
||||
|
||||
switch (entry->type)
|
||||
{
|
||||
case COGL_CLIP_STACK_RECT:
|
||||
g_slice_free1 (sizeof (CoglClipStackRect), entry);
|
||||
break;
|
||||
|
||||
case COGL_CLIP_STACK_WINDOW_RECT:
|
||||
g_slice_free1 (sizeof (CoglClipStackWindowRect), entry);
|
||||
break;
|
||||
|
||||
case COGL_CLIP_STACK_PATH:
|
||||
cogl_object_unref (((CoglClipStackPath *) entry)->path);
|
||||
g_slice_free1 (sizeof (CoglClipStackPath), entry);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
entry = parent;
|
||||
}
|
||||
}
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_stack_pop (CoglClipStack *stack)
|
||||
{
|
||||
CoglClipStack *new_top;
|
||||
|
||||
g_return_val_if_fail (stack != NULL, NULL);
|
||||
|
||||
/* To pop we are moving the top of the stack to the old top's parent
|
||||
node. The stack always needs to have a reference to the top entry
|
||||
so we must take a reference to the new top. The stack would have
|
||||
previously had a reference to the old top so we need to decrease
|
||||
the ref count on that. We need to ref the new head first in case
|
||||
this stack was the only thing referencing the old top. In that
|
||||
case the call to _cogl_clip_stack_entry_unref will unref the
|
||||
parent. */
|
||||
new_top = stack->parent;
|
||||
|
||||
_cogl_clip_stack_ref (new_top);
|
||||
|
||||
_cogl_clip_stack_unref (stack);
|
||||
|
||||
return new_top;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_clip_stack_get_bounds (CoglClipStack *stack,
|
||||
int *scissor_x0,
|
||||
int *scissor_y0,
|
||||
int *scissor_x1,
|
||||
int *scissor_y1)
|
||||
{
|
||||
CoglClipStack *entry;
|
||||
|
||||
*scissor_x0 = 0;
|
||||
*scissor_y0 = 0;
|
||||
*scissor_x1 = G_MAXINT;
|
||||
*scissor_y1 = G_MAXINT;
|
||||
|
||||
for (entry = stack; entry; entry = entry->parent)
|
||||
{
|
||||
/* Get the intersection of the current scissor and the bounding
|
||||
box of this clip */
|
||||
*scissor_x0 = MAX (*scissor_x0, entry->bounds_x0);
|
||||
*scissor_y0 = MAX (*scissor_y0, entry->bounds_y0);
|
||||
*scissor_x1 = MIN (*scissor_x1, entry->bounds_x1);
|
||||
*scissor_y1 = MIN (*scissor_y1, entry->bounds_y1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_clip_stack_flush (CoglClipStack *stack)
|
||||
{
|
||||
int has_clip_planes;
|
||||
gboolean using_clip_planes = FALSE;
|
||||
gboolean using_stencil_buffer = FALSE;
|
||||
int scissor_x0;
|
||||
int scissor_y0;
|
||||
int scissor_x1;
|
||||
int scissor_y1;
|
||||
CoglMatrixStack *modelview_stack;
|
||||
CoglClipStack *entry;
|
||||
int scissor_y_start;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
/* If we have already flushed this state then we don't need to do
|
||||
anything */
|
||||
if (ctx->current_clip_stack_valid)
|
||||
{
|
||||
if (ctx->current_clip_stack == stack)
|
||||
return;
|
||||
|
||||
_cogl_clip_stack_unref (ctx->current_clip_stack);
|
||||
}
|
||||
|
||||
ctx->current_clip_stack_valid = TRUE;
|
||||
ctx->current_clip_stack = _cogl_clip_stack_ref (stack);
|
||||
|
||||
modelview_stack =
|
||||
_cogl_framebuffer_get_modelview_stack (cogl_get_draw_framebuffer ());
|
||||
|
||||
has_clip_planes = cogl_features_available (COGL_FEATURE_FOUR_CLIP_PLANES);
|
||||
|
||||
if (has_clip_planes)
|
||||
disable_clip_planes ();
|
||||
disable_stencil_buffer ();
|
||||
|
||||
/* If the stack is empty then there's nothing else to do */
|
||||
if (stack == NULL)
|
||||
{
|
||||
COGL_NOTE (CLIPPING, "Flushed empty clip stack");
|
||||
|
||||
ctx->current_clip_stack_uses_stencil = FALSE;
|
||||
GE (glDisable (GL_SCISSOR_TEST));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Calculate the scissor rect first so that if we eventually have to
|
||||
clear the stencil buffer then the clear will be clipped to the
|
||||
intersection of all of the bounding boxes. This saves having to
|
||||
clear the whole stencil buffer */
|
||||
_cogl_clip_stack_get_bounds (stack,
|
||||
&scissor_x0, &scissor_y0,
|
||||
&scissor_x1, &scissor_y1);
|
||||
|
||||
/* Enable scissoring as soon as possible */
|
||||
if (scissor_x0 >= scissor_x1 || scissor_y0 >= scissor_y1)
|
||||
scissor_x0 = scissor_y0 = scissor_x1 = scissor_y1 = scissor_y_start = 0;
|
||||
else
|
||||
{
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
|
||||
/* We store the entry coordinates in Cogl coordinate space
|
||||
* but OpenGL requires the window origin to be the bottom
|
||||
* left so we may need to convert the incoming coordinates.
|
||||
*
|
||||
* NB: Cogl forces all offscreen rendering to be done upside
|
||||
* down so in this case no conversion is needed.
|
||||
*/
|
||||
|
||||
if (cogl_is_offscreen (framebuffer))
|
||||
scissor_y_start = scissor_y0;
|
||||
else
|
||||
{
|
||||
int framebuffer_height =
|
||||
cogl_framebuffer_get_height (framebuffer);
|
||||
|
||||
scissor_y_start = framebuffer_height - scissor_y1;
|
||||
}
|
||||
}
|
||||
|
||||
COGL_NOTE (CLIPPING, "Flushing scissor to (%i, %i, %i, %i)",
|
||||
scissor_x0, scissor_y0,
|
||||
scissor_x1, scissor_y1);
|
||||
|
||||
GE (glEnable (GL_SCISSOR_TEST));
|
||||
GE (glScissor (scissor_x0, scissor_y_start,
|
||||
scissor_x1 - scissor_x0,
|
||||
scissor_y1 - scissor_y0));
|
||||
|
||||
/* Add all of the entries. This will end up adding them in the
|
||||
reverse order that they were specified but as all of the clips
|
||||
are intersecting it should work out the same regardless of the
|
||||
order */
|
||||
for (entry = stack; entry; entry = entry->parent)
|
||||
{
|
||||
if (entry->type == COGL_CLIP_STACK_PATH)
|
||||
{
|
||||
CoglClipStackPath *path_entry = (CoglClipStackPath *) entry;
|
||||
|
||||
COGL_NOTE (CLIPPING, "Adding stencil clip for path");
|
||||
|
||||
_cogl_matrix_stack_push (modelview_stack);
|
||||
_cogl_matrix_stack_set (modelview_stack, &path_entry->matrix);
|
||||
|
||||
_cogl_add_path_to_stencil_buffer (path_entry->path,
|
||||
using_stencil_buffer,
|
||||
TRUE);
|
||||
|
||||
_cogl_matrix_stack_pop (modelview_stack);
|
||||
|
||||
using_stencil_buffer = TRUE;
|
||||
}
|
||||
else if (entry->type == COGL_CLIP_STACK_RECT)
|
||||
{
|
||||
CoglClipStackRect *rect = (CoglClipStackRect *) entry;
|
||||
|
||||
/* We don't need to do anything extra if the clip for this
|
||||
rectangle was entirely described by its scissor bounds */
|
||||
if (!rect->can_be_scissor)
|
||||
{
|
||||
_cogl_matrix_stack_push (modelview_stack);
|
||||
_cogl_matrix_stack_set (modelview_stack, &rect->matrix);
|
||||
|
||||
/* If we support clip planes and we haven't already used
|
||||
them then use that instead */
|
||||
if (has_clip_planes)
|
||||
{
|
||||
COGL_NOTE (CLIPPING, "Adding clip planes clip for rectangle");
|
||||
|
||||
set_clip_planes (rect->x0,
|
||||
rect->y0,
|
||||
rect->x1,
|
||||
rect->y1);
|
||||
using_clip_planes = TRUE;
|
||||
/* We can't use clip planes a second time */
|
||||
has_clip_planes = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
COGL_NOTE (CLIPPING, "Adding stencil clip for rectangle");
|
||||
|
||||
add_stencil_clip_rectangle (rect->x0,
|
||||
rect->y0,
|
||||
rect->x1,
|
||||
rect->y1,
|
||||
!using_stencil_buffer);
|
||||
using_stencil_buffer = TRUE;
|
||||
}
|
||||
|
||||
_cogl_matrix_stack_pop (modelview_stack);
|
||||
}
|
||||
}
|
||||
/* We don't need to do anything for window space rectangles
|
||||
because their functionality is entirely implemented by the
|
||||
entry bounding box */
|
||||
}
|
||||
|
||||
/* Enabling clip planes is delayed to now so that they won't affect
|
||||
setting up the stencil buffer */
|
||||
if (using_clip_planes)
|
||||
enable_clip_planes ();
|
||||
|
||||
ctx->current_clip_stack_uses_stencil = using_stencil_buffer;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_clip_stack_dirty (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
if (ctx->current_clip_stack_valid)
|
||||
{
|
||||
ctx->current_clip_stack_valid = FALSE;
|
||||
_cogl_clip_stack_unref (ctx->current_clip_stack);
|
||||
}
|
||||
}
|
@ -1,192 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_CLIP_STACK_H
|
||||
#define __COGL_CLIP_STACK_H
|
||||
|
||||
#include "cogl2-path.h"
|
||||
#include "cogl-matrix.h"
|
||||
|
||||
/* The clip stack works like a GSList where only a pointer to the top
|
||||
of the stack is stored. The empty clip stack is represented simply
|
||||
by the NULL pointer. When an entry is added to or removed from the
|
||||
stack the new top of the stack is returned. When an entry is pushed
|
||||
a new clip stack entry is created which effectively takes ownership
|
||||
of the reference on the old entry. Therefore unrefing the top entry
|
||||
effectively loses ownership of all entries in the stack */
|
||||
|
||||
typedef struct _CoglClipStack CoglClipStack;
|
||||
typedef struct _CoglClipStackRect CoglClipStackRect;
|
||||
typedef struct _CoglClipStackWindowRect CoglClipStackWindowRect;
|
||||
typedef struct _CoglClipStackPath CoglClipStackPath;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COGL_CLIP_STACK_RECT,
|
||||
COGL_CLIP_STACK_WINDOW_RECT,
|
||||
COGL_CLIP_STACK_PATH
|
||||
} CoglClipStackType;
|
||||
|
||||
/* A clip stack consists a list of entries. Each entry has a reference
|
||||
* count and a link to its parent node. The child takes a reference on
|
||||
* the parent and the CoglClipStack holds a reference to the top of
|
||||
* the stack. There are no links back from the parent to the
|
||||
* children. This allows stacks that have common ancestry to share the
|
||||
* entries.
|
||||
*
|
||||
* For example, the following sequence of operations would generate
|
||||
* the tree below:
|
||||
*
|
||||
* CoglClipStack *stack_a = NULL;
|
||||
* stack_a = _cogl_clip_stack_push_rectangle (stack_a, ...);
|
||||
* stack_a = _cogl_clip_stack_push_rectangle (stack_a, ...);
|
||||
* stack_a = _cogl_clip_stack_push_from_path (stack_a, ...);
|
||||
* CoglClipStack *stack_b = NULL;
|
||||
* stack_b = cogl_clip_stack_push_window_rectangle (stack_b, ...);
|
||||
*
|
||||
* stack_a
|
||||
* \ holds a ref to
|
||||
* +-----------+
|
||||
* | path node |
|
||||
* |ref count 1|
|
||||
* +-----------+
|
||||
* \
|
||||
* +-----------+ +-----------+
|
||||
* both tops hold | rect node | | rect node |
|
||||
* a ref to the |ref count 2|--|ref count 1|
|
||||
* same rect node +-----------+ +-----------+
|
||||
* /
|
||||
* +-----------+
|
||||
* | win. rect |
|
||||
* |ref count 1|
|
||||
* +-----------+
|
||||
* / holds a ref to
|
||||
* stack_b
|
||||
*
|
||||
*/
|
||||
|
||||
struct _CoglClipStack
|
||||
{
|
||||
CoglClipStackType type;
|
||||
|
||||
/* This will be null if there is no parent. If it is not null then
|
||||
this node must be holding a reference to the parent */
|
||||
CoglClipStack *parent;
|
||||
|
||||
/* All clip entries have a window-space bounding box which we can
|
||||
use to calculate a scissor. The scissor limits the clip so that
|
||||
we don't need to do a full stencil clear if the stencil buffer is
|
||||
needed. This is stored in Cogl's coordinate space (ie, 0,0 is the
|
||||
top left) */
|
||||
int bounds_x0;
|
||||
int bounds_y0;
|
||||
int bounds_x1;
|
||||
int bounds_y1;
|
||||
|
||||
unsigned int ref_count;
|
||||
};
|
||||
|
||||
struct _CoglClipStackRect
|
||||
{
|
||||
CoglClipStack _parent_data;
|
||||
|
||||
/* The rectangle for this clip */
|
||||
float x0;
|
||||
float y0;
|
||||
float x1;
|
||||
float y1;
|
||||
|
||||
/* If this is true then the clip for this rectangle is entirely
|
||||
described by the scissor bounds. This implies that the rectangle
|
||||
is screen aligned and we don't need to use the stencil buffer to
|
||||
set the clip. We keep the entry as a rect entry rather than a
|
||||
window rect entry so that it will be easier to detect if the
|
||||
modelview matrix is that same as when a rectangle is added to the
|
||||
journal. In that case we can use the original clip coordinates
|
||||
and modify the rectangle instead. */
|
||||
gboolean can_be_scissor;
|
||||
|
||||
/* The matrix that was current when the clip was set */
|
||||
CoglMatrix matrix;
|
||||
};
|
||||
|
||||
struct _CoglClipStackWindowRect
|
||||
{
|
||||
CoglClipStack _parent_data;
|
||||
|
||||
/* The window rect clip doesn't need any specific data because it
|
||||
just adds to the scissor clip */
|
||||
};
|
||||
|
||||
struct _CoglClipStackPath
|
||||
{
|
||||
CoglClipStack _parent_data;
|
||||
|
||||
/* The matrix that was current when the clip was set */
|
||||
CoglMatrix matrix;
|
||||
|
||||
CoglPath *path;
|
||||
};
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_stack_push_window_rectangle (CoglClipStack *stack,
|
||||
int x_offset,
|
||||
int y_offset,
|
||||
int width,
|
||||
int height);
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_stack_push_rectangle (CoglClipStack *stack,
|
||||
float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2,
|
||||
const CoglMatrix *modelview_matrix);
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_stack_push_from_path (CoglClipStack *stack,
|
||||
CoglPath *path,
|
||||
const CoglMatrix *modelview_matrix);
|
||||
CoglClipStack *
|
||||
_cogl_clip_stack_pop (CoglClipStack *stack);
|
||||
|
||||
void
|
||||
_cogl_clip_stack_get_bounds (CoglClipStack *stack,
|
||||
int *scissor_x0,
|
||||
int *scissor_y0,
|
||||
int *scissor_x1,
|
||||
int *scissor_y1);
|
||||
|
||||
void
|
||||
_cogl_clip_stack_flush (CoglClipStack *stack);
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_stack_ref (CoglClipStack *stack);
|
||||
|
||||
void
|
||||
_cogl_clip_stack_unref (CoglClipStack *stack);
|
||||
|
||||
void
|
||||
_cogl_clip_stack_dirty (void);
|
||||
|
||||
#endif /* __COGL_CLIP_STACK_H */
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_CLIP_STATE_PRIVATE_H
|
||||
#define __COGL_CLIP_STATE_PRIVATE_H
|
||||
|
||||
#include "cogl-clip-stack.h"
|
||||
|
||||
typedef struct _CoglClipState CoglClipState;
|
||||
|
||||
struct _CoglClipState
|
||||
{
|
||||
/* Stack of CoglClipStacks */
|
||||
GSList *stacks;
|
||||
};
|
||||
|
||||
void
|
||||
_cogl_clip_state_init (CoglClipState *state);
|
||||
|
||||
void
|
||||
_cogl_clip_state_destroy (CoglClipState *state);
|
||||
|
||||
void
|
||||
_cogl_clip_state_flush (CoglClipState *clip_state);
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_state_get_stack (CoglClipState *clip_state);
|
||||
|
||||
void
|
||||
_cogl_clip_state_set_stack (CoglClipState *clip_state,
|
||||
CoglClipStack *clip_stack);
|
||||
|
||||
#endif /* __COGL_CLIP_STATE_PRIVATE_H */
|
@ -1,255 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-clip-stack.h"
|
||||
#include "cogl-clip-state-private.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-framebuffer-private.h"
|
||||
#include "cogl-journal-private.h"
|
||||
#include "cogl-util.h"
|
||||
#include "cogl-matrix-private.h"
|
||||
|
||||
void
|
||||
cogl_clip_push_window_rectangle (int x_offset,
|
||||
int y_offset,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
CoglFramebuffer *framebuffer;
|
||||
CoglClipState *clip_state;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
framebuffer = cogl_get_draw_framebuffer ();
|
||||
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
||||
|
||||
clip_state->stacks->data =
|
||||
_cogl_clip_stack_push_window_rectangle (clip_state->stacks->data,
|
||||
x_offset, y_offset,
|
||||
width, height);
|
||||
}
|
||||
|
||||
/* XXX: This is deprecated API */
|
||||
void
|
||||
cogl_clip_push_window_rect (float x_offset,
|
||||
float y_offset,
|
||||
float width,
|
||||
float height)
|
||||
{
|
||||
cogl_clip_push_window_rectangle (x_offset, y_offset, width, height);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_clip_push_rectangle (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2)
|
||||
{
|
||||
CoglFramebuffer *framebuffer;
|
||||
CoglClipState *clip_state;
|
||||
CoglMatrix modelview_matrix;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
framebuffer = cogl_get_draw_framebuffer ();
|
||||
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
||||
|
||||
cogl_get_modelview_matrix (&modelview_matrix);
|
||||
|
||||
clip_state->stacks->data =
|
||||
_cogl_clip_stack_push_rectangle (clip_state->stacks->data,
|
||||
x_1, y_1, x_2, y_2,
|
||||
&modelview_matrix);
|
||||
}
|
||||
|
||||
/* XXX: Deprecated API */
|
||||
void
|
||||
cogl_clip_push (float x_offset,
|
||||
float y_offset,
|
||||
float width,
|
||||
float height)
|
||||
{
|
||||
cogl_clip_push_rectangle (x_offset,
|
||||
y_offset,
|
||||
x_offset + width,
|
||||
y_offset + height);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_clip_push_from_path_preserve (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
cogl2_clip_push_from_path (ctx->current_path);
|
||||
}
|
||||
|
||||
#undef cogl_clip_push_from_path
|
||||
void
|
||||
cogl_clip_push_from_path (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_clip_push_from_path (ctx->current_path);
|
||||
|
||||
cogl_object_unref (ctx->current_path);
|
||||
ctx->current_path = cogl2_path_new ();
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_clip_pop_real (CoglClipState *clip_state)
|
||||
{
|
||||
clip_state->stacks->data = _cogl_clip_stack_pop (clip_state->stacks->data);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_clip_pop (void)
|
||||
{
|
||||
CoglFramebuffer *framebuffer;
|
||||
CoglClipState *clip_state;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
framebuffer = cogl_get_draw_framebuffer ();
|
||||
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
||||
|
||||
_cogl_clip_pop_real (clip_state);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_clip_state_flush (CoglClipState *clip_state)
|
||||
{
|
||||
/* Flush the topmost stack. The clip stack code will bail out early
|
||||
if this is already flushed */
|
||||
_cogl_clip_stack_flush (clip_state->stacks->data);
|
||||
}
|
||||
|
||||
/* XXX: This should never have been made public API! */
|
||||
void
|
||||
cogl_clip_ensure (void)
|
||||
{
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglClipState *clip_state;
|
||||
|
||||
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
||||
/* Flushing the clip state doesn't cause the journal to be
|
||||
flushed. This function may be being called by an external
|
||||
application however so it makes sense to flush the journal
|
||||
here */
|
||||
_cogl_framebuffer_flush_journal (framebuffer);
|
||||
_cogl_clip_state_flush (clip_state);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_clip_stack_save_real (CoglClipState *clip_state)
|
||||
{
|
||||
clip_state->stacks = g_slist_prepend (clip_state->stacks, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_clip_stack_save (void)
|
||||
{
|
||||
CoglFramebuffer *framebuffer;
|
||||
CoglClipState *clip_state;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
framebuffer = cogl_get_draw_framebuffer ();
|
||||
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
||||
|
||||
_cogl_clip_stack_save_real (clip_state);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_clip_stack_restore_real (CoglClipState *clip_state)
|
||||
{
|
||||
CoglHandle stack;
|
||||
|
||||
g_return_if_fail (clip_state->stacks != NULL);
|
||||
|
||||
stack = clip_state->stacks->data;
|
||||
|
||||
_cogl_clip_stack_unref (stack);
|
||||
|
||||
/* Revert to an old stack */
|
||||
clip_state->stacks = g_slist_delete_link (clip_state->stacks,
|
||||
clip_state->stacks);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_clip_stack_restore (void)
|
||||
{
|
||||
CoglFramebuffer *framebuffer;
|
||||
CoglClipState *clip_state;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
framebuffer = cogl_get_draw_framebuffer ();
|
||||
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
||||
|
||||
_cogl_clip_stack_restore_real (clip_state);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_clip_state_init (CoglClipState *clip_state)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
clip_state->stacks = NULL;
|
||||
|
||||
/* Add an intial stack */
|
||||
_cogl_clip_stack_save_real (clip_state);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_clip_state_destroy (CoglClipState *clip_state)
|
||||
{
|
||||
/* Destroy all of the stacks */
|
||||
while (clip_state->stacks)
|
||||
_cogl_clip_stack_restore_real (clip_state);
|
||||
}
|
||||
|
||||
CoglClipStack *
|
||||
_cogl_clip_state_get_stack (CoglClipState *clip_state)
|
||||
{
|
||||
return clip_state->stacks->data;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_clip_state_set_stack (CoglClipState *clip_state,
|
||||
CoglClipStack *stack)
|
||||
{
|
||||
/* Replace the top of the stack of stacks */
|
||||
_cogl_clip_stack_ref (stack);
|
||||
_cogl_clip_stack_unref (clip_state->stacks->data);
|
||||
clip_state->stacks->data = stack;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_CLIP_STATE_H
|
||||
#define __COGL_CLIP_STATE_H
|
||||
|
||||
#include <cogl/cogl-types.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* cogl_clip_push_from_path:
|
||||
*
|
||||
* Sets a new clipping area using the current path. The current path
|
||||
* is then cleared. The clipping area is intersected with the previous
|
||||
* clipping area. To restore the previous clipping area, call
|
||||
* cogl_clip_pop().
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
void
|
||||
cogl_clip_push_from_path (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_CLIP_STATE_H */
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-types.h"
|
||||
#include "cogl-private.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-winsys-private.h"
|
||||
#include "cogl-framebuffer-private.h"
|
||||
|
||||
gboolean
|
||||
cogl_clutter_check_extension (const char *name, const char *ext)
|
||||
{
|
||||
return _cogl_check_extension (name, ext);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_clutter_winsys_has_feature (CoglWinsysFeature feature)
|
||||
{
|
||||
return _cogl_winsys_has_feature (feature);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_onscreen_clutter_backend_set_size (int width, int height)
|
||||
{
|
||||
CoglFramebuffer *framebuffer;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
if (!ctx->stub_winsys)
|
||||
return;
|
||||
|
||||
framebuffer = COGL_FRAMEBUFFER (ctx->window_buffer);
|
||||
|
||||
_cogl_framebuffer_winsys_update_size (framebuffer, width, height);
|
||||
}
|
||||
|
||||
#ifdef COGL_HAS_XLIB_SUPPORT
|
||||
XVisualInfo *
|
||||
cogl_clutter_winsys_xlib_get_visual_info (void)
|
||||
{
|
||||
const CoglWinsysVtable *winsys;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
|
||||
winsys = _cogl_context_get_winsys (ctx);
|
||||
|
||||
return winsys->xlib_get_visual_info ();
|
||||
}
|
||||
#endif
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_CLUTTER_H__
|
||||
#define __COGL_CLUTTER_H__
|
||||
|
||||
#ifdef COGL_HAS_XLIB
|
||||
#include <X11/Xutil.h>
|
||||
#endif
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define cogl_clutter_check_extension cogl_clutter_check_extension_CLUTTER
|
||||
gboolean
|
||||
cogl_clutter_check_extension (const char *name, const char *ext);
|
||||
|
||||
#define cogl_clutter_winsys_has_feature cogl_clutter_winsys_has_feature_CLUTTER
|
||||
gboolean
|
||||
cogl_clutter_winsys_has_feature (CoglWinsysFeature feature);
|
||||
|
||||
#define cogl_onscreen_clutter_backend_set_size cogl_onscreen_clutter_backend_set_size_CLUTTER
|
||||
void
|
||||
cogl_onscreen_clutter_backend_set_size (int width, int height);
|
||||
|
||||
#ifdef COGL_HAS_XLIB
|
||||
#define cogl_clutter_winsys_xlib_get_visual_info cogl_clutter_winsys_xlib_get_visual_info_CLUTTER
|
||||
XVisualInfo *
|
||||
cogl_clutter_winsys_xlib_get_visual_info (void);
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_CLUTTER_H__ */
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_COLOR_PRIVATE_PRIVATE_H
|
||||
#define __COGL_COLOR_PRIVATE_PRIVATE_H
|
||||
|
||||
#include "cogl-color.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/* cogl-pipeline.c wants to be able to hash CoglColor data so it needs
|
||||
* the exact data size to be able to avoid reading the padding bytes.
|
||||
*/
|
||||
#define _COGL_COLOR_DATA_SIZE 4
|
||||
|
||||
void
|
||||
_cogl_color_get_rgba_4ubv (const CoglColor *color,
|
||||
guint8 *dest);
|
||||
|
||||
#endif /* __COGL_COLOR_PRIVATE_PRIVATE_H */
|
||||
|
@ -1,313 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-color.h"
|
||||
#include "cogl-fixed.h"
|
||||
|
||||
CoglColor *
|
||||
cogl_color_new (void)
|
||||
{
|
||||
return g_slice_new (CoglColor);
|
||||
}
|
||||
|
||||
CoglColor *
|
||||
cogl_color_copy (const CoglColor *color)
|
||||
{
|
||||
if (G_LIKELY (color))
|
||||
return g_slice_dup (CoglColor, color);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_free (CoglColor *color)
|
||||
{
|
||||
if (G_LIKELY (color))
|
||||
g_slice_free (CoglColor, color);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_init_from_4ub (CoglColor *color,
|
||||
guint8 red,
|
||||
guint8 green,
|
||||
guint8 blue,
|
||||
guint8 alpha)
|
||||
{
|
||||
g_return_if_fail (color != NULL);
|
||||
|
||||
color->red = red;
|
||||
color->green = green;
|
||||
color->blue = blue;
|
||||
color->alpha = alpha;
|
||||
}
|
||||
|
||||
/* XXX: deprecated, use cogl_color_init_from_4ub */
|
||||
void
|
||||
cogl_color_set_from_4ub (CoglColor *dest,
|
||||
guint8 red,
|
||||
guint8 green,
|
||||
guint8 blue,
|
||||
guint8 alpha)
|
||||
{
|
||||
cogl_color_init_from_4ub (dest, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_init_from_4f (CoglColor *color,
|
||||
float red,
|
||||
float green,
|
||||
float blue,
|
||||
float alpha)
|
||||
{
|
||||
g_return_if_fail (color != NULL);
|
||||
|
||||
color->red = (red * 255);
|
||||
color->green = (green * 255);
|
||||
color->blue = (blue * 255);
|
||||
color->alpha = (alpha * 255);
|
||||
}
|
||||
|
||||
/* XXX: deprecated, use cogl_color_init_from_4f */
|
||||
void
|
||||
cogl_color_set_from_4f (CoglColor *color,
|
||||
float red,
|
||||
float green,
|
||||
float blue,
|
||||
float alpha)
|
||||
{
|
||||
cogl_color_init_from_4f (color, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_init_from_4fv (CoglColor *color,
|
||||
float *color_array)
|
||||
{
|
||||
g_return_if_fail (color != NULL);
|
||||
|
||||
color->red = (color_array[0] * 255);
|
||||
color->green = (color_array[1] * 255);
|
||||
color->blue = (color_array[2] * 255);
|
||||
color->alpha = (color_array[3] * 255);
|
||||
}
|
||||
|
||||
unsigned char
|
||||
cogl_color_get_red_byte (const CoglColor *color)
|
||||
{
|
||||
return color->red;
|
||||
}
|
||||
|
||||
float
|
||||
cogl_color_get_red_float (const CoglColor *color)
|
||||
{
|
||||
return (float) color->red / 255.0;
|
||||
}
|
||||
|
||||
float
|
||||
cogl_color_get_red (const CoglColor *color)
|
||||
{
|
||||
return ((float) color->red / 255.0);
|
||||
}
|
||||
|
||||
unsigned char
|
||||
cogl_color_get_green_byte (const CoglColor *color)
|
||||
{
|
||||
return color->green;
|
||||
}
|
||||
|
||||
float
|
||||
cogl_color_get_green_float (const CoglColor *color)
|
||||
{
|
||||
return (float) color->green / 255.0;
|
||||
}
|
||||
|
||||
float
|
||||
cogl_color_get_green (const CoglColor *color)
|
||||
{
|
||||
return ((float) color->green / 255.0);
|
||||
}
|
||||
|
||||
unsigned char
|
||||
cogl_color_get_blue_byte (const CoglColor *color)
|
||||
{
|
||||
return color->blue;
|
||||
}
|
||||
|
||||
float
|
||||
cogl_color_get_blue_float (const CoglColor *color)
|
||||
{
|
||||
return (float) color->blue / 255.0;
|
||||
}
|
||||
|
||||
float
|
||||
cogl_color_get_blue (const CoglColor *color)
|
||||
{
|
||||
return ((float) color->blue / 255.0);
|
||||
}
|
||||
|
||||
unsigned char
|
||||
cogl_color_get_alpha_byte (const CoglColor *color)
|
||||
{
|
||||
return color->alpha;
|
||||
}
|
||||
|
||||
float
|
||||
cogl_color_get_alpha_float (const CoglColor *color)
|
||||
{
|
||||
return (float) color->alpha / 255.0;
|
||||
}
|
||||
|
||||
float
|
||||
cogl_color_get_alpha (const CoglColor *color)
|
||||
{
|
||||
return ((float) color->alpha / 255.0);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_red_byte (CoglColor *color,
|
||||
unsigned char red)
|
||||
{
|
||||
color->red = red;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_red_float (CoglColor *color,
|
||||
float red)
|
||||
{
|
||||
color->red = red * 255.0;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_red (CoglColor *color,
|
||||
float red)
|
||||
{
|
||||
color->red = red * 255.0;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_green_byte (CoglColor *color,
|
||||
unsigned char green)
|
||||
{
|
||||
color->green = green;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_green_float (CoglColor *color,
|
||||
float green)
|
||||
{
|
||||
color->green = green * 255.0;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_green (CoglColor *color,
|
||||
float green)
|
||||
{
|
||||
color->green = green * 255.0;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_blue_byte (CoglColor *color,
|
||||
unsigned char blue)
|
||||
{
|
||||
color->blue = blue;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_blue_float (CoglColor *color,
|
||||
float blue)
|
||||
{
|
||||
color->blue = blue * 255.0;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_blue (CoglColor *color,
|
||||
float blue)
|
||||
{
|
||||
color->blue = blue * 255.0;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_alpha_byte (CoglColor *color,
|
||||
unsigned char alpha)
|
||||
{
|
||||
color->alpha = alpha;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_alpha_float (CoglColor *color,
|
||||
float alpha)
|
||||
{
|
||||
color->alpha = alpha * 255.0;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_set_alpha (CoglColor *color,
|
||||
float alpha)
|
||||
{
|
||||
color->alpha = alpha * 255.0;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_premultiply (CoglColor *color)
|
||||
{
|
||||
color->red = (color->red * color->alpha + 128) / 255;
|
||||
color->green = (color->green * color->alpha + 128) / 255;
|
||||
color->blue = (color->blue * color->alpha + 128) / 255;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_color_unpremultiply (CoglColor *color)
|
||||
{
|
||||
if (color->alpha != 0)
|
||||
{
|
||||
color->red = (color->red * 255) / color->alpha;
|
||||
color->green = (color->green * 255) / color->alpha;
|
||||
color->blue = (color->blue * 255) / color->alpha;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_color_equal (gconstpointer v1, gconstpointer v2)
|
||||
{
|
||||
const guint32 *c1 = v1, *c2 = v2;
|
||||
|
||||
g_return_val_if_fail (v1 != NULL, FALSE);
|
||||
g_return_val_if_fail (v2 != NULL, FALSE);
|
||||
|
||||
/* XXX: We don't compare the padding */
|
||||
return *c1 == *c2 ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_color_get_rgba_4ubv (const CoglColor *color,
|
||||
guint8 *dest)
|
||||
{
|
||||
memcpy (dest, color, 4);
|
||||
}
|
||||
|
@ -1,544 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:cogl-color
|
||||
* @short_description: A generic color definition
|
||||
*
|
||||
* #CoglColor is a simple structure holding the definition of a color such
|
||||
* that it can be efficiently used by GL
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_COLOR_H__
|
||||
#define __COGL_COLOR_H__
|
||||
|
||||
#include <cogl/cogl-types.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* cogl_color_new:
|
||||
*
|
||||
* Creates a new (empty) color
|
||||
*
|
||||
* Return value: a newly-allocated #CoglColor. Use cogl_color_free()
|
||||
* to free the allocated resources
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglColor *
|
||||
cogl_color_new (void);
|
||||
|
||||
/**
|
||||
* cogl_color_copy:
|
||||
* @color: the color to copy
|
||||
*
|
||||
* Creates a copy of @color
|
||||
*
|
||||
* Return value: a newly-allocated #CoglColor. Use cogl_color_free()
|
||||
* to free the allocate resources
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglColor *
|
||||
cogl_color_copy (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_free:
|
||||
* @color: the color to free
|
||||
*
|
||||
* Frees the resources allocated by cogl_color_new() and cogl_color_copy()
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
void
|
||||
cogl_color_free (CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_init_from_4ub:
|
||||
* @color: A pointer to a #CoglColor to initialize
|
||||
* @red: value of the red channel, between 0 and 255
|
||||
* @green: value of the green channel, between 0 and 255
|
||||
* @blue: value of the blue channel, between 0 and 255
|
||||
* @alpha: value of the alpha channel, between 0 and 255
|
||||
*
|
||||
* Sets the values of the passed channels into a #CoglColor.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_init_from_4ub (CoglColor *color,
|
||||
guint8 red,
|
||||
guint8 green,
|
||||
guint8 blue,
|
||||
guint8 alpha);
|
||||
|
||||
/**
|
||||
* cogl_color_set_from_4ub:
|
||||
* @color: A pointer to a #CoglColor to initialize
|
||||
* @red: value of the red channel, between 0 and 255
|
||||
* @green: value of the green channel, between 0 and 255
|
||||
* @blue: value of the blue channel, between 0 and 255
|
||||
* @alpha: value of the alpha channel, between 0 and 255
|
||||
*
|
||||
* Sets the values of the passed channels into a #CoglColor.
|
||||
*
|
||||
* Since: 1.0
|
||||
* Deprecated: 1.4: Use cogl_color_init_from_4ub instead.
|
||||
*/
|
||||
void
|
||||
cogl_color_set_from_4ub (CoglColor *color,
|
||||
guint8 red,
|
||||
guint8 green,
|
||||
guint8 blue,
|
||||
guint8 alpha);
|
||||
|
||||
/**
|
||||
* cogl_color_init_from_4f:
|
||||
* @color: A pointer to a #CoglColor to initialize
|
||||
* @red: value of the red channel, between 0 and %1.0
|
||||
* @green: value of the green channel, between 0 and %1.0
|
||||
* @blue: value of the blue channel, between 0 and %1.0
|
||||
* @alpha: value of the alpha channel, between 0 and %1.0
|
||||
*
|
||||
* Sets the values of the passed channels into a #CoglColor
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_init_from_4f (CoglColor *color,
|
||||
float red,
|
||||
float green,
|
||||
float blue,
|
||||
float alpha);
|
||||
|
||||
/**
|
||||
* cogl_color_set_from_4f:
|
||||
* @color: A pointer to a #CoglColor to initialize
|
||||
* @red: value of the red channel, between 0 and %1.0
|
||||
* @green: value of the green channel, between 0 and %1.0
|
||||
* @blue: value of the blue channel, between 0 and %1.0
|
||||
* @alpha: value of the alpha channel, between 0 and %1.0
|
||||
*
|
||||
* Sets the values of the passed channels into a #CoglColor
|
||||
*
|
||||
* Since: 1.0
|
||||
* Deprecated: 1.4: Use cogl_color_init_from_4f instead.
|
||||
*/
|
||||
void
|
||||
cogl_color_set_from_4f (CoglColor *color,
|
||||
float red,
|
||||
float green,
|
||||
float blue,
|
||||
float alpha);
|
||||
|
||||
/**
|
||||
* cogl_color_init_from_4fv:
|
||||
* @color: A pointer to a #CoglColor to initialize
|
||||
* @color_array: a pointer to an array of 4 float color components
|
||||
*
|
||||
* Sets the values of the passed channels into a #CoglColor
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_init_from_4fv (CoglColor *color,
|
||||
float *color_array);
|
||||
|
||||
/**
|
||||
* cogl_color_get_red_byte:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the red channel of @color as a byte value
|
||||
* between 0 and 255
|
||||
*
|
||||
* Return value: the red channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
unsigned char
|
||||
cogl_color_get_red_byte (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_green_byte:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the green channel of @color as a byte value
|
||||
* between 0 and 255
|
||||
*
|
||||
* Return value: the green channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
unsigned char
|
||||
cogl_color_get_green_byte (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_blue_byte:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the blue channel of @color as a byte value
|
||||
* between 0 and 255
|
||||
*
|
||||
* Return value: the blue channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
unsigned char
|
||||
cogl_color_get_blue_byte (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_alpha_byte:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the alpha channel of @color as a byte value
|
||||
* between 0 and 255
|
||||
*
|
||||
* Return value: the alpha channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
unsigned char
|
||||
cogl_color_get_alpha_byte (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_red_float:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the red channel of @color as a floating point
|
||||
* value between 0.0 and 1.0
|
||||
*
|
||||
* Return value: the red channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
float
|
||||
cogl_color_get_red_float (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_green_float:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the green channel of @color as a floating point
|
||||
* value between 0.0 and 1.0
|
||||
*
|
||||
* Return value: the green channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
float
|
||||
cogl_color_get_green_float (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_blue_float:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the blue channel of @color as a floating point
|
||||
* value between 0.0 and 1.0
|
||||
*
|
||||
* Return value: the blue channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
float
|
||||
cogl_color_get_blue_float (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_alpha_float:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the alpha channel of @color as a floating point
|
||||
* value between 0.0 and 1.0
|
||||
*
|
||||
* Return value: the alpha channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
float
|
||||
cogl_color_get_alpha_float (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_red:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the red channel of @color as a fixed point
|
||||
* value between 0 and %1.0.
|
||||
*
|
||||
* Return value: the red channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
float
|
||||
cogl_color_get_red (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_green:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the green channel of @color as a fixed point
|
||||
* value between 0 and %1.0.
|
||||
*
|
||||
* Return value: the green channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
float
|
||||
cogl_color_get_green (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_blue:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the blue channel of @color as a fixed point
|
||||
* value between 0 and %1.0.
|
||||
*
|
||||
* Return value: the blue channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
float
|
||||
cogl_color_get_blue (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_get_alpha:
|
||||
* @color: a #CoglColor
|
||||
*
|
||||
* Retrieves the alpha channel of @color as a fixed point
|
||||
* value between 0 and %1.0.
|
||||
*
|
||||
* Return value: the alpha channel of the passed color
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
float
|
||||
cogl_color_get_alpha (const CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_set_red_byte:
|
||||
* @color: a #CoglColor
|
||||
* @red: a byte value between 0 and 255
|
||||
*
|
||||
* Sets the red channel of @color to @red.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_red_byte (CoglColor *color,
|
||||
unsigned char red);
|
||||
|
||||
/**
|
||||
* cogl_color_set_green_byte:
|
||||
* @color: a #CoglColor
|
||||
* @green: a byte value between 0 and 255
|
||||
*
|
||||
* Sets the green channel of @color to @green.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_green_byte (CoglColor *color,
|
||||
unsigned char green);
|
||||
|
||||
/**
|
||||
* cogl_color_set_blue_byte:
|
||||
* @color: a #CoglColor
|
||||
* @blue: a byte value between 0 and 255
|
||||
*
|
||||
* Sets the blue channel of @color to @blue.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_blue_byte (CoglColor *color,
|
||||
unsigned char blue);
|
||||
|
||||
/**
|
||||
* cogl_color_set_alpha_byte:
|
||||
* @color: a #CoglColor
|
||||
* @alpha: a byte value between 0 and 255
|
||||
*
|
||||
* Sets the alpha channel of @color to @alpha.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_alpha_byte (CoglColor *color,
|
||||
unsigned char alpha);
|
||||
|
||||
/**
|
||||
* cogl_color_set_red_float:
|
||||
* @color: a #CoglColor
|
||||
* @red: a float value between 0.0f and 1.0f
|
||||
*
|
||||
* Sets the red channel of @color to @red.
|
||||
*
|
||||
* since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_red_float (CoglColor *color,
|
||||
float red);
|
||||
|
||||
/**
|
||||
* cogl_color_set_green_float:
|
||||
* @color: a #CoglColor
|
||||
* @green: a float value between 0.0f and 1.0f
|
||||
*
|
||||
* Sets the green channel of @color to @green.
|
||||
*
|
||||
* since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_green_float (CoglColor *color,
|
||||
float green);
|
||||
|
||||
/**
|
||||
* cogl_color_set_blue_float:
|
||||
* @color: a #CoglColor
|
||||
* @blue: a float value between 0.0f and 1.0f
|
||||
*
|
||||
* Sets the blue channel of @color to @blue.
|
||||
*
|
||||
* since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_blue_float (CoglColor *color,
|
||||
float blue);
|
||||
|
||||
/**
|
||||
* cogl_color_set_alpha_float:
|
||||
* @color: a #CoglColor
|
||||
* @alpha: a float value between 0.0f and 1.0f
|
||||
*
|
||||
* Sets the alpha channel of @color to @alpha.
|
||||
*
|
||||
* since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_alpha_float (CoglColor *color,
|
||||
float alpha);
|
||||
|
||||
/**
|
||||
* cogl_color_set_red:
|
||||
* @color: a #CoglColor
|
||||
* @red: a float value between 0.0f and 1.0f
|
||||
*
|
||||
* Sets the red channel of @color to @red.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_red (CoglColor *color,
|
||||
float red);
|
||||
|
||||
/**
|
||||
* cogl_color_set_green:
|
||||
* @color: a #CoglColor
|
||||
* @green: a float value between 0.0f and 1.0f
|
||||
*
|
||||
* Sets the green channel of @color to @green.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_green (CoglColor *color,
|
||||
float green);
|
||||
|
||||
/**
|
||||
* cogl_color_set_blue:
|
||||
* @color: a #CoglColor
|
||||
* @blue: a float value between 0.0f and 1.0f
|
||||
*
|
||||
* Sets the blue channel of @color to @blue.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_blue (CoglColor *color,
|
||||
float blue);
|
||||
|
||||
/**
|
||||
* cogl_color_set_alpha:
|
||||
* @color: a #CoglColor
|
||||
* @alpha: a float value between 0.0f and 1.0f
|
||||
*
|
||||
* Sets the alpha channel of @color to @alpha.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_set_alpha (CoglColor *color,
|
||||
float alpha);
|
||||
|
||||
/**
|
||||
* cogl_color_premultiply:
|
||||
* @color: the color to premultiply
|
||||
*
|
||||
* Converts a non-premultiplied color to a pre-multiplied color. For
|
||||
* example, semi-transparent red is (1.0, 0, 0, 0.5) when non-premultiplied
|
||||
* and (0.5, 0, 0, 0.5) when premultiplied.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
void
|
||||
cogl_color_premultiply (CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_unpremultiply:
|
||||
* @color: the color to unpremultiply
|
||||
*
|
||||
* Converts a pre-multiplied color to a non-premultiplied color. For
|
||||
* example, semi-transparent red is (0.5, 0, 0, 0.5) when premultiplied
|
||||
* and (1.0, 0, 0, 0.5) when non-premultiplied.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_color_unpremultiply (CoglColor *color);
|
||||
|
||||
/**
|
||||
* cogl_color_equal:
|
||||
* @v1: a #CoglColor
|
||||
* @v2: a #CoglColor
|
||||
*
|
||||
* Compares two #CoglColor<!-- -->s and checks if they are the same.
|
||||
*
|
||||
* This function can be passed to g_hash_table_new() as the @key_equal_func
|
||||
* parameter, when using #CoglColor<!-- -->s as keys in a #GHashTable.
|
||||
*
|
||||
* Return value: %TRUE if the two colors are the same.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
gboolean
|
||||
cogl_color_equal (gconstpointer v1,
|
||||
gconstpointer v2);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_COLOR_H__ */
|
@ -1,282 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_CONTEXT_PRIVATE_H
|
||||
#define __COGL_CONTEXT_PRIVATE_H
|
||||
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-context.h"
|
||||
#include "cogl-winsys-private.h"
|
||||
#include "cogl-flags.h"
|
||||
|
||||
#ifdef COGL_HAS_XLIB_SUPPORT
|
||||
#include "cogl-xlib-private.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_COGL_GL
|
||||
#include "cogl-context-driver-gl.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_COGL_GLES || HAVE_COGL_GLES2
|
||||
#include "cogl-context-driver-gles.h"
|
||||
#endif
|
||||
|
||||
#include "cogl-display-private.h"
|
||||
#include "cogl-primitives.h"
|
||||
#include "cogl-clip-stack.h"
|
||||
#include "cogl-matrix-stack.h"
|
||||
#include "cogl-pipeline-private.h"
|
||||
#include "cogl-buffer-private.h"
|
||||
#include "cogl-bitmask.h"
|
||||
#include "cogl-atlas.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GLfloat v[3];
|
||||
GLfloat t[2];
|
||||
GLubyte c[4];
|
||||
} CoglTextureGLVertex;
|
||||
|
||||
struct _CoglContext
|
||||
{
|
||||
CoglObject _parent;
|
||||
|
||||
CoglDisplay *display;
|
||||
|
||||
/* Features cache */
|
||||
CoglFeatureFlags feature_flags;
|
||||
|
||||
CoglHandle default_pipeline;
|
||||
CoglHandle default_layer_0;
|
||||
CoglHandle default_layer_n;
|
||||
CoglHandle dummy_layer_dependant;
|
||||
|
||||
/* Enable cache */
|
||||
unsigned long enable_flags;
|
||||
|
||||
gboolean enable_backface_culling;
|
||||
CoglFrontWinding flushed_front_winding;
|
||||
|
||||
/* A few handy matrix constants */
|
||||
CoglMatrix identity_matrix;
|
||||
CoglMatrix y_flip_matrix;
|
||||
|
||||
/* Client-side matrix stack or NULL if none */
|
||||
CoglMatrixMode flushed_matrix_mode;
|
||||
|
||||
/* On GLES2 we need to track the matrices separately because the are
|
||||
stored in GLSL uniforms rather than using the fixed function
|
||||
API. We keep track of the matrix stack that Cogl is trying to
|
||||
flush so we can flush it later after the program is generated. A
|
||||
reference is taken on the stacks. */
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
CoglMatrixStack *flushed_modelview_stack;
|
||||
CoglMatrixStack *flushed_projection_stack;
|
||||
#endif /* HAVE_COGL_GLES2 */
|
||||
|
||||
GArray *texture_units;
|
||||
int active_texture_unit;
|
||||
|
||||
CoglPipelineFogState legacy_fog_state;
|
||||
|
||||
/* Pipelines */
|
||||
CoglPipeline *opaque_color_pipeline; /* used for set_source_color */
|
||||
CoglPipeline *blended_color_pipeline; /* used for set_source_color */
|
||||
CoglPipeline *texture_pipeline; /* used for set_source_texture */
|
||||
GString *codegen_header_buffer;
|
||||
GString *codegen_source_buffer;
|
||||
GList *source_stack;
|
||||
|
||||
int legacy_state_set;
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
GHashTable *arbfp_cache;
|
||||
#endif
|
||||
|
||||
/* Textures */
|
||||
CoglHandle default_gl_texture_2d_tex;
|
||||
CoglHandle default_gl_texture_rect_tex;
|
||||
|
||||
/* Central list of all framebuffers so all journals can be flushed
|
||||
* at any time. */
|
||||
GList *framebuffers;
|
||||
|
||||
/* Global journal buffers */
|
||||
GArray *journal_flush_attributes_array;
|
||||
GArray *journal_clip_bounds;
|
||||
|
||||
GArray *polygon_vertices;
|
||||
|
||||
/* Some simple caching, to minimize state changes... */
|
||||
CoglPipeline *current_pipeline;
|
||||
unsigned long current_pipeline_changes_since_flush;
|
||||
gboolean current_pipeline_skip_gl_color;
|
||||
unsigned long current_pipeline_age;
|
||||
|
||||
GArray *pipeline0_nodes;
|
||||
GArray *pipeline1_nodes;
|
||||
|
||||
/* Bitmask of attributes enabled. On GLES2 these are the vertex
|
||||
attribute numbers and on regular GL these are only used for the
|
||||
texture coordinate arrays */
|
||||
CoglBitmask arrays_enabled;
|
||||
/* These are temporary bitmasks that are used when disabling
|
||||
texcoord arrays. They are here just to avoid allocating new ones
|
||||
each time */
|
||||
CoglBitmask arrays_to_change;
|
||||
CoglBitmask temp_bitmask;
|
||||
|
||||
gboolean gl_blend_enable_cache;
|
||||
|
||||
gboolean depth_test_enabled_cache;
|
||||
CoglDepthTestFunction depth_test_function_cache;
|
||||
gboolean depth_writing_enabled_cache;
|
||||
float depth_range_near_cache;
|
||||
float depth_range_far_cache;
|
||||
|
||||
gboolean legacy_depth_test_enabled;
|
||||
|
||||
float point_size_cache;
|
||||
|
||||
CoglBuffer *current_buffer[COGL_BUFFER_BIND_TARGET_COUNT];
|
||||
|
||||
/* Framebuffers */
|
||||
GSList *framebuffer_stack;
|
||||
CoglHandle window_buffer;
|
||||
gboolean dirty_bound_framebuffer;
|
||||
gboolean dirty_gl_viewport;
|
||||
|
||||
/* Primitives */
|
||||
CoglPath *current_path;
|
||||
CoglPipeline *stencil_pipeline;
|
||||
|
||||
/* Pre-generated VBOs containing indices to generate GL_TRIANGLES
|
||||
out of a vertex array of quads */
|
||||
CoglHandle quad_buffer_indices_byte;
|
||||
unsigned int quad_buffer_indices_len;
|
||||
CoglHandle quad_buffer_indices;
|
||||
|
||||
CoglIndices *rectangle_byte_indices;
|
||||
CoglIndices *rectangle_short_indices;
|
||||
int rectangle_short_indices_len;
|
||||
|
||||
gboolean in_begin_gl_block;
|
||||
|
||||
CoglPipeline *texture_download_pipeline;
|
||||
CoglPipeline *blit_texture_pipeline;
|
||||
|
||||
GSList *atlases;
|
||||
GHookList atlas_reorganize_callbacks;
|
||||
|
||||
/* This debugging variable is used to pick a colour for visually
|
||||
displaying the quad batches. It needs to be global so that it can
|
||||
be reset by cogl_clear. It needs to be reset to increase the
|
||||
chances of getting the same colour during an animation */
|
||||
guint8 journal_rectangles_color;
|
||||
|
||||
/* Cached values for GL_MAX_TEXTURE_[IMAGE_]UNITS to avoid calling
|
||||
glGetInteger too often */
|
||||
GLint max_texture_units;
|
||||
GLint max_texture_image_units;
|
||||
GLint max_activateable_texture_units;
|
||||
|
||||
/* Fragment processing programs */
|
||||
CoglHandle current_program;
|
||||
|
||||
CoglPipelineProgramType current_fragment_program_type;
|
||||
CoglPipelineProgramType current_vertex_program_type;
|
||||
GLuint current_gl_program;
|
||||
|
||||
/* List of types that will be considered a subclass of CoglTexture in
|
||||
cogl_is_texture */
|
||||
GSList *texture_types;
|
||||
|
||||
/* List of types that will be considered a subclass of CoglBuffer in
|
||||
cogl_is_buffer */
|
||||
GSList *buffer_types;
|
||||
|
||||
/* Clipping */
|
||||
/* TRUE if we have a valid clipping stack flushed. In that case
|
||||
current_clip_stack will describe what the current state is. If
|
||||
this is FALSE then the current clip stack is completely unknown
|
||||
so it will need to be reflushed. In that case current_clip_stack
|
||||
doesn't need to be a valid pointer. We can't just use NULL in
|
||||
current_clip_stack to mark a dirty state because NULL is a valid
|
||||
stack (meaning no clipping) */
|
||||
gboolean current_clip_stack_valid;
|
||||
/* The clip state that was flushed. This isn't intended to be used
|
||||
as a stack to push and pop new entries. Instead the current stack
|
||||
that the user wants is part of the framebuffer state. This is
|
||||
just used to record the flush state so we can avoid flushing the
|
||||
same state multiple times. When the clip state is flushed this
|
||||
will hold a reference */
|
||||
CoglClipStack *current_clip_stack;
|
||||
/* Whether the stencil buffer was used as part of the current clip
|
||||
state. If TRUE then any further use of the stencil buffer (such
|
||||
as for drawing paths) would need to be merged with the existing
|
||||
stencil buffer */
|
||||
gboolean current_clip_stack_uses_stencil;
|
||||
|
||||
/* This is used as a temporary buffer to fill a CoglBuffer when
|
||||
cogl_buffer_map fails and we only want to map to fill it with new
|
||||
data */
|
||||
GByteArray *buffer_map_fallback_array;
|
||||
gboolean buffer_map_fallback_in_use;
|
||||
|
||||
CoglWinsysRectangleState rectangle_state;
|
||||
|
||||
/* FIXME: remove these when we remove the last xlib based clutter
|
||||
* backend. they should be tracked as part of the renderer but e.g.
|
||||
* the eglx backend doesn't yet have a corresponding Cogl winsys
|
||||
* and so we wont have a renderer in that case. */
|
||||
#ifdef COGL_HAS_XLIB_SUPPORT
|
||||
int damage_base;
|
||||
/* List of callback functions that will be given every Xlib event */
|
||||
GSList *event_filters;
|
||||
/* Current top of the XError trap state stack. The actual memory for
|
||||
these is expected to be allocated on the stack by the caller */
|
||||
CoglXlibTrapState *trap_state;
|
||||
#endif
|
||||
|
||||
CoglContextDriver drv;
|
||||
|
||||
unsigned int winsys_features
|
||||
[COGL_FLAGS_N_INTS_FOR_SIZE (COGL_WINSYS_FEATURE_N_FEATURES)];
|
||||
void *winsys;
|
||||
gboolean stub_winsys;
|
||||
};
|
||||
|
||||
CoglContext *
|
||||
_cogl_context_get_default ();
|
||||
|
||||
const CoglWinsysVtable *
|
||||
_cogl_context_get_winsys (CoglContext *context);
|
||||
|
||||
/* Obtains the context and returns retval if NULL */
|
||||
#define _COGL_GET_CONTEXT(ctxvar, retval) \
|
||||
CoglContext *ctxvar = _cogl_context_get_default (); \
|
||||
if (ctxvar == NULL) return retval;
|
||||
|
||||
#define NO_RETVAL
|
||||
|
||||
#endif /* __COGL_CONTEXT_PRIVATE_H */
|
@ -1,501 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-object.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-private.h"
|
||||
#include "cogl-winsys-private.h"
|
||||
#include "cogl-profile.h"
|
||||
#include "cogl-util.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-display-private.h"
|
||||
#include "cogl-renderer-private.h"
|
||||
#include "cogl-journal-private.h"
|
||||
#include "cogl-texture-private.h"
|
||||
#include "cogl-pipeline-private.h"
|
||||
#include "cogl-pipeline-opengl-private.h"
|
||||
#include "cogl-framebuffer-private.h"
|
||||
#include "cogl2-path.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
#include "cogl-pipeline-fragend-arbfp-private.h"
|
||||
#define glActiveTexture _context->drv.pf_glActiveTexture
|
||||
#endif
|
||||
|
||||
/* This isn't defined in the GLES headers */
|
||||
#ifndef GL_POINT_SPRITE
|
||||
#define GL_POINT_SPRITE 0x8861
|
||||
#endif
|
||||
|
||||
static void _cogl_context_free (CoglContext *context);
|
||||
|
||||
COGL_OBJECT_DEFINE (Context, context);
|
||||
|
||||
extern void
|
||||
_cogl_create_context_driver (CoglContext *context);
|
||||
|
||||
static CoglContext *_context = NULL;
|
||||
|
||||
static void
|
||||
_cogl_init_feature_overrides (CoglContext *ctx)
|
||||
{
|
||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_VBOS)))
|
||||
ctx->feature_flags &= ~COGL_FEATURE_VBOS;
|
||||
|
||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_PBOS)))
|
||||
ctx->feature_flags &= ~COGL_FEATURE_PBOS;
|
||||
|
||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_ARBFP)))
|
||||
ctx->feature_flags &= ~COGL_FEATURE_SHADERS_ARBFP;
|
||||
|
||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_GLSL)))
|
||||
ctx->feature_flags &= ~COGL_FEATURE_SHADERS_GLSL;
|
||||
|
||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_NPOT_TEXTURES)))
|
||||
ctx->feature_flags &= ~(COGL_FEATURE_TEXTURE_NPOT |
|
||||
COGL_FEATURE_TEXTURE_NPOT_BASIC |
|
||||
COGL_FEATURE_TEXTURE_NPOT_MIPMAP |
|
||||
COGL_FEATURE_TEXTURE_NPOT_REPEAT);
|
||||
}
|
||||
|
||||
const CoglWinsysVtable *
|
||||
_cogl_context_get_winsys (CoglContext *context)
|
||||
{
|
||||
return context->display->renderer->winsys_vtable;
|
||||
}
|
||||
|
||||
/* For reference: There was some deliberation over whether to have a
|
||||
* constructor that could throw an exception but looking at standard
|
||||
* practices with several high level OO languages including python, C++,
|
||||
* C# Java and Ruby they all support exceptions in constructors and the
|
||||
* general consensus appears to be that throwing an exception is neater
|
||||
* than successfully constructing with an internal error status that
|
||||
* would then have to be explicitly checked via some form of ::is_ok()
|
||||
* method.
|
||||
*/
|
||||
CoglContext *
|
||||
cogl_context_new (CoglDisplay *display,
|
||||
GError **error)
|
||||
{
|
||||
CoglContext *context;
|
||||
GLubyte default_texture_data[] = { 0xff, 0xff, 0xff, 0x0 };
|
||||
unsigned long enable_flags = 0;
|
||||
const CoglWinsysVtable *winsys;
|
||||
int i;
|
||||
|
||||
#ifdef CLUTTER_ENABLE_PROFILE
|
||||
/* We need to be absolutely sure that uprof has been initialized
|
||||
* before calling _cogl_uprof_init. uprof_init (NULL, NULL)
|
||||
* will be a NOP if it has been initialized but it will also
|
||||
* mean subsequent parsing of the UProf GOptionGroup will have no
|
||||
* affect.
|
||||
*
|
||||
* Sadly GOptionGroup based library initialization is extremely
|
||||
* fragile by design because GOptionGroups have no notion of
|
||||
* dependencies and so the order things are initialized isn't
|
||||
* currently under tight control.
|
||||
*/
|
||||
uprof_init (NULL, NULL);
|
||||
_cogl_uprof_init ();
|
||||
#endif
|
||||
|
||||
/* Allocate context memory */
|
||||
context = g_malloc (sizeof (CoglContext));
|
||||
|
||||
/* XXX: Gross hack!
|
||||
* Currently everything in Cogl just assumes there is a default
|
||||
* context which it can access via _COGL_GET_CONTEXT() including
|
||||
* code used to construct a CoglContext. Until all of that code
|
||||
* has been updated to take an explicit context argument we have
|
||||
* to immediately make our pointer the default context.
|
||||
*/
|
||||
_context = context;
|
||||
|
||||
/* Init default values */
|
||||
context->feature_flags = 0;
|
||||
|
||||
context->texture_types = NULL;
|
||||
context->buffer_types = NULL;
|
||||
|
||||
context->rectangle_state = COGL_WINSYS_RECTANGLE_STATE_UNKNOWN;
|
||||
|
||||
memset (context->winsys_features, 0, sizeof (context->winsys_features));
|
||||
|
||||
if (!display)
|
||||
display = cogl_display_new (NULL, NULL);
|
||||
else
|
||||
cogl_object_ref (display);
|
||||
|
||||
if (!cogl_display_setup (display, error))
|
||||
{
|
||||
cogl_object_unref (display);
|
||||
g_free (context);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
context->display = display;
|
||||
|
||||
#ifdef COGL_HAS_FULL_WINSYS
|
||||
context->stub_winsys = FALSE;
|
||||
winsys = _cogl_context_get_winsys (context);
|
||||
if (!winsys->context_init (context, error))
|
||||
{
|
||||
cogl_object_unref (display);
|
||||
g_free (context);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
/* In this case Clutter is still responsible for creating a GL
|
||||
* context. */
|
||||
context->stub_winsys = TRUE;
|
||||
if (!_cogl_gl_check_version (error))
|
||||
{
|
||||
g_free (context);
|
||||
return NULL;
|
||||
}
|
||||
_cogl_gl_update_features (context);
|
||||
#ifdef COGL_HAS_XLIB_SUPPORT
|
||||
_cogl_xlib_query_damage_extension ();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Initialise the driver specific state */
|
||||
_cogl_init_feature_overrides (context);
|
||||
|
||||
_cogl_pipeline_init_default_pipeline ();
|
||||
_cogl_pipeline_init_default_layers ();
|
||||
_cogl_pipeline_init_state_hash_functions ();
|
||||
_cogl_pipeline_init_layer_state_hash_functions ();
|
||||
|
||||
context->enable_flags = 0;
|
||||
|
||||
context->enable_backface_culling = FALSE;
|
||||
context->flushed_front_winding = COGL_FRONT_WINDING_COUNTER_CLOCKWISE;
|
||||
|
||||
cogl_matrix_init_identity (&context->identity_matrix);
|
||||
cogl_matrix_init_identity (&context->y_flip_matrix);
|
||||
cogl_matrix_scale (&context->y_flip_matrix, 1, -1, 1);
|
||||
|
||||
context->flushed_matrix_mode = COGL_MATRIX_MODELVIEW;
|
||||
|
||||
context->texture_units =
|
||||
g_array_new (FALSE, FALSE, sizeof (CoglTextureUnit));
|
||||
|
||||
/* See cogl-pipeline.c for more details about why we leave texture unit 1
|
||||
* active by default... */
|
||||
context->active_texture_unit = 1;
|
||||
GE (glActiveTexture (GL_TEXTURE1));
|
||||
|
||||
context->legacy_fog_state.enabled = FALSE;
|
||||
|
||||
context->opaque_color_pipeline = cogl_pipeline_new ();
|
||||
context->blended_color_pipeline = cogl_pipeline_new ();
|
||||
context->texture_pipeline = cogl_pipeline_new ();
|
||||
context->codegen_header_buffer = g_string_new ("");
|
||||
context->codegen_source_buffer = g_string_new ("");
|
||||
context->source_stack = NULL;
|
||||
|
||||
context->legacy_state_set = 0;
|
||||
|
||||
context->default_gl_texture_2d_tex = COGL_INVALID_HANDLE;
|
||||
context->default_gl_texture_rect_tex = COGL_INVALID_HANDLE;
|
||||
|
||||
context->framebuffers = NULL;
|
||||
|
||||
context->journal_flush_attributes_array =
|
||||
g_array_new (TRUE, FALSE, sizeof (CoglAttribute *));
|
||||
context->journal_clip_bounds = NULL;
|
||||
|
||||
context->polygon_vertices = g_array_new (FALSE, FALSE, sizeof (float));
|
||||
|
||||
context->current_pipeline = NULL;
|
||||
context->current_pipeline_changes_since_flush = 0;
|
||||
context->current_pipeline_skip_gl_color = FALSE;
|
||||
|
||||
context->pipeline0_nodes =
|
||||
g_array_sized_new (FALSE, FALSE, sizeof (CoglHandle), 20);
|
||||
context->pipeline1_nodes =
|
||||
g_array_sized_new (FALSE, FALSE, sizeof (CoglHandle), 20);
|
||||
|
||||
_cogl_bitmask_init (&context->arrays_enabled);
|
||||
_cogl_bitmask_init (&context->temp_bitmask);
|
||||
_cogl_bitmask_init (&context->arrays_to_change);
|
||||
|
||||
context->max_texture_units = -1;
|
||||
context->max_texture_image_units = -1;
|
||||
context->max_activateable_texture_units = -1;
|
||||
|
||||
context->current_program = COGL_INVALID_HANDLE;
|
||||
|
||||
context->current_fragment_program_type = COGL_PIPELINE_PROGRAM_TYPE_FIXED;
|
||||
context->current_vertex_program_type = COGL_PIPELINE_PROGRAM_TYPE_FIXED;
|
||||
context->current_gl_program = 0;
|
||||
|
||||
context->gl_blend_enable_cache = FALSE;
|
||||
|
||||
context->depth_test_enabled_cache = FALSE;
|
||||
context->depth_test_function_cache = COGL_DEPTH_TEST_FUNCTION_LESS;
|
||||
context->depth_writing_enabled_cache = TRUE;
|
||||
context->depth_range_near_cache = 0;
|
||||
context->depth_range_far_cache = 1;
|
||||
|
||||
context->point_size_cache = 1.0f;
|
||||
|
||||
context->legacy_depth_test_enabled = FALSE;
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
_context->arbfp_cache = g_hash_table_new (_cogl_pipeline_fragend_arbfp_hash,
|
||||
_cogl_pipeline_fragend_arbfp_equal);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < COGL_BUFFER_BIND_TARGET_COUNT; i++)
|
||||
context->current_buffer[i] = NULL;
|
||||
|
||||
context->framebuffer_stack = _cogl_create_framebuffer_stack ();
|
||||
|
||||
/* XXX: In this case the Clutter backend is still responsible for
|
||||
* the OpenGL binding API and for creating onscreen framebuffers and
|
||||
* so we have to add a dummy framebuffer to represent the backend
|
||||
* owned window... */
|
||||
if (context->stub_winsys)
|
||||
{
|
||||
CoglOnscreen *window = _cogl_onscreen_new ();
|
||||
cogl_set_framebuffer (COGL_FRAMEBUFFER (window));
|
||||
cogl_object_unref (COGL_FRAMEBUFFER (window));
|
||||
}
|
||||
|
||||
_context->current_clip_stack_valid = FALSE;
|
||||
|
||||
context->dirty_bound_framebuffer = TRUE;
|
||||
context->dirty_gl_viewport = TRUE;
|
||||
|
||||
context->current_path = cogl2_path_new ();
|
||||
context->stencil_pipeline = cogl_pipeline_new ();
|
||||
|
||||
context->in_begin_gl_block = FALSE;
|
||||
|
||||
context->quad_buffer_indices_byte = COGL_INVALID_HANDLE;
|
||||
context->quad_buffer_indices = COGL_INVALID_HANDLE;
|
||||
context->quad_buffer_indices_len = 0;
|
||||
|
||||
context->rectangle_byte_indices = NULL;
|
||||
context->rectangle_short_indices = NULL;
|
||||
context->rectangle_short_indices_len = 0;
|
||||
|
||||
context->texture_download_pipeline = COGL_INVALID_HANDLE;
|
||||
context->blit_texture_pipeline = COGL_INVALID_HANDLE;
|
||||
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
/* The default for GL_ALPHA_TEST is to always pass which is equivalent to
|
||||
* the test being disabled therefore we assume that for all drivers there
|
||||
* will be no performance impact if we always leave the test enabled which
|
||||
* makes things a bit simpler for us. Under GLES2 the alpha test is
|
||||
* implemented in the fragment shader so there is no enable for it
|
||||
*/
|
||||
GE (glEnable (GL_ALPHA_TEST));
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
_context->flushed_modelview_stack = NULL;
|
||||
_context->flushed_projection_stack = NULL;
|
||||
#endif
|
||||
|
||||
/* Create default textures used for fall backs */
|
||||
context->default_gl_texture_2d_tex =
|
||||
cogl_texture_new_from_data (1, /* width */
|
||||
1, /* height */
|
||||
COGL_TEXTURE_NO_SLICING,
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */
|
||||
/* internal format */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
||||
0, /* auto calc row stride */
|
||||
default_texture_data);
|
||||
context->default_gl_texture_rect_tex =
|
||||
cogl_texture_new_from_data (1, /* width */
|
||||
1, /* height */
|
||||
COGL_TEXTURE_NO_SLICING,
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */
|
||||
/* internal format */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
||||
0, /* auto calc row stride */
|
||||
default_texture_data);
|
||||
|
||||
cogl_push_source (context->opaque_color_pipeline);
|
||||
_cogl_pipeline_flush_gl_state (context->opaque_color_pipeline, FALSE, 0);
|
||||
_cogl_enable (enable_flags);
|
||||
_cogl_flush_face_winding ();
|
||||
|
||||
context->atlases = NULL;
|
||||
g_hook_list_init (&context->atlas_reorganize_callbacks, sizeof (GHook));
|
||||
|
||||
_context->buffer_map_fallback_array = g_byte_array_new ();
|
||||
_context->buffer_map_fallback_in_use = FALSE;
|
||||
|
||||
/* As far as I can tell, GL_POINT_SPRITE doesn't have any effect
|
||||
unless GL_COORD_REPLACE is enabled for an individual
|
||||
layer. Therefore it seems like it should be ok to just leave it
|
||||
enabled all the time instead of having to have a set property on
|
||||
each pipeline to track whether any layers have point sprite
|
||||
coords enabled. We don't need to do this for GLES2 because point
|
||||
sprites are handled using a builtin varying in the shader. */
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
if (cogl_features_available (COGL_FEATURE_POINT_SPRITE))
|
||||
GE (glEnable (GL_POINT_SPRITE));
|
||||
#endif
|
||||
|
||||
return _cogl_context_object_new (context);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_context_free (CoglContext *context)
|
||||
{
|
||||
const CoglWinsysVtable *winsys = _cogl_context_get_winsys (context);
|
||||
|
||||
winsys->context_deinit (context);
|
||||
|
||||
_cogl_destroy_texture_units ();
|
||||
|
||||
_cogl_free_framebuffer_stack (context->framebuffer_stack);
|
||||
|
||||
if (context->current_path)
|
||||
cogl_handle_unref (context->current_path);
|
||||
|
||||
if (context->default_gl_texture_2d_tex)
|
||||
cogl_handle_unref (context->default_gl_texture_2d_tex);
|
||||
if (context->default_gl_texture_rect_tex)
|
||||
cogl_handle_unref (context->default_gl_texture_rect_tex);
|
||||
|
||||
if (context->opaque_color_pipeline)
|
||||
cogl_handle_unref (context->opaque_color_pipeline);
|
||||
if (context->blended_color_pipeline)
|
||||
cogl_handle_unref (context->blended_color_pipeline);
|
||||
if (context->texture_pipeline)
|
||||
cogl_handle_unref (context->texture_pipeline);
|
||||
|
||||
if (context->blit_texture_pipeline)
|
||||
cogl_handle_unref (context->blit_texture_pipeline);
|
||||
|
||||
if (context->journal_flush_attributes_array)
|
||||
g_array_free (context->journal_flush_attributes_array, TRUE);
|
||||
if (context->journal_clip_bounds)
|
||||
g_array_free (context->journal_clip_bounds, TRUE);
|
||||
|
||||
if (context->polygon_vertices)
|
||||
g_array_free (context->polygon_vertices, TRUE);
|
||||
|
||||
if (context->quad_buffer_indices_byte)
|
||||
cogl_handle_unref (context->quad_buffer_indices_byte);
|
||||
if (context->quad_buffer_indices)
|
||||
cogl_handle_unref (context->quad_buffer_indices);
|
||||
|
||||
if (context->rectangle_byte_indices)
|
||||
cogl_object_unref (context->rectangle_byte_indices);
|
||||
if (context->rectangle_short_indices)
|
||||
cogl_object_unref (context->rectangle_short_indices);
|
||||
|
||||
if (context->default_pipeline)
|
||||
cogl_handle_unref (context->default_pipeline);
|
||||
|
||||
if (context->dummy_layer_dependant)
|
||||
cogl_handle_unref (context->dummy_layer_dependant);
|
||||
if (context->default_layer_n)
|
||||
cogl_handle_unref (context->default_layer_n);
|
||||
if (context->default_layer_0)
|
||||
cogl_handle_unref (context->default_layer_0);
|
||||
|
||||
if (context->current_clip_stack_valid)
|
||||
_cogl_clip_stack_unref (context->current_clip_stack);
|
||||
|
||||
g_slist_free (context->atlases);
|
||||
g_hook_list_clear (&context->atlas_reorganize_callbacks);
|
||||
|
||||
_cogl_bitmask_destroy (&context->arrays_enabled);
|
||||
_cogl_bitmask_destroy (&context->temp_bitmask);
|
||||
_cogl_bitmask_destroy (&context->arrays_to_change);
|
||||
|
||||
g_slist_free (context->texture_types);
|
||||
g_slist_free (context->buffer_types);
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
if (_context->flushed_modelview_stack)
|
||||
cogl_object_unref (_context->flushed_modelview_stack);
|
||||
if (_context->flushed_projection_stack)
|
||||
cogl_object_unref (_context->flushed_projection_stack);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
g_hash_table_unref (context->arbfp_cache);
|
||||
#endif
|
||||
|
||||
g_byte_array_free (context->buffer_map_fallback_array, TRUE);
|
||||
|
||||
cogl_object_unref (context->display);
|
||||
|
||||
g_free (context);
|
||||
}
|
||||
|
||||
CoglContext *
|
||||
_cogl_context_get_default (void)
|
||||
{
|
||||
GError *error = NULL;
|
||||
/* Create if doesn't exist yet */
|
||||
if (_context == NULL)
|
||||
{
|
||||
_context = cogl_context_new (NULL, &error);
|
||||
if (!_context)
|
||||
{
|
||||
g_warning ("Failed to create default context: %s",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
|
||||
return _context;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_set_default_context (CoglContext *context)
|
||||
{
|
||||
cogl_object_ref (context);
|
||||
|
||||
if (_context)
|
||||
cogl_object_unref (_context);
|
||||
_context = context;
|
||||
}
|
||||
|
||||
#ifdef COGL_HAS_EGL_SUPPORT
|
||||
EGLDisplay
|
||||
cogl_context_egl_get_egl_display (CoglContext *context)
|
||||
{
|
||||
const CoglWinsysVtable *winsys = _cogl_context_get_winsys (context);
|
||||
return winsys->context_egl_get_egl_display (context);
|
||||
}
|
||||
#endif
|
||||
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_CONTEXT_H__
|
||||
#define __COGL_CONTEXT_H__
|
||||
|
||||
#include <cogl/cogl-display.h>
|
||||
|
||||
#ifdef COGL_HAS_EGL_SUPPORT
|
||||
#ifdef COGL_HAS_GLES1
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/egl.h>
|
||||
#else
|
||||
#include <EGL/egl.h>
|
||||
#define NativeDisplayType EGLNativeDisplayType
|
||||
#define NativeWindowType EGLNativeWindowType
|
||||
#endif
|
||||
#endif
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-context
|
||||
* @short_description: The top level application context.
|
||||
*
|
||||
* A CoglContext is the topmost sandbox of Cogl state for an
|
||||
* application or toolkit. Its main purpose is to bind together the
|
||||
* key state objects at any one time; with the most significant being
|
||||
* the current framebuffer being drawn too (See #CoglFramebuffer for
|
||||
* more details) and the current GPU pipeline configuration (See
|
||||
* #CoglPipeline for more details).
|
||||
*/
|
||||
|
||||
typedef struct _CoglContext CoglContext;
|
||||
|
||||
#define COGL_CONTEXT(OBJECT) ((CoglContext *)OBJECT)
|
||||
|
||||
#define cogl_context_new cogl_context_new_EXP
|
||||
|
||||
CoglContext *
|
||||
cogl_context_new (CoglDisplay *display,
|
||||
GError **error);
|
||||
|
||||
#define cogl_set_default_context cogl_set_default_context_EXP
|
||||
void
|
||||
cogl_set_default_context (CoglContext *context);
|
||||
|
||||
#ifdef COGL_HAS_EGL_SUPPORT
|
||||
#define cogl_context_egl_get_egl_display cogl_context_egl_get_egl_display_EXP
|
||||
EGLDisplay
|
||||
cogl_context_egl_get_egl_display (CoglContext *context);
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_CONTEXT_H__ */
|
||||
|
@ -1,187 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
OPT (HANDLE,
|
||||
"Cogl Tracing",
|
||||
"ref-counts",
|
||||
"CoglObject references",
|
||||
"Debug ref counting issues for CoglObjects")
|
||||
OPT (SLICING,
|
||||
"Cogl Tracing",
|
||||
"slicing",
|
||||
"Trace Texture Slicing",
|
||||
"debug the creation of texture slices")
|
||||
OPT (ATLAS,
|
||||
"Cogl Tracing",
|
||||
"atlas",
|
||||
"Trace Atlas Textures",
|
||||
"Debug texture atlas management")
|
||||
OPT (BLEND_STRINGS,
|
||||
"Cogl Tracing",
|
||||
"blend-strings",
|
||||
"Trace Blend Strings",
|
||||
"Debug CoglBlendString parsing")
|
||||
OPT (JOURNAL,
|
||||
"Cogl Tracing",
|
||||
"journal",
|
||||
"Trace Journal",
|
||||
"View all the geometry passing through the journal")
|
||||
OPT (BATCHING,
|
||||
"Cogl Tracing",
|
||||
"batching",
|
||||
"Trace Batching",
|
||||
"Show how geometry is being batched in the journal")
|
||||
OPT (MATRICES,
|
||||
"Cogl Tracing",
|
||||
"matrices",
|
||||
"Trace matrices",
|
||||
"Trace all matrix manipulation")
|
||||
/* XXX we should replace the "draw" option its very hand wavy... */
|
||||
OPT (DRAW,
|
||||
"Cogl Tracing",
|
||||
"draw",
|
||||
"Trace Misc Drawing",
|
||||
"Trace some misc drawing operations")
|
||||
OPT (PANGO,
|
||||
"Cogl Tracing",
|
||||
"pango",
|
||||
"Trace Pango Renderer",
|
||||
"Trace the Cogl Pango renderer")
|
||||
OPT (TEXTURE_PIXMAP,
|
||||
"Cogl Tracing",
|
||||
"texture-pixmap",
|
||||
"Trace CoglTexturePixmap backend",
|
||||
"Trace the Cogl texture pixmap backend")
|
||||
OPT (RECTANGLES,
|
||||
"Visualize",
|
||||
"rectangles",
|
||||
"Outline rectangles",
|
||||
"Add wire outlines for all rectangular geometry")
|
||||
OPT (WIREFRAME,
|
||||
"Visualize",
|
||||
"wireframe",
|
||||
"Show wireframes",
|
||||
"Add wire outlines for all geometry")
|
||||
OPT (DISABLE_BATCHING,
|
||||
"Root Cause",
|
||||
"disable-batching",
|
||||
"Disable Journal batching",
|
||||
"Disable batching of geometry in the Cogl Journal.")
|
||||
OPT (DISABLE_VBOS,
|
||||
"Root Cause",
|
||||
"disable-vbos",
|
||||
"Disable GL Vertex Buffers",
|
||||
"Disable use of OpenGL vertex buffer objects")
|
||||
OPT (DISABLE_PBOS,
|
||||
"Root Cause",
|
||||
"disable-pbos",
|
||||
"Disable GL Pixel Buffers",
|
||||
"Disable use of OpenGL pixel buffer objects")
|
||||
OPT (DISABLE_SOFTWARE_TRANSFORM,
|
||||
"Root Cause",
|
||||
"disable-software-transform",
|
||||
"Disable software rect transform",
|
||||
"Use the GPU to transform rectangular geometry")
|
||||
OPT (DUMP_ATLAS_IMAGE,
|
||||
"Cogl Specialist",
|
||||
"dump-atlas-image",
|
||||
"Dump atlas images",
|
||||
"Dump texture atlas changes to an image file")
|
||||
OPT (DISABLE_ATLAS,
|
||||
"Root Cause",
|
||||
"disable-atlas",
|
||||
"Disable texture atlasing",
|
||||
"Disable use of texture atlasing")
|
||||
OPT (DISABLE_SHARED_ATLAS,
|
||||
"Root Cause",
|
||||
"disable-shared-atlas",
|
||||
"Disable sharing the texture atlas between text and images",
|
||||
"When this is set the glyph cache will always use a separate texture "
|
||||
"for its atlas. Otherwise it will try to share the atlas with images.")
|
||||
OPT (DISABLE_TEXTURING,
|
||||
"Root Cause",
|
||||
"disable-texturing",
|
||||
"Disable texturing",
|
||||
"Disable texturing any primitives")
|
||||
OPT (DISABLE_ARBFP,
|
||||
"Root Cause",
|
||||
"disable-arbfp",
|
||||
"Disable arbfp",
|
||||
"Disable use of ARB fragment programs")
|
||||
OPT (DISABLE_FIXED,
|
||||
"Root Cause",
|
||||
"disable-fixed",
|
||||
"Disable fixed",
|
||||
"Disable use of the fixed function pipeline backend")
|
||||
OPT (DISABLE_GLSL,
|
||||
"Root Cause",
|
||||
"disable-glsl",
|
||||
"Disable GLSL",
|
||||
"Disable use of GLSL")
|
||||
OPT (DISABLE_BLENDING,
|
||||
"Root Cause",
|
||||
"disable-blending",
|
||||
"Disable blending",
|
||||
"Disable use of blending")
|
||||
OPT (DISABLE_NPOT_TEXTURES,
|
||||
"Root Cause",
|
||||
"disable-npot-textures",
|
||||
"Disable non-power-of-two textures",
|
||||
"Makes Cogl think that the GL driver doesn't support NPOT textures "
|
||||
"so that it will create sliced textures or textures with waste instead.")
|
||||
OPT (DISABLE_SOFTWARE_CLIP,
|
||||
"Root Cause",
|
||||
"disable-software-clip",
|
||||
"Disable software clipping",
|
||||
"Disables Cogl's attempts to clip some rectangles in software.")
|
||||
OPT (SHOW_SOURCE,
|
||||
"Cogl Tracing",
|
||||
"show-source",
|
||||
"Show source",
|
||||
"Show generated ARBfp/GLSL source code")
|
||||
OPT (OPENGL,
|
||||
"Cogl Tracing",
|
||||
"opengl",
|
||||
"Trace some OpenGL",
|
||||
"Traces some select OpenGL calls")
|
||||
OPT (OFFSCREEN,
|
||||
"Cogl Tracing",
|
||||
"offscreen",
|
||||
"Trace offscreen support",
|
||||
"Debug offscreen support")
|
||||
OPT (DISABLE_BLENDING,
|
||||
"Root Cause",
|
||||
"disable-program-caches",
|
||||
"Disable program caches",
|
||||
"Disable fallback caches for arbfp and glsl programs")
|
||||
OPT (DISABLE_FAST_READ_PIXEL,
|
||||
"Root Cause",
|
||||
"disable-fast-read-pixel",
|
||||
"Disable read pixel optimization",
|
||||
"Disable optimization for reading 1px for simple "
|
||||
"scenes of opaque rectangles")
|
||||
OPT (CLIPPING,
|
||||
"Cogl Tracing",
|
||||
"clipping",
|
||||
"Trace clipping",
|
||||
"Logs information about how Cogl is implementing clipping")
|
@ -1,248 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <glib/gi18n-lib.h>
|
||||
|
||||
#include "cogl-debug.h"
|
||||
|
||||
#ifdef COGL_ENABLE_DEBUG
|
||||
|
||||
/* XXX: If you add a debug option, please also add an option
|
||||
* definition to cogl-debug-options.h. This will enable us - for
|
||||
* example - to emit a "help" description for the option.
|
||||
*/
|
||||
|
||||
/* NB: Only these options get enabled if COGL_DEBUG=all is
|
||||
* used since they don't affect the behaviour of Cogl they
|
||||
* simply print out verbose information */
|
||||
static const GDebugKey cogl_log_debug_keys[] = {
|
||||
{ "handle", COGL_DEBUG_HANDLE },
|
||||
{ "slicing", COGL_DEBUG_SLICING },
|
||||
{ "atlas", COGL_DEBUG_ATLAS },
|
||||
{ "blend-strings", COGL_DEBUG_BLEND_STRINGS },
|
||||
{ "journal", COGL_DEBUG_JOURNAL },
|
||||
{ "batching", COGL_DEBUG_BATCHING },
|
||||
{ "matrices", COGL_DEBUG_MATRICES },
|
||||
{ "draw", COGL_DEBUG_DRAW },
|
||||
{ "opengl", COGL_DEBUG_OPENGL },
|
||||
{ "pango", COGL_DEBUG_PANGO },
|
||||
{ "show-source", COGL_DEBUG_SHOW_SOURCE},
|
||||
{ "offscreen", COGL_DEBUG_OFFSCREEN },
|
||||
{ "texture-pixmap", COGL_DEBUG_TEXTURE_PIXMAP },
|
||||
{ "bitmap", COGL_DEBUG_BITMAP },
|
||||
{ "clipping", COGL_DEBUG_CLIPPING }
|
||||
};
|
||||
static const int n_cogl_log_debug_keys =
|
||||
G_N_ELEMENTS (cogl_log_debug_keys);
|
||||
|
||||
static const GDebugKey cogl_behavioural_debug_keys[] = {
|
||||
{ "rectangles", COGL_DEBUG_RECTANGLES },
|
||||
{ "disable-batching", COGL_DEBUG_DISABLE_BATCHING },
|
||||
{ "disable-vbos", COGL_DEBUG_DISABLE_VBOS },
|
||||
{ "disable-pbos", COGL_DEBUG_DISABLE_PBOS },
|
||||
{ "disable-software-transform", COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM },
|
||||
{ "dump-atlas-image", COGL_DEBUG_DUMP_ATLAS_IMAGE },
|
||||
{ "disable-atlas", COGL_DEBUG_DISABLE_ATLAS },
|
||||
{ "disable-shared-atlas", COGL_DEBUG_DISABLE_SHARED_ATLAS },
|
||||
{ "disable-texturing", COGL_DEBUG_DISABLE_TEXTURING},
|
||||
{ "disable-arbfp", COGL_DEBUG_DISABLE_ARBFP},
|
||||
{ "disable-fixed", COGL_DEBUG_DISABLE_FIXED},
|
||||
{ "disable-glsl", COGL_DEBUG_DISABLE_GLSL},
|
||||
{ "disable-blending", COGL_DEBUG_DISABLE_BLENDING},
|
||||
{ "disable-npot-textures", COGL_DEBUG_DISABLE_NPOT_TEXTURES},
|
||||
{ "wireframe", COGL_DEBUG_WIREFRAME},
|
||||
{ "disable-software-clip", COGL_DEBUG_DISABLE_SOFTWARE_CLIP},
|
||||
{ "disable-program-caches", COGL_DEBUG_DISABLE_PROGRAM_CACHES},
|
||||
{ "disable-fast-read-pixel", COGL_DEBUG_DISABLE_FAST_READ_PIXEL}
|
||||
};
|
||||
static const int n_cogl_behavioural_debug_keys =
|
||||
G_N_ELEMENTS (cogl_behavioural_debug_keys);
|
||||
|
||||
unsigned int _cogl_debug_flags[COGL_DEBUG_N_INTS];
|
||||
|
||||
static void
|
||||
_cogl_parse_debug_string_for_keys (const char *value,
|
||||
gboolean enable,
|
||||
const GDebugKey *keys,
|
||||
unsigned int nkeys)
|
||||
{
|
||||
int int_num, key_num;
|
||||
|
||||
/* g_parse_debug_string expects the value field in GDebugKey to be a
|
||||
mask in a guint but we may have multiple guints so we need to
|
||||
build a separate array for each possible guint */
|
||||
|
||||
for (int_num = 0; int_num < COGL_DEBUG_N_INTS; int_num++)
|
||||
{
|
||||
GDebugKey keys_for_int[sizeof (unsigned int) * 8];
|
||||
unsigned int mask_for_int;
|
||||
int nkeys_for_int = 0;
|
||||
|
||||
for (key_num = 0; key_num < nkeys; key_num++)
|
||||
if (COGL_FLAGS_GET_INDEX (keys[key_num].value) == int_num)
|
||||
{
|
||||
keys_for_int[nkeys_for_int] = keys[key_num];
|
||||
keys_for_int[nkeys_for_int].value =
|
||||
COGL_FLAGS_GET_MASK (keys[key_num].value);
|
||||
nkeys_for_int++;
|
||||
}
|
||||
|
||||
if (nkeys_for_int > 0)
|
||||
{
|
||||
mask_for_int = g_parse_debug_string (value,
|
||||
keys_for_int,
|
||||
nkeys_for_int);
|
||||
if (enable)
|
||||
_cogl_debug_flags[int_num] |= mask_for_int;
|
||||
else
|
||||
_cogl_debug_flags[int_num] &= ~mask_for_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_parse_debug_string (const char *value,
|
||||
gboolean enable,
|
||||
gboolean ignore_help)
|
||||
{
|
||||
if (ignore_help && strcmp (value, "help") == 0)
|
||||
return;
|
||||
|
||||
/* We don't want to let g_parse_debug_string handle "all" because
|
||||
* literally enabling all the debug options wouldn't be useful to
|
||||
* anyone; instead the all option enables all non behavioural
|
||||
* options.
|
||||
*/
|
||||
if (strcmp (value, "all") == 0 ||
|
||||
strcmp (value, "verbose") == 0)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n_cogl_log_debug_keys; i++)
|
||||
if (enable)
|
||||
COGL_DEBUG_SET_FLAG (cogl_log_debug_keys[i].value);
|
||||
else
|
||||
COGL_DEBUG_CLEAR_FLAG (cogl_log_debug_keys[i].value);
|
||||
}
|
||||
else if (strcmp (value, "help") == 0)
|
||||
{
|
||||
g_printerr ("\n\n%28s\n", "Supported debug values:");
|
||||
#define OPT(MASK_NAME, GROUP, NAME, NAME_FORMATTED, DESCRIPTION) \
|
||||
g_printerr ("%28s %s\n", NAME ":", DESCRIPTION);
|
||||
#include "cogl-debug-options.h"
|
||||
g_printerr ("\n%28s\n", "Special debug values:");
|
||||
OPT (IGNORED, "ignored", "all", "ignored", \
|
||||
"Enables all non-behavioural debug options");
|
||||
OPT (IGNORED, "ignored", "verbose", "ignored", \
|
||||
"Enables all non-behavioural debug options");
|
||||
#undef OPT
|
||||
exit (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_cogl_parse_debug_string_for_keys (value,
|
||||
enable,
|
||||
cogl_log_debug_keys,
|
||||
n_cogl_log_debug_keys);
|
||||
_cogl_parse_debug_string_for_keys (value,
|
||||
enable,
|
||||
cogl_behavioural_debug_keys,
|
||||
n_cogl_behavioural_debug_keys);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
cogl_arg_debug_cb (const char *key,
|
||||
const char *value,
|
||||
gpointer user_data)
|
||||
{
|
||||
_cogl_parse_debug_string (value,
|
||||
TRUE /* enable the flags */,
|
||||
FALSE /* don't ignore help */);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
cogl_arg_no_debug_cb (const char *key,
|
||||
const char *value,
|
||||
gpointer user_data)
|
||||
{
|
||||
_cogl_parse_debug_string (value,
|
||||
FALSE, /* disable the flags */
|
||||
TRUE /* ignore help */);
|
||||
return TRUE;
|
||||
}
|
||||
#endif /* COGL_ENABLE_DEBUG */
|
||||
|
||||
static GOptionEntry cogl_args[] = {
|
||||
#ifdef COGL_ENABLE_DEBUG
|
||||
{ "cogl-debug", 0, 0, G_OPTION_ARG_CALLBACK, cogl_arg_debug_cb,
|
||||
N_("Cogl debugging flags to set"), "FLAGS" },
|
||||
{ "cogl-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, cogl_arg_no_debug_cb,
|
||||
N_("Cogl debugging flags to unset"), "FLAGS" },
|
||||
#endif /* COGL_ENABLE_DEBUG */
|
||||
{ NULL, },
|
||||
};
|
||||
|
||||
static gboolean
|
||||
pre_parse_hook (GOptionContext *context,
|
||||
GOptionGroup *group,
|
||||
gpointer data,
|
||||
GError **error)
|
||||
{
|
||||
#ifdef COGL_ENABLE_DEBUG
|
||||
const char *env_string;
|
||||
|
||||
env_string = g_getenv ("COGL_DEBUG");
|
||||
if (env_string != NULL)
|
||||
{
|
||||
_cogl_parse_debug_string (env_string,
|
||||
TRUE /* enable the flags */,
|
||||
FALSE /* don't ignore help */);
|
||||
env_string = NULL;
|
||||
}
|
||||
#endif /* COGL_ENABLE_DEBUG */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GOptionGroup *
|
||||
cogl_get_option_group (void)
|
||||
{
|
||||
GOptionGroup *group;
|
||||
|
||||
group = g_option_group_new ("cogl",
|
||||
_("Cogl Options"),
|
||||
_("Show Cogl options"),
|
||||
NULL, NULL);
|
||||
|
||||
g_option_group_set_parse_hooks (group, pre_parse_hook, NULL);
|
||||
g_option_group_add_entries (group, cogl_args);
|
||||
g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
|
||||
|
||||
return group;
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_DEBUG_H__
|
||||
#define __COGL_DEBUG_H__
|
||||
|
||||
#include "cogl-profile.h"
|
||||
#include "cogl-flags.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
COGL_DEBUG_SLICING,
|
||||
COGL_DEBUG_OFFSCREEN,
|
||||
COGL_DEBUG_DRAW,
|
||||
COGL_DEBUG_PANGO,
|
||||
COGL_DEBUG_RECTANGLES,
|
||||
COGL_DEBUG_HANDLE,
|
||||
COGL_DEBUG_BLEND_STRINGS,
|
||||
COGL_DEBUG_DISABLE_BATCHING,
|
||||
COGL_DEBUG_DISABLE_VBOS,
|
||||
COGL_DEBUG_DISABLE_PBOS,
|
||||
COGL_DEBUG_JOURNAL,
|
||||
COGL_DEBUG_BATCHING,
|
||||
COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM,
|
||||
COGL_DEBUG_MATRICES,
|
||||
COGL_DEBUG_ATLAS,
|
||||
COGL_DEBUG_DUMP_ATLAS_IMAGE,
|
||||
COGL_DEBUG_DISABLE_ATLAS,
|
||||
COGL_DEBUG_DISABLE_SHARED_ATLAS,
|
||||
COGL_DEBUG_OPENGL,
|
||||
COGL_DEBUG_DISABLE_TEXTURING,
|
||||
COGL_DEBUG_DISABLE_ARBFP,
|
||||
COGL_DEBUG_DISABLE_FIXED,
|
||||
COGL_DEBUG_DISABLE_GLSL,
|
||||
COGL_DEBUG_SHOW_SOURCE,
|
||||
COGL_DEBUG_DISABLE_BLENDING,
|
||||
COGL_DEBUG_TEXTURE_PIXMAP,
|
||||
COGL_DEBUG_BITMAP,
|
||||
COGL_DEBUG_DISABLE_NPOT_TEXTURES,
|
||||
COGL_DEBUG_WIREFRAME,
|
||||
COGL_DEBUG_DISABLE_SOFTWARE_CLIP,
|
||||
COGL_DEBUG_DISABLE_PROGRAM_CACHES,
|
||||
COGL_DEBUG_DISABLE_FAST_READ_PIXEL,
|
||||
COGL_DEBUG_CLIPPING,
|
||||
COGL_DEBUG_WINSYS,
|
||||
|
||||
COGL_DEBUG_N_FLAGS
|
||||
} CoglDebugFlags;
|
||||
|
||||
#ifdef COGL_ENABLE_DEBUG
|
||||
|
||||
#define COGL_DEBUG_N_INTS COGL_FLAGS_N_INTS_FOR_SIZE (COGL_DEBUG_N_FLAGS)
|
||||
|
||||
extern unsigned int _cogl_debug_flags[COGL_DEBUG_N_INTS];
|
||||
|
||||
#define COGL_DEBUG_ENABLED(flag) \
|
||||
COGL_FLAGS_GET (_cogl_debug_flags, flag)
|
||||
|
||||
#define COGL_DEBUG_SET_FLAG(flag) \
|
||||
COGL_FLAGS_SET (_cogl_debug_flags, flag, TRUE)
|
||||
|
||||
#define COGL_DEBUG_CLEAR_FLAG(flag) \
|
||||
COGL_FLAGS_SET (_cogl_debug_flags, flag, FALSE)
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define COGL_NOTE(type,x,a...) G_STMT_START { \
|
||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_##type))) { \
|
||||
_cogl_profile_trace_message ("[" #type "] " G_STRLOC " & " x, ##a); \
|
||||
} } G_STMT_END
|
||||
|
||||
#else
|
||||
#define COGL_NOTE(type,...) G_STMT_START { \
|
||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_##type)) { \
|
||||
char *_fmt = g_strdup_printf (__VA_ARGS__); \
|
||||
_cogl_profile_trace_message ("[" #type "] " G_STRLOC " & %s", _fmt);\
|
||||
g_free (_fmt); \
|
||||
} } G_STMT_END
|
||||
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
#else /* !COGL_ENABLE_DEBUG */
|
||||
|
||||
#define COGL_NOTE(type,...) G_STMT_START {} G_STMT_END
|
||||
|
||||
#define COGL_DEBUG_ENABLED(flag) FALSE
|
||||
|
||||
#define COGL_DEBUG_SET_FLAG(flag) \
|
||||
G_STMT_START { } G_STMT_END
|
||||
|
||||
#define COGL_DEBUG_CLEAR_FLAG(flag) \
|
||||
G_STMT_START { } G_STMT_END
|
||||
|
||||
#endif /* COGL_ENABLE_DEBUG */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_DEBUG_H__ */
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_DEFINES_H__
|
||||
#define __COGL_DEFINES_H__
|
||||
|
||||
#include <glib.h>
|
||||
@COGL_GL_HEADER_INCLUDES@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@COGL_DEFINES@
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef COGL_DEPRECATED_H
|
||||
|
||||
#define cogl_color cogl_color_REPLACED_BY_cogl_set_source_color
|
||||
#define cogl_enable_depth_test cogl_enable_depth_test_RENAMED_TO_cogl_set_depth_test_enabled
|
||||
#define cogl_enable_backface_culling cogl_enable_backface_culling_RENAMED_TO_cogl_set_backface_culling_enabled
|
||||
|
||||
#define cogl_texture_rectangle cogl_texture_rectangle_REPLACE_BY_cogl_set_source_texture_AND_cogl_rectangle_with_texture_coords
|
||||
|
||||
#define cogl_texture_multiple_rectangles cogl_texture_multiple_rectangles_REPLACED_BY_cogl_set_source_texture_AND_cogl_rectangles_with_texture_coords
|
||||
|
||||
#define cogl_texture_polygon cogl_texture_polygon_REPLACED_BY_cogl_set_source_texture_AND_cogl_polygon
|
||||
|
||||
#endif
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_DISPLAY_GLX_PRIVATE_H
|
||||
#define __COGL_DISPLAY_GLX_PRIVATE_H
|
||||
|
||||
#include "cogl-object-private.h"
|
||||
#include "cogl-display-xlib-private.h"
|
||||
|
||||
typedef struct _CoglGLXCachedConfig
|
||||
{
|
||||
/* This will be -1 if there is no cached config in this slot */
|
||||
int depth;
|
||||
gboolean found;
|
||||
GLXFBConfig fb_config;
|
||||
gboolean can_mipmap;
|
||||
} CoglGLXCachedConfig;
|
||||
|
||||
#define COGL_GLX_N_CACHED_CONFIGS 3
|
||||
|
||||
typedef struct _CoglDisplayGLX
|
||||
{
|
||||
CoglDisplayXlib _parent;
|
||||
|
||||
CoglGLXCachedConfig glx_cached_configs[COGL_GLX_N_CACHED_CONFIGS];
|
||||
|
||||
gboolean found_fbconfig;
|
||||
gboolean fbconfig_has_rgba_visual;
|
||||
GLXFBConfig fbconfig;
|
||||
|
||||
/* Single context for all wins */
|
||||
GLXContext glx_context;
|
||||
GLXWindow dummy_glxwin;
|
||||
} CoglDisplayGLX;
|
||||
|
||||
#endif /* __COGL_DISPLAY_GLX_PRIVATE_H */
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_DISPLAY_PRIVATE_H
|
||||
#define __COGL_DISPLAY_PRIVATE_H
|
||||
|
||||
#include "cogl-object-private.h"
|
||||
#include "cogl-display.h"
|
||||
#include "cogl-renderer.h"
|
||||
#include "cogl-onscreen-template.h"
|
||||
|
||||
struct _CoglDisplay
|
||||
{
|
||||
CoglObject _parent;
|
||||
|
||||
gboolean setup;
|
||||
CoglRenderer *renderer;
|
||||
CoglOnscreenTemplate *onscreen_template;
|
||||
|
||||
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
|
||||
struct gdl_plane *gdl_plane;
|
||||
#endif
|
||||
|
||||
void *winsys;
|
||||
};
|
||||
|
||||
#endif /* __COGL_DISPLAY_PRIVATE_H */
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_DISPLAY_XLIB_PRIVATE_H
|
||||
#define __COGL_DISPLAY_XLIB_PRIVATE_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
typedef struct _CoglDisplayXlib
|
||||
{
|
||||
Window dummy_xwin;
|
||||
} CoglDisplayXlib;
|
||||
|
||||
#endif /* __COGL_DISPLAY_XLIB_PRIVATE_H */
|
@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-object.h"
|
||||
|
||||
#include "cogl-display-private.h"
|
||||
#include "cogl-renderer-private.h"
|
||||
#include "cogl-winsys-private.h"
|
||||
|
||||
static void _cogl_display_free (CoglDisplay *display);
|
||||
|
||||
COGL_OBJECT_DEFINE (Display, display);
|
||||
|
||||
GQuark
|
||||
cogl_display_error_quark (void)
|
||||
{
|
||||
return g_quark_from_static_string ("cogl-display-error-quark");
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_display_free (CoglDisplay *display)
|
||||
{
|
||||
if (display->renderer)
|
||||
{
|
||||
cogl_object_unref (display->renderer);
|
||||
display->renderer = NULL;
|
||||
}
|
||||
|
||||
if (display->onscreen_template)
|
||||
{
|
||||
cogl_object_unref (display->onscreen_template);
|
||||
display->onscreen_template = NULL;
|
||||
}
|
||||
|
||||
g_slice_free (CoglDisplay, display);
|
||||
}
|
||||
|
||||
CoglDisplay *
|
||||
cogl_display_new (CoglRenderer *renderer,
|
||||
CoglOnscreenTemplate *onscreen_template)
|
||||
{
|
||||
CoglDisplay *display = g_slice_new0 (CoglDisplay);
|
||||
GError *error = NULL;
|
||||
|
||||
display->renderer = renderer;
|
||||
if (renderer)
|
||||
cogl_object_ref (renderer);
|
||||
else
|
||||
display->renderer = cogl_renderer_new ();
|
||||
|
||||
if (!cogl_renderer_connect (display->renderer, &error))
|
||||
{
|
||||
g_warning ("Failed to connect renderer: %s\n", error->message);
|
||||
g_error_free (error);
|
||||
g_object_unref (display->renderer);
|
||||
g_slice_free (CoglDisplay, display);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
display->onscreen_template = onscreen_template;
|
||||
if (onscreen_template)
|
||||
cogl_object_ref (onscreen_template);
|
||||
|
||||
display->setup = FALSE;
|
||||
|
||||
return _cogl_display_object_new (display);
|
||||
}
|
||||
|
||||
static const CoglWinsysVtable *
|
||||
_cogl_display_get_winsys (CoglDisplay *display)
|
||||
{
|
||||
return display->renderer->winsys_vtable;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_display_setup (CoglDisplay *display,
|
||||
GError **error)
|
||||
{
|
||||
#ifdef COGL_HAS_FULL_WINSYS
|
||||
const CoglWinsysVtable *winsys;
|
||||
#endif
|
||||
|
||||
if (display->setup)
|
||||
return TRUE;
|
||||
|
||||
#ifdef COGL_HAS_FULL_WINSYS
|
||||
winsys = _cogl_display_get_winsys (display);
|
||||
if (!winsys->display_setup (display, error))
|
||||
return FALSE;
|
||||
#endif
|
||||
|
||||
display->setup = TRUE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
|
||||
void
|
||||
cogl_gdl_display_set_plane (CoglDisplay *display,
|
||||
struct gdl_plane *plane)
|
||||
{
|
||||
g_return_if_fail (display->setup == FALSE);
|
||||
|
||||
display->gdl_plane = plane;
|
||||
}
|
||||
#endif
|
||||
|
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_DISPLAY_H__
|
||||
#define __COGL_DISPLAY_H__
|
||||
|
||||
#include <cogl/cogl-renderer.h>
|
||||
#include <cogl/cogl-onscreen-template.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
|
||||
#include <@CLUTTER_CEX100_LIBGDL_PREFIX@libgdl.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* SECTION:cogl-display
|
||||
* @short_description: Represents a display pipeline
|
||||
*
|
||||
* TODO: We still need to decide if we really need this object or if
|
||||
* it's enough to just have the CoglSwapChain CoglOnscreenTemplate
|
||||
* objects.
|
||||
*
|
||||
* The basic intention is for this object to let the application
|
||||
* specify its display preferences before creating a context, and
|
||||
* there are a few different aspects to this...
|
||||
*
|
||||
* Firstly there is the physical display pipeline that is currently
|
||||
* being used including the digital to analogue conversion hardware
|
||||
* and the screen the user sees. Although we don't have a plan to
|
||||
* expose all the advanced features of arbitrary display hardware with
|
||||
* a Cogl API, some backends may want to expose limited control over
|
||||
* this hardware via Cogl and simpler features like providing a list
|
||||
* of modes to choose from in a UI could be nice too.
|
||||
*
|
||||
* Another aspect is that the display configuration may be tightly
|
||||
* related to how onscreen framebuffers should be configured. In fact
|
||||
* one of the early rationals for this object was to let us handle
|
||||
* GLX's requirement that framebuffers must be "compatible" with the
|
||||
* fbconfig associated with the current context meaning we have to
|
||||
* force the user to describe how they would like to create their
|
||||
* onscreen windows before we can choose a suitable fbconfig and
|
||||
* create a GLContext.
|
||||
*
|
||||
* TODO: continue this thought process and come to a decision...
|
||||
*/
|
||||
|
||||
typedef struct _CoglDisplay CoglDisplay;
|
||||
|
||||
#define COGL_DISPLAY(OBJECT) ((CoglDisplay *)OBJECT)
|
||||
|
||||
#define cogl_display_new cogl_display_new_EXP
|
||||
CoglDisplay *
|
||||
cogl_display_new (CoglRenderer *renderer,
|
||||
CoglOnscreenTemplate *onscreen_template);
|
||||
|
||||
#define cogl_display_setup cogl_display_setup_EXP
|
||||
gboolean
|
||||
cogl_display_setup (CoglDisplay *display,
|
||||
GError **error);
|
||||
|
||||
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
|
||||
#define cogl_gdl_display_set_plane \
|
||||
cogl_gdl_display_set_plane_EXP
|
||||
void
|
||||
cogl_gdl_display_set_plane (CoglDisplay *display,
|
||||
struct gdl_plane *plane);
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_DISPLAY_H__ */
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*** BEGIN file-header ***/
|
||||
#include "cogl-enum-types.h"
|
||||
#include "cogl.h"
|
||||
/*** END file-header ***/
|
||||
|
||||
/*** BEGIN file-production ***/
|
||||
|
||||
/* enumerations from "@filename@" */
|
||||
#include "@filename@"
|
||||
|
||||
/*** END file-production ***/
|
||||
|
||||
/*** BEGIN value-header ***/
|
||||
GType
|
||||
@enum_name@_get_type (void)
|
||||
{
|
||||
static volatile gsize g_enum_type_id__volatile = 0;
|
||||
|
||||
if (g_once_init_enter (&g_enum_type_id__volatile))
|
||||
{
|
||||
static const G@Type@Value values[] = {
|
||||
/*** END value-header ***/
|
||||
|
||||
/*** BEGIN value-production ***/
|
||||
{ @VALUENAME@, "@VALUENAME@", "@valuenick@" },
|
||||
/*** END value-production ***/
|
||||
|
||||
/*** BEGIN value-tail ***/
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
GType g_enum_type_id;
|
||||
|
||||
g_enum_type_id =
|
||||
g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
|
||||
|
||||
g_once_init_leave (&g_enum_type_id__volatile, g_enum_type_id);
|
||||
}
|
||||
|
||||
return g_enum_type_id__volatile;
|
||||
}
|
||||
/*** END value-tail ***/
|
@ -1,25 +0,0 @@
|
||||
/*** BEGIN file-header ***/
|
||||
#ifndef __COGL_ENUM_TYPES_H__
|
||||
#define __COGL_ENUM_TYPES_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*** END file-header ***/
|
||||
|
||||
/*** BEGIN file-production ***/
|
||||
/* enumerations from "@filename@" */
|
||||
/*** END file-production ***/
|
||||
|
||||
/*** BEGIN file-tail ***/
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* !__CLUTTER_ENUM_TYPES_H__ */
|
||||
/*** END file-tail ***/
|
||||
|
||||
/*** BEGIN value-header ***/
|
||||
GType @enum_name@_get_type (void) G_GNUC_CONST;
|
||||
#define COGL_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
|
||||
|
||||
/*** END value-header ***/
|
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-context-private.h"
|
||||
|
||||
#include "cogl-feature-private.h"
|
||||
|
||||
gboolean
|
||||
_cogl_feature_check (const char *driver_prefix,
|
||||
const CoglFeatureData *data,
|
||||
unsigned int gl_major,
|
||||
unsigned int gl_minor,
|
||||
const char *extensions_string,
|
||||
void *function_table)
|
||||
|
||||
{
|
||||
const char *suffix = NULL;
|
||||
int func_num;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
/* First check whether the functions should be directly provided by
|
||||
GL */
|
||||
if (COGL_CHECK_GL_VERSION (gl_major, gl_minor,
|
||||
data->min_gl_major, data->min_gl_minor))
|
||||
suffix = "";
|
||||
else
|
||||
{
|
||||
/* Otherwise try all of the extensions */
|
||||
const char *namespace, *namespace_suffix;
|
||||
unsigned int namespace_len;
|
||||
|
||||
for (namespace = data->namespaces;
|
||||
*namespace;
|
||||
namespace += strlen (namespace) + 1)
|
||||
{
|
||||
const char *extension;
|
||||
GString *full_extension_name = g_string_new ("");
|
||||
|
||||
/* If the namespace part contains a ':' then the suffix for
|
||||
the function names is different from the name space */
|
||||
if ((namespace_suffix = strchr (namespace, ':')))
|
||||
{
|
||||
namespace_len = namespace_suffix - namespace;
|
||||
namespace_suffix++;
|
||||
}
|
||||
else
|
||||
{
|
||||
namespace_len = strlen (namespace);
|
||||
namespace_suffix = namespace;
|
||||
}
|
||||
|
||||
for (extension = data->extension_names;
|
||||
*extension;
|
||||
extension += strlen (extension) + 1)
|
||||
{
|
||||
g_string_assign (full_extension_name, driver_prefix);
|
||||
g_string_append_c (full_extension_name, '_');
|
||||
g_string_append_len (full_extension_name,
|
||||
namespace, namespace_len);
|
||||
g_string_append_c (full_extension_name, '_');
|
||||
g_string_append (full_extension_name, extension);
|
||||
if (!_cogl_check_extension (full_extension_name->str,
|
||||
extensions_string))
|
||||
break;
|
||||
}
|
||||
|
||||
g_string_free (full_extension_name, TRUE);
|
||||
|
||||
/* If we found all of the extensions with this namespace
|
||||
then use it as the suffix */
|
||||
if (*extension == '\0')
|
||||
{
|
||||
suffix = namespace_suffix;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If we couldn't find anything that provides the functions then
|
||||
give up */
|
||||
if (suffix == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* Try to get all of the entry points */
|
||||
for (func_num = 0; data->functions[func_num].name; func_num++)
|
||||
{
|
||||
void *func;
|
||||
char *full_function_name;
|
||||
|
||||
full_function_name = g_strconcat (data->functions[func_num].name,
|
||||
suffix, NULL);
|
||||
func = cogl_get_proc_address (full_function_name);
|
||||
g_free (full_function_name);
|
||||
|
||||
if (func == NULL)
|
||||
break;
|
||||
|
||||
/* Set the function pointer in the context */
|
||||
*(void **) ((guint8 *) function_table +
|
||||
data->functions[func_num].pointer_offset) = func;
|
||||
}
|
||||
|
||||
/* If one of the functions wasn't found then we should set all of
|
||||
the function pointers back to NULL so that the rest of Cogl can
|
||||
safely do feature testing by just looking at the function
|
||||
pointers */
|
||||
if (data->functions[func_num].name)
|
||||
{
|
||||
while (func_num-- > 0)
|
||||
*(void **) ((guint8 *) ctx +
|
||||
data->functions[func_num].pointer_offset) = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
return TRUE;
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_FEATURE_PRIVATE_H
|
||||
#define __COGL_FEATURE_PRIVATE_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl-internal.h"
|
||||
|
||||
#define COGL_CHECK_GL_VERSION(driver_major, driver_minor, \
|
||||
target_major, target_minor) \
|
||||
((driver_major) > (target_major) || \
|
||||
((driver_major) == (target_major) && (driver_minor) >= (target_minor)))
|
||||
|
||||
typedef struct _CoglFeatureFunction CoglFeatureFunction;
|
||||
|
||||
struct _CoglFeatureFunction
|
||||
{
|
||||
/* The name of the function without the "EXT" or "ARB" suffix */
|
||||
const char *name;
|
||||
/* The offset in the context of where to store the function pointer */
|
||||
unsigned int pointer_offset;
|
||||
};
|
||||
|
||||
typedef struct _CoglFeatureData CoglFeatureData;
|
||||
|
||||
struct _CoglFeatureData
|
||||
{
|
||||
/* A minimum GL version which the functions should be defined in
|
||||
without needing an extension. Set to 255,255 if it's only
|
||||
provided in an extension */
|
||||
guint8 min_gl_major, min_gl_minor;
|
||||
/* \0 separated list of namespaces to try. Eg "EXT\0ARB\0" */
|
||||
const char *namespaces;
|
||||
/* \0 separated list of required extension names without the GL_EXT
|
||||
or GL_ARB prefix. All of the extensions must be available for the
|
||||
feature to be considered available. If the suffix for an
|
||||
extension is different from the namespace, you can specify it
|
||||
with a ':' after the namespace */
|
||||
const char *extension_names;
|
||||
/* A set of feature flags to enable if the extension is available */
|
||||
CoglFeatureFlags feature_flags;
|
||||
/* FIXME: This is now unused */
|
||||
int padding_feature_flags_private;
|
||||
/* An optional corresponding winsys feature. */
|
||||
CoglWinsysFeature winsys_feature;
|
||||
/* A list of functions required for this feature. Terminated with a
|
||||
NULL name */
|
||||
const CoglFeatureFunction *functions;
|
||||
};
|
||||
|
||||
gboolean
|
||||
_cogl_feature_check (const char *driver_prefix,
|
||||
const CoglFeatureData *data,
|
||||
unsigned int gl_major,
|
||||
unsigned int gl_minor,
|
||||
const char *extensions_string,
|
||||
void *function_table);
|
||||
|
||||
#endif /* __COGL_FEATURE_PRIVATE_H */
|
@ -1,950 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#define G_IMPLEMENT_INLINES
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl-fixed.h"
|
||||
|
||||
/* pre-computed sin table for 1st quadrant
|
||||
*
|
||||
* Currently contains 257 entries.
|
||||
*
|
||||
* The current maximum absolute error is about 1.9e-0.5
|
||||
* and is greatest around pi/2 where the second derivative
|
||||
* of sin(x) is greatest. If greater accuracy is needed,
|
||||
* modestly increasing the table size, or maybe using
|
||||
* quadratic interpolation would drop the interpolation
|
||||
* error below the precision limits of CoglFixed.
|
||||
*/
|
||||
static const CoglFixed sin_tbl[] =
|
||||
{
|
||||
0x00000000L, 0x00000192L, 0x00000324L, 0x000004B6L,
|
||||
0x00000648L, 0x000007DAL, 0x0000096CL, 0x00000AFEL,
|
||||
0x00000C90L, 0x00000E21L, 0x00000FB3L, 0x00001144L,
|
||||
0x000012D5L, 0x00001466L, 0x000015F7L, 0x00001787L,
|
||||
0x00001918L, 0x00001AA8L, 0x00001C38L, 0x00001DC7L,
|
||||
0x00001F56L, 0x000020E5L, 0x00002274L, 0x00002402L,
|
||||
0x00002590L, 0x0000271EL, 0x000028ABL, 0x00002A38L,
|
||||
0x00002BC4L, 0x00002D50L, 0x00002EDCL, 0x00003067L,
|
||||
0x000031F1L, 0x0000337CL, 0x00003505L, 0x0000368EL,
|
||||
0x00003817L, 0x0000399FL, 0x00003B27L, 0x00003CAEL,
|
||||
0x00003E34L, 0x00003FBAL, 0x0000413FL, 0x000042C3L,
|
||||
0x00004447L, 0x000045CBL, 0x0000474DL, 0x000048CFL,
|
||||
0x00004A50L, 0x00004BD1L, 0x00004D50L, 0x00004ECFL,
|
||||
0x0000504DL, 0x000051CBL, 0x00005348L, 0x000054C3L,
|
||||
0x0000563EL, 0x000057B9L, 0x00005932L, 0x00005AAAL,
|
||||
0x00005C22L, 0x00005D99L, 0x00005F0FL, 0x00006084L,
|
||||
0x000061F8L, 0x0000636BL, 0x000064DDL, 0x0000664EL,
|
||||
0x000067BEL, 0x0000692DL, 0x00006A9BL, 0x00006C08L,
|
||||
0x00006D74L, 0x00006EDFL, 0x00007049L, 0x000071B2L,
|
||||
0x0000731AL, 0x00007480L, 0x000075E6L, 0x0000774AL,
|
||||
0x000078ADL, 0x00007A10L, 0x00007B70L, 0x00007CD0L,
|
||||
0x00007E2FL, 0x00007F8CL, 0x000080E8L, 0x00008243L,
|
||||
0x0000839CL, 0x000084F5L, 0x0000864CL, 0x000087A1L,
|
||||
0x000088F6L, 0x00008A49L, 0x00008B9AL, 0x00008CEBL,
|
||||
0x00008E3AL, 0x00008F88L, 0x000090D4L, 0x0000921FL,
|
||||
0x00009368L, 0x000094B0L, 0x000095F7L, 0x0000973CL,
|
||||
0x00009880L, 0x000099C2L, 0x00009B03L, 0x00009C42L,
|
||||
0x00009D80L, 0x00009EBCL, 0x00009FF7L, 0x0000A130L,
|
||||
0x0000A268L, 0x0000A39EL, 0x0000A4D2L, 0x0000A605L,
|
||||
0x0000A736L, 0x0000A866L, 0x0000A994L, 0x0000AAC1L,
|
||||
0x0000ABEBL, 0x0000AD14L, 0x0000AE3CL, 0x0000AF62L,
|
||||
0x0000B086L, 0x0000B1A8L, 0x0000B2C9L, 0x0000B3E8L,
|
||||
0x0000B505L, 0x0000B620L, 0x0000B73AL, 0x0000B852L,
|
||||
0x0000B968L, 0x0000BA7DL, 0x0000BB8FL, 0x0000BCA0L,
|
||||
0x0000BDAFL, 0x0000BEBCL, 0x0000BFC7L, 0x0000C0D1L,
|
||||
0x0000C1D8L, 0x0000C2DEL, 0x0000C3E2L, 0x0000C4E4L,
|
||||
0x0000C5E4L, 0x0000C6E2L, 0x0000C7DEL, 0x0000C8D9L,
|
||||
0x0000C9D1L, 0x0000CAC7L, 0x0000CBBCL, 0x0000CCAEL,
|
||||
0x0000CD9FL, 0x0000CE8EL, 0x0000CF7AL, 0x0000D065L,
|
||||
0x0000D14DL, 0x0000D234L, 0x0000D318L, 0x0000D3FBL,
|
||||
0x0000D4DBL, 0x0000D5BAL, 0x0000D696L, 0x0000D770L,
|
||||
0x0000D848L, 0x0000D91EL, 0x0000D9F2L, 0x0000DAC4L,
|
||||
0x0000DB94L, 0x0000DC62L, 0x0000DD2DL, 0x0000DDF7L,
|
||||
0x0000DEBEL, 0x0000DF83L, 0x0000E046L, 0x0000E107L,
|
||||
0x0000E1C6L, 0x0000E282L, 0x0000E33CL, 0x0000E3F4L,
|
||||
0x0000E4AAL, 0x0000E55EL, 0x0000E610L, 0x0000E6BFL,
|
||||
0x0000E76CL, 0x0000E817L, 0x0000E8BFL, 0x0000E966L,
|
||||
0x0000EA0AL, 0x0000EAABL, 0x0000EB4BL, 0x0000EBE8L,
|
||||
0x0000EC83L, 0x0000ED1CL, 0x0000EDB3L, 0x0000EE47L,
|
||||
0x0000EED9L, 0x0000EF68L, 0x0000EFF5L, 0x0000F080L,
|
||||
0x0000F109L, 0x0000F18FL, 0x0000F213L, 0x0000F295L,
|
||||
0x0000F314L, 0x0000F391L, 0x0000F40CL, 0x0000F484L,
|
||||
0x0000F4FAL, 0x0000F56EL, 0x0000F5DFL, 0x0000F64EL,
|
||||
0x0000F6BAL, 0x0000F724L, 0x0000F78CL, 0x0000F7F1L,
|
||||
0x0000F854L, 0x0000F8B4L, 0x0000F913L, 0x0000F96EL,
|
||||
0x0000F9C8L, 0x0000FA1FL, 0x0000FA73L, 0x0000FAC5L,
|
||||
0x0000FB15L, 0x0000FB62L, 0x0000FBADL, 0x0000FBF5L,
|
||||
0x0000FC3BL, 0x0000FC7FL, 0x0000FCC0L, 0x0000FCFEL,
|
||||
0x0000FD3BL, 0x0000FD74L, 0x0000FDACL, 0x0000FDE1L,
|
||||
0x0000FE13L, 0x0000FE43L, 0x0000FE71L, 0x0000FE9CL,
|
||||
0x0000FEC4L, 0x0000FEEBL, 0x0000FF0EL, 0x0000FF30L,
|
||||
0x0000FF4EL, 0x0000FF6BL, 0x0000FF85L, 0x0000FF9CL,
|
||||
0x0000FFB1L, 0x0000FFC4L, 0x0000FFD4L, 0x0000FFE1L,
|
||||
0x0000FFECL, 0x0000FFF5L, 0x0000FFFBL, 0x0000FFFFL,
|
||||
0x00010000L,
|
||||
};
|
||||
|
||||
/* pre-computed tan table for 1st quadrant */
|
||||
static const CoglFixed tan_tbl[] =
|
||||
{
|
||||
0x00000000L, 0x00000192L, 0x00000324L, 0x000004b7L,
|
||||
0x00000649L, 0x000007dbL, 0x0000096eL, 0x00000b01L,
|
||||
0x00000c94L, 0x00000e27L, 0x00000fbaL, 0x0000114eL,
|
||||
0x000012e2L, 0x00001477L, 0x0000160cL, 0x000017a1L,
|
||||
0x00001937L, 0x00001acdL, 0x00001c64L, 0x00001dfbL,
|
||||
0x00001f93L, 0x0000212cL, 0x000022c5L, 0x0000245fL,
|
||||
0x000025f9L, 0x00002795L, 0x00002931L, 0x00002aceL,
|
||||
0x00002c6cL, 0x00002e0aL, 0x00002faaL, 0x0000314aL,
|
||||
0x000032ecL, 0x0000348eL, 0x00003632L, 0x000037d7L,
|
||||
0x0000397dL, 0x00003b24L, 0x00003cccL, 0x00003e75L,
|
||||
0x00004020L, 0x000041ccL, 0x00004379L, 0x00004528L,
|
||||
0x000046d8L, 0x0000488aL, 0x00004a3dL, 0x00004bf2L,
|
||||
0x00004da8L, 0x00004f60L, 0x0000511aL, 0x000052d5L,
|
||||
0x00005492L, 0x00005651L, 0x00005812L, 0x000059d5L,
|
||||
0x00005b99L, 0x00005d60L, 0x00005f28L, 0x000060f3L,
|
||||
0x000062c0L, 0x0000648fL, 0x00006660L, 0x00006834L,
|
||||
0x00006a0aL, 0x00006be2L, 0x00006dbdL, 0x00006f9aL,
|
||||
0x0000717aL, 0x0000735dL, 0x00007542L, 0x0000772aL,
|
||||
0x00007914L, 0x00007b02L, 0x00007cf2L, 0x00007ee6L,
|
||||
0x000080dcL, 0x000082d6L, 0x000084d2L, 0x000086d2L,
|
||||
0x000088d6L, 0x00008adcL, 0x00008ce7L, 0x00008ef4L,
|
||||
0x00009106L, 0x0000931bL, 0x00009534L, 0x00009750L,
|
||||
0x00009971L, 0x00009b95L, 0x00009dbeL, 0x00009febL,
|
||||
0x0000a21cL, 0x0000a452L, 0x0000a68cL, 0x0000a8caL,
|
||||
0x0000ab0eL, 0x0000ad56L, 0x0000afa3L, 0x0000b1f5L,
|
||||
0x0000b44cL, 0x0000b6a8L, 0x0000b909L, 0x0000bb70L,
|
||||
0x0000bdddL, 0x0000c04fL, 0x0000c2c7L, 0x0000c545L,
|
||||
0x0000c7c9L, 0x0000ca53L, 0x0000cce3L, 0x0000cf7aL,
|
||||
0x0000d218L, 0x0000d4bcL, 0x0000d768L, 0x0000da1aL,
|
||||
0x0000dcd4L, 0x0000df95L, 0x0000e25eL, 0x0000e52eL,
|
||||
0x0000e806L, 0x0000eae7L, 0x0000edd0L, 0x0000f0c1L,
|
||||
0x0000f3bbL, 0x0000f6bfL, 0x0000f9cbL, 0x0000fce1L,
|
||||
0x00010000L, 0x00010329L, 0x0001065dL, 0x0001099aL,
|
||||
0x00010ce3L, 0x00011036L, 0x00011394L, 0x000116feL,
|
||||
0x00011a74L, 0x00011df6L, 0x00012184L, 0x0001251fL,
|
||||
0x000128c6L, 0x00012c7cL, 0x0001303fL, 0x00013410L,
|
||||
0x000137f0L, 0x00013bdfL, 0x00013fddL, 0x000143ebL,
|
||||
0x00014809L, 0x00014c37L, 0x00015077L, 0x000154c9L,
|
||||
0x0001592dL, 0x00015da4L, 0x0001622eL, 0x000166ccL,
|
||||
0x00016b7eL, 0x00017045L, 0x00017523L, 0x00017a17L,
|
||||
0x00017f22L, 0x00018444L, 0x00018980L, 0x00018ed5L,
|
||||
0x00019445L, 0x000199cfL, 0x00019f76L, 0x0001a53aL,
|
||||
0x0001ab1cL, 0x0001b11dL, 0x0001b73fL, 0x0001bd82L,
|
||||
0x0001c3e7L, 0x0001ca71L, 0x0001d11fL, 0x0001d7f4L,
|
||||
0x0001def1L, 0x0001e618L, 0x0001ed6aL, 0x0001f4e8L,
|
||||
0x0001fc96L, 0x00020473L, 0x00020c84L, 0x000214c9L,
|
||||
0x00021d44L, 0x000225f9L, 0x00022ee9L, 0x00023818L,
|
||||
0x00024187L, 0x00024b3aL, 0x00025534L, 0x00025f78L,
|
||||
0x00026a0aL, 0x000274edL, 0x00028026L, 0x00028bb8L,
|
||||
0x000297a8L, 0x0002a3fbL, 0x0002b0b5L, 0x0002bdddL,
|
||||
0x0002cb79L, 0x0002d98eL, 0x0002e823L, 0x0002f740L,
|
||||
0x000306ecL, 0x00031730L, 0x00032816L, 0x000339a6L,
|
||||
0x00034bebL, 0x00035ef2L, 0x000372c6L, 0x00038776L,
|
||||
0x00039d11L, 0x0003b3a6L, 0x0003cb48L, 0x0003e40aL,
|
||||
0x0003fe02L, 0x00041949L, 0x000435f7L, 0x0004542bL,
|
||||
0x00047405L, 0x000495a9L, 0x0004b940L, 0x0004def6L,
|
||||
0x00050700L, 0x00053196L, 0x00055ef9L, 0x00058f75L,
|
||||
0x0005c35dL, 0x0005fb14L, 0x00063709L, 0x000677c0L,
|
||||
0x0006bdd0L, 0x000709ecL, 0x00075ce6L, 0x0007b7bbL,
|
||||
0x00081b98L, 0x000889e9L, 0x0009046eL, 0x00098d4dL,
|
||||
0x000a2736L, 0x000ad593L, 0x000b9cc6L, 0x000c828aL,
|
||||
0x000d8e82L, 0x000ecb1bL, 0x001046eaL, 0x00121703L,
|
||||
0x00145b00L, 0x0017448dL, 0x001b2672L, 0x002095afL,
|
||||
0x0028bc49L, 0x0036519aL, 0x00517bb6L, 0x00a2f8fdL,
|
||||
0x46d3eab2L,
|
||||
};
|
||||
|
||||
/* 257-value table of atan.
|
||||
*
|
||||
* atan_tbl[0] is atan(0.0) and atan_tbl[256] is atan(1).
|
||||
* The angles are radians in CoglFixed truncated to 16-bit (they're
|
||||
* all less than one)
|
||||
*/
|
||||
static const guint16 atan_tbl[] =
|
||||
{
|
||||
0x0000, 0x00FF, 0x01FF, 0x02FF, 0x03FF, 0x04FF, 0x05FF, 0x06FF,
|
||||
0x07FF, 0x08FF, 0x09FE, 0x0AFE, 0x0BFD, 0x0CFD, 0x0DFC, 0x0EFB,
|
||||
0x0FFA, 0x10F9, 0x11F8, 0x12F7, 0x13F5, 0x14F3, 0x15F2, 0x16F0,
|
||||
0x17EE, 0x18EB, 0x19E9, 0x1AE6, 0x1BE3, 0x1CE0, 0x1DDD, 0x1ED9,
|
||||
0x1FD5, 0x20D1, 0x21CD, 0x22C8, 0x23C3, 0x24BE, 0x25B9, 0x26B3,
|
||||
0x27AD, 0x28A7, 0x29A1, 0x2A9A, 0x2B93, 0x2C8B, 0x2D83, 0x2E7B,
|
||||
0x2F72, 0x306A, 0x3160, 0x3257, 0x334D, 0x3442, 0x3538, 0x362D,
|
||||
0x3721, 0x3815, 0x3909, 0x39FC, 0x3AEF, 0x3BE2, 0x3CD4, 0x3DC5,
|
||||
0x3EB6, 0x3FA7, 0x4097, 0x4187, 0x4277, 0x4365, 0x4454, 0x4542,
|
||||
0x462F, 0x471C, 0x4809, 0x48F5, 0x49E0, 0x4ACB, 0x4BB6, 0x4CA0,
|
||||
0x4D89, 0x4E72, 0x4F5B, 0x5043, 0x512A, 0x5211, 0x52F7, 0x53DD,
|
||||
0x54C2, 0x55A7, 0x568B, 0x576F, 0x5852, 0x5934, 0x5A16, 0x5AF7,
|
||||
0x5BD8, 0x5CB8, 0x5D98, 0x5E77, 0x5F55, 0x6033, 0x6110, 0x61ED,
|
||||
0x62C9, 0x63A4, 0x647F, 0x6559, 0x6633, 0x670C, 0x67E4, 0x68BC,
|
||||
0x6993, 0x6A6A, 0x6B40, 0x6C15, 0x6CEA, 0x6DBE, 0x6E91, 0x6F64,
|
||||
0x7036, 0x7108, 0x71D9, 0x72A9, 0x7379, 0x7448, 0x7516, 0x75E4,
|
||||
0x76B1, 0x777E, 0x7849, 0x7915, 0x79DF, 0x7AA9, 0x7B72, 0x7C3B,
|
||||
0x7D03, 0x7DCA, 0x7E91, 0x7F57, 0x801C, 0x80E1, 0x81A5, 0x8269,
|
||||
0x832B, 0x83EE, 0x84AF, 0x8570, 0x8630, 0x86F0, 0x87AF, 0x886D,
|
||||
0x892A, 0x89E7, 0x8AA4, 0x8B5F, 0x8C1A, 0x8CD5, 0x8D8E, 0x8E47,
|
||||
0x8F00, 0x8FB8, 0x906F, 0x9125, 0x91DB, 0x9290, 0x9345, 0x93F9,
|
||||
0x94AC, 0x955F, 0x9611, 0x96C2, 0x9773, 0x9823, 0x98D2, 0x9981,
|
||||
0x9A2F, 0x9ADD, 0x9B89, 0x9C36, 0x9CE1, 0x9D8C, 0x9E37, 0x9EE0,
|
||||
0x9F89, 0xA032, 0xA0DA, 0xA181, 0xA228, 0xA2CE, 0xA373, 0xA418,
|
||||
0xA4BC, 0xA560, 0xA602, 0xA6A5, 0xA746, 0xA7E8, 0xA888, 0xA928,
|
||||
0xA9C7, 0xAA66, 0xAB04, 0xABA1, 0xAC3E, 0xACDB, 0xAD76, 0xAE11,
|
||||
0xAEAC, 0xAF46, 0xAFDF, 0xB078, 0xB110, 0xB1A7, 0xB23E, 0xB2D5,
|
||||
0xB36B, 0xB400, 0xB495, 0xB529, 0xB5BC, 0xB64F, 0xB6E2, 0xB773,
|
||||
0xB805, 0xB895, 0xB926, 0xB9B5, 0xBA44, 0xBAD3, 0xBB61, 0xBBEE,
|
||||
0xBC7B, 0xBD07, 0xBD93, 0xBE1E, 0xBEA9, 0xBF33, 0xBFBC, 0xC046,
|
||||
0xC0CE, 0xC156, 0xC1DD, 0xC264, 0xC2EB, 0xC371, 0xC3F6, 0xC47B,
|
||||
0xC4FF, 0xC583, 0xC606, 0xC689, 0xC70B, 0xC78D, 0xC80E, 0xC88F,
|
||||
0xC90F
|
||||
};
|
||||
|
||||
/* look up table for square root */
|
||||
static const CoglFixed sqrt_tbl[] =
|
||||
{
|
||||
0x00000000L, 0x00010000L, 0x00016A0AL, 0x0001BB68L,
|
||||
0x00020000L, 0x00023C6FL, 0x00027312L, 0x0002A550L,
|
||||
0x0002D414L, 0x00030000L, 0x0003298BL, 0x0003510EL,
|
||||
0x000376CFL, 0x00039B05L, 0x0003BDDDL, 0x0003DF7CL,
|
||||
0x00040000L, 0x00041F84L, 0x00043E1EL, 0x00045BE1L,
|
||||
0x000478DEL, 0x00049524L, 0x0004B0BFL, 0x0004CBBCL,
|
||||
0x0004E624L, 0x00050000L, 0x00051959L, 0x00053237L,
|
||||
0x00054AA0L, 0x0005629AL, 0x00057A2BL, 0x00059159L,
|
||||
0x0005A828L, 0x0005BE9CL, 0x0005D4B9L, 0x0005EA84L,
|
||||
0x00060000L, 0x00061530L, 0x00062A17L, 0x00063EB8L,
|
||||
0x00065316L, 0x00066733L, 0x00067B12L, 0x00068EB4L,
|
||||
0x0006A21DL, 0x0006B54DL, 0x0006C847L, 0x0006DB0CL,
|
||||
0x0006ED9FL, 0x00070000L, 0x00071232L, 0x00072435L,
|
||||
0x0007360BL, 0x000747B5L, 0x00075935L, 0x00076A8CL,
|
||||
0x00077BBBL, 0x00078CC2L, 0x00079DA3L, 0x0007AE60L,
|
||||
0x0007BEF8L, 0x0007CF6DL, 0x0007DFBFL, 0x0007EFF0L,
|
||||
0x00080000L, 0x00080FF0L, 0x00081FC1L, 0x00082F73L,
|
||||
0x00083F08L, 0x00084E7FL, 0x00085DDAL, 0x00086D18L,
|
||||
0x00087C3BL, 0x00088B44L, 0x00089A32L, 0x0008A906L,
|
||||
0x0008B7C2L, 0x0008C664L, 0x0008D4EEL, 0x0008E361L,
|
||||
0x0008F1BCL, 0x00090000L, 0x00090E2EL, 0x00091C45L,
|
||||
0x00092A47L, 0x00093834L, 0x0009460CL, 0x000953CFL,
|
||||
0x0009617EL, 0x00096F19L, 0x00097CA1L, 0x00098A16L,
|
||||
0x00099777L, 0x0009A4C6L, 0x0009B203L, 0x0009BF2EL,
|
||||
0x0009CC47L, 0x0009D94FL, 0x0009E645L, 0x0009F32BL,
|
||||
0x000A0000L, 0x000A0CC5L, 0x000A1979L, 0x000A261EL,
|
||||
0x000A32B3L, 0x000A3F38L, 0x000A4BAEL, 0x000A5816L,
|
||||
0x000A646EL, 0x000A70B8L, 0x000A7CF3L, 0x000A8921L,
|
||||
0x000A9540L, 0x000AA151L, 0x000AAD55L, 0x000AB94BL,
|
||||
0x000AC534L, 0x000AD110L, 0x000ADCDFL, 0x000AE8A1L,
|
||||
0x000AF457L, 0x000B0000L, 0x000B0B9DL, 0x000B172DL,
|
||||
0x000B22B2L, 0x000B2E2BL, 0x000B3998L, 0x000B44F9L,
|
||||
0x000B504FL, 0x000B5B9AL, 0x000B66D9L, 0x000B720EL,
|
||||
0x000B7D37L, 0x000B8856L, 0x000B936AL, 0x000B9E74L,
|
||||
0x000BA973L, 0x000BB467L, 0x000BBF52L, 0x000BCA32L,
|
||||
0x000BD508L, 0x000BDFD5L, 0x000BEA98L, 0x000BF551L,
|
||||
0x000C0000L, 0x000C0AA6L, 0x000C1543L, 0x000C1FD6L,
|
||||
0x000C2A60L, 0x000C34E1L, 0x000C3F59L, 0x000C49C8L,
|
||||
0x000C542EL, 0x000C5E8CL, 0x000C68E0L, 0x000C732DL,
|
||||
0x000C7D70L, 0x000C87ACL, 0x000C91DFL, 0x000C9C0AL,
|
||||
0x000CA62CL, 0x000CB047L, 0x000CBA59L, 0x000CC464L,
|
||||
0x000CCE66L, 0x000CD861L, 0x000CE254L, 0x000CEC40L,
|
||||
0x000CF624L, 0x000D0000L, 0x000D09D5L, 0x000D13A2L,
|
||||
0x000D1D69L, 0x000D2727L, 0x000D30DFL, 0x000D3A90L,
|
||||
0x000D4439L, 0x000D4DDCL, 0x000D5777L, 0x000D610CL,
|
||||
0x000D6A9AL, 0x000D7421L, 0x000D7DA1L, 0x000D871BL,
|
||||
0x000D908EL, 0x000D99FAL, 0x000DA360L, 0x000DACBFL,
|
||||
0x000DB618L, 0x000DBF6BL, 0x000DC8B7L, 0x000DD1FEL,
|
||||
0x000DDB3DL, 0x000DE477L, 0x000DEDABL, 0x000DF6D8L,
|
||||
0x000E0000L, 0x000E0922L, 0x000E123DL, 0x000E1B53L,
|
||||
0x000E2463L, 0x000E2D6DL, 0x000E3672L, 0x000E3F70L,
|
||||
0x000E4869L, 0x000E515DL, 0x000E5A4BL, 0x000E6333L,
|
||||
0x000E6C16L, 0x000E74F3L, 0x000E7DCBL, 0x000E869DL,
|
||||
0x000E8F6BL, 0x000E9832L, 0x000EA0F5L, 0x000EA9B2L,
|
||||
0x000EB26BL, 0x000EBB1EL, 0x000EC3CBL, 0x000ECC74L,
|
||||
0x000ED518L, 0x000EDDB7L, 0x000EE650L, 0x000EEEE5L,
|
||||
0x000EF775L, 0x000F0000L, 0x000F0886L, 0x000F1107L,
|
||||
0x000F1984L, 0x000F21FCL, 0x000F2A6FL, 0x000F32DDL,
|
||||
0x000F3B47L, 0x000F43ACL, 0x000F4C0CL, 0x000F5468L,
|
||||
0x000F5CBFL, 0x000F6512L, 0x000F6D60L, 0x000F75AAL,
|
||||
0x000F7DEFL, 0x000F8630L, 0x000F8E6DL, 0x000F96A5L,
|
||||
0x000F9ED9L, 0x000FA709L, 0x000FAF34L, 0x000FB75BL,
|
||||
0x000FBF7EL, 0x000FC79DL, 0x000FCFB7L, 0x000FD7CEL,
|
||||
0x000FDFE0L, 0x000FE7EEL, 0x000FEFF8L, 0x000FF7FEL,
|
||||
0x00100000L,
|
||||
};
|
||||
|
||||
/* the difference of the angle for two adjacent values in the
|
||||
* sin_tbl table, expressed as CoglFixed number
|
||||
*/
|
||||
static const int sin_tbl_size = G_N_ELEMENTS (sin_tbl) - 1;
|
||||
|
||||
static const double _magic = 68719476736.0 * 1.5;
|
||||
|
||||
/* Where in the 64 bits of double is the mantissa.
|
||||
*
|
||||
* FIXME - this should go inside the configure.ac
|
||||
*/
|
||||
#if (__FLOAT_WORD_ORDER == 1234)
|
||||
#define _COGL_MAN 0
|
||||
#elif (__FLOAT_WORD_ORDER == 4321)
|
||||
#define _COGL_MAN 1
|
||||
#else
|
||||
#define COGL_NO_FAST_CONVERSIONS
|
||||
#endif
|
||||
|
||||
/*
|
||||
* cogl_double_to_fixed :
|
||||
* @value: value to be converted
|
||||
*
|
||||
* A fast conversion from double precision floating to fixed point
|
||||
*
|
||||
* Return value: Fixed point representation of the value
|
||||
*/
|
||||
CoglFixed
|
||||
cogl_double_to_fixed (double val)
|
||||
{
|
||||
#ifdef COGL_NO_FAST_CONVERSIONS
|
||||
return (CoglFixed) (val * (double) COGL_FIXED_1);
|
||||
#else
|
||||
union {
|
||||
double d;
|
||||
unsigned int i[2];
|
||||
} dbl;
|
||||
|
||||
dbl.d = val;
|
||||
dbl.d = dbl.d + _magic;
|
||||
|
||||
return dbl.i[_COGL_MAN];
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* cogl_double_to_int :
|
||||
* @value: value to be converted
|
||||
*
|
||||
* A fast conversion from doulbe precision floatint point to int;
|
||||
* used this instead of casting double/float to int.
|
||||
*
|
||||
* Return value: Integer part of the double
|
||||
*/
|
||||
int
|
||||
cogl_double_to_int (double val)
|
||||
{
|
||||
#ifdef COGL_NO_FAST_CONVERSIONS
|
||||
return (int) (val);
|
||||
#else
|
||||
union {
|
||||
double d;
|
||||
unsigned int i[2];
|
||||
} dbl;
|
||||
|
||||
dbl.d = val;
|
||||
dbl.d = dbl.d + _magic;
|
||||
|
||||
return ((int) dbl.i[_COGL_MAN]) >> 16;
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned int
|
||||
cogl_double_to_uint (double val)
|
||||
{
|
||||
#ifdef COGL_NO_FAST_CONVERSIONS
|
||||
return (unsigned int)(val);
|
||||
#else
|
||||
union {
|
||||
double d;
|
||||
unsigned int i[2];
|
||||
} dbl;
|
||||
|
||||
dbl.d = val;
|
||||
dbl.d = dbl.d + _magic;
|
||||
|
||||
return (dbl.i[_COGL_MAN]) >> 16;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef _COGL_MAN
|
||||
|
||||
CoglFixed
|
||||
cogl_fixed_sin (CoglFixed angle)
|
||||
{
|
||||
int sign = 1, indx1, indx2;
|
||||
CoglFixed low, high;
|
||||
CoglFixed p1, p2;
|
||||
CoglFixed d1, d2;
|
||||
|
||||
/* convert negative angle to positive + sign */
|
||||
if ((int) angle < 0)
|
||||
{
|
||||
sign = -sign;
|
||||
angle = -angle;
|
||||
}
|
||||
|
||||
/* reduce to <0, 2*pi) */
|
||||
angle = angle % COGL_FIXED_2_PI;
|
||||
|
||||
/* reduce to first quadrant and sign */
|
||||
if (angle > COGL_FIXED_PI)
|
||||
{
|
||||
sign = -sign;
|
||||
|
||||
if (angle > COGL_FIXED_PI + COGL_FIXED_PI_2)
|
||||
{
|
||||
/* fourth qudrant */
|
||||
angle = COGL_FIXED_2_PI - angle;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* third quadrant */
|
||||
angle -= COGL_FIXED_PI;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (angle > COGL_FIXED_PI_2)
|
||||
{
|
||||
/* second quadrant */
|
||||
angle = COGL_FIXED_PI - angle;
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate indices of the two nearest values in our table
|
||||
* and return weighted average.
|
||||
*
|
||||
* We multiple first than divide to preserve precision. Since
|
||||
* angle is in the first quadrant, angle * SIN_TBL_SIZE (=256)
|
||||
* can't overflow.
|
||||
*
|
||||
* Handle the end of the table gracefully
|
||||
*/
|
||||
indx1 = (angle * sin_tbl_size) / COGL_FIXED_PI_2;
|
||||
|
||||
if (indx1 == sin_tbl_size)
|
||||
{
|
||||
indx2 = indx1;
|
||||
indx1 = indx2 - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
indx2 = indx1 + 1;
|
||||
}
|
||||
|
||||
low = sin_tbl[indx1];
|
||||
high = sin_tbl[indx2];
|
||||
|
||||
/* Again multiply the divide; no danger of overflow */
|
||||
p1 = (indx1 * COGL_FIXED_PI_2) / sin_tbl_size;
|
||||
p2 = (indx2 * COGL_FIXED_PI_2) / sin_tbl_size;
|
||||
d1 = angle - p1;
|
||||
d2 = p2 - angle;
|
||||
|
||||
angle = ((low * d2 + high * d1) / (p2 - p1));
|
||||
|
||||
if (sign < 0)
|
||||
angle = -angle;
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_angle_sin (CoglAngle angle)
|
||||
{
|
||||
int sign = 1;
|
||||
CoglFixed result;
|
||||
|
||||
/* reduce negative angle to positive + sign */
|
||||
if (angle < 0)
|
||||
{
|
||||
sign = -sign;
|
||||
angle = -angle;
|
||||
}
|
||||
|
||||
/* reduce to <0, 2*pi) */
|
||||
angle &= 0x3ff;
|
||||
|
||||
/* reduce to first quadrant and sign */
|
||||
if (angle > 512)
|
||||
{
|
||||
sign = -sign;
|
||||
|
||||
if (angle > 768)
|
||||
{
|
||||
/* fourth qudrant */
|
||||
angle = 1024 - angle;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* third quadrant */
|
||||
angle -= 512;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (angle > 256)
|
||||
{
|
||||
/* second quadrant */
|
||||
angle = 512 - angle;
|
||||
}
|
||||
}
|
||||
|
||||
result = sin_tbl[angle];
|
||||
|
||||
if (sign < 0)
|
||||
result = -result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_fixed_tan (CoglFixed angle)
|
||||
{
|
||||
return cogl_angle_tan (COGL_ANGLE_FROM_DEGX (angle));
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_angle_tan (CoglAngle angle)
|
||||
{
|
||||
int sign = 1;
|
||||
CoglFixed result;
|
||||
|
||||
/* reduce negative angle to positive + sign */
|
||||
if (angle < 0)
|
||||
{
|
||||
sign = -sign;
|
||||
angle = -angle;
|
||||
}
|
||||
|
||||
/* reduce to <0, pi) */
|
||||
angle &= 0x1ff;
|
||||
|
||||
/* reduce to first quadrant and sign */
|
||||
if (angle > 256)
|
||||
{
|
||||
sign = -sign;
|
||||
angle = 512 - angle;
|
||||
}
|
||||
|
||||
result = tan_tbl[angle];
|
||||
|
||||
if (sign < 0)
|
||||
result = -result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_fixed_atan (CoglFixed x)
|
||||
{
|
||||
gboolean negative = FALSE;
|
||||
CoglFixed angle;
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
negative = TRUE;
|
||||
x = -x;
|
||||
}
|
||||
|
||||
if (x > COGL_FIXED_1)
|
||||
{
|
||||
/* if x > 1 then atan(x) = pi/2 - atan(1/x) */
|
||||
angle = COGL_FIXED_PI / 2
|
||||
- atan_tbl[COGL_FIXED_DIV (COGL_FIXED_1, x) >> 8];
|
||||
}
|
||||
else
|
||||
angle = atan_tbl[x >> 8];
|
||||
|
||||
return negative ? -angle : angle;
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_fixed_atan2 (CoglFixed y, CoglFixed x)
|
||||
{
|
||||
CoglFixed angle;
|
||||
|
||||
if (x == 0)
|
||||
angle = y >= 0 ? COGL_FIXED_PI_2 : -COGL_FIXED_PI_2;
|
||||
else
|
||||
{
|
||||
angle = cogl_fixed_atan (COGL_FIXED_DIV (y, x));
|
||||
|
||||
if (x < 0)
|
||||
angle += y >= 0 ? COGL_FIXED_PI : -COGL_FIXED_PI;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_fixed_sqrt (CoglFixed x)
|
||||
{
|
||||
/* The idea for this comes from the Alegro library, exploiting the
|
||||
* fact that,
|
||||
* sqrt (x) = sqrt (x/d) * sqrt (d);
|
||||
*
|
||||
* For d == 2^(n):
|
||||
*
|
||||
* sqrt (x) = sqrt (x/2^(2n)) * 2^n
|
||||
*
|
||||
* By locating suitable n for given x such that x >> 2n is in <0,255>
|
||||
* we can use a LUT of precomputed values.
|
||||
*
|
||||
* This algorithm provides both good performance and precision;
|
||||
* on ARM this function is about 5 times faster than c-lib sqrt,
|
||||
* whilst producing errors < 1%.
|
||||
*/
|
||||
int t = 0;
|
||||
int sh = 0;
|
||||
unsigned int mask = 0x40000000;
|
||||
unsigned fract = x & 0x0000ffff;
|
||||
unsigned int d1, d2;
|
||||
CoglFixed v1, v2;
|
||||
|
||||
if (x <= 0)
|
||||
return 0;
|
||||
|
||||
if (x > COGL_FIXED_255 || x < COGL_FIXED_1)
|
||||
{
|
||||
/*
|
||||
* Find the highest bit set
|
||||
*/
|
||||
#if __arm__
|
||||
/* This actually requires at least arm v5, but gcc does not seem
|
||||
* to set the architecture defines correctly, and it is I think
|
||||
* very unlikely that anyone will want to use clutter on anything
|
||||
* less than v5.
|
||||
*/
|
||||
int bit;
|
||||
__asm__ ("clz %0, %1\n"
|
||||
"rsb %0, %0, #31\n"
|
||||
:"=r"(bit)
|
||||
:"r" (x));
|
||||
|
||||
/* make even (2n) */
|
||||
bit &= 0xfffffffe;
|
||||
#else
|
||||
/* TODO -- add i386 branch using bshr
|
||||
*
|
||||
* NB: it's been said that the bshr instruction is poorly implemented
|
||||
* and that it is possible to write a faster code in C using binary
|
||||
* search -- at some point we should explore this
|
||||
*/
|
||||
int bit = 30;
|
||||
while (bit >= 0)
|
||||
{
|
||||
if (x & mask)
|
||||
break;
|
||||
|
||||
mask = (mask >> 1 | mask >> 2);
|
||||
bit -= 2;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* now bit indicates the highest bit set; there are two scenarios
|
||||
*
|
||||
* 1) bit < 23: Our number is smaller so we shift it left to maximase
|
||||
* precision (< 16 really, since <16,23> never goes
|
||||
* through here.
|
||||
*
|
||||
* 2) bit > 23: our number is above the table, so we shift right
|
||||
*/
|
||||
|
||||
sh = ((bit - 22) >> 1);
|
||||
if (bit >= 8)
|
||||
t = (x >> (16 - 22 + bit));
|
||||
else
|
||||
t = (x << (22 - 16 - bit));
|
||||
}
|
||||
else
|
||||
{
|
||||
t = COGL_FIXED_TO_INT (x);
|
||||
}
|
||||
|
||||
/* Do a weighted average of the two nearest values */
|
||||
v1 = sqrt_tbl[t];
|
||||
v2 = sqrt_tbl[t+1];
|
||||
|
||||
/*
|
||||
* 12 is fairly arbitrary -- we want integer that is not too big to cost
|
||||
* us precision
|
||||
*/
|
||||
d1 = (unsigned)(fract) >> 12;
|
||||
d2 = ((unsigned)COGL_FIXED_1 >> 12) - d1;
|
||||
|
||||
x = ((v1*d2) + (v2*d1))/(COGL_FIXED_1 >> 12);
|
||||
|
||||
if (sh > 0)
|
||||
x = x << sh;
|
||||
else if (sh < 0)
|
||||
x = x >> -sh;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* cogl_sqrti:
|
||||
* @x: integer value
|
||||
*
|
||||
* Very fast fixed point implementation of square root for integers.
|
||||
*
|
||||
* This function is at least 6x faster than clib sqrt() on x86, and (this is
|
||||
* not a typo!) about 500x faster on ARM without FPU. It's error is < 5%
|
||||
* for arguments < %COGL_SQRTI_ARG_5_PERCENT and < 10% for arguments <
|
||||
* %COGL_SQRTI_ARG_10_PERCENT. The maximum argument that can be passed to
|
||||
* this function is COGL_SQRTI_ARG_MAX.
|
||||
*
|
||||
* Return value: integer square root.
|
||||
*
|
||||
*
|
||||
* Since: 0.2
|
||||
*/
|
||||
int
|
||||
cogl_sqrti (int number)
|
||||
{
|
||||
#if defined __SSE2__
|
||||
/* The GCC built-in with SSE2 (sqrtsd) is up to twice as fast as
|
||||
* the pure integer code below. It is also more accurate.
|
||||
*/
|
||||
return __builtin_sqrt (number);
|
||||
#else
|
||||
/* This is a fixed point implementation of the Quake III sqrt algorithm,
|
||||
* described, for example, at
|
||||
* http://www.codemaestro.com/reviews/review00000105.html
|
||||
*
|
||||
* While the original QIII is extremely fast, the use of floating division
|
||||
* and multiplication makes it perform very on arm processors without FPU.
|
||||
*
|
||||
* The key to successfully replacing the floating point operations with
|
||||
* fixed point is in the choice of the fixed point format. The QIII
|
||||
* algorithm does not calculate the square root, but its reciprocal ('y'
|
||||
* below), which is only at the end turned to the inverse value. In order
|
||||
* for the algorithm to produce satisfactory results, the reciprocal value
|
||||
* must be represented with sufficient precission; the 16.16 we use
|
||||
* elsewhere in clutter is not good enough, and 10.22 is used instead.
|
||||
*/
|
||||
CoglFixed x;
|
||||
guint32 y_1; /* 10.22 fixed point */
|
||||
guint32 f = 0x600000; /* '1.5' as 10.22 fixed */
|
||||
|
||||
union
|
||||
{
|
||||
float f;
|
||||
guint32 i;
|
||||
} flt, flt2;
|
||||
|
||||
flt.f = number;
|
||||
|
||||
x = COGL_FIXED_FROM_INT (number) / 2;
|
||||
|
||||
/* The QIII initial estimate */
|
||||
flt.i = 0x5f3759df - ( flt.i >> 1 );
|
||||
|
||||
/* Now, we convert the float to 10.22 fixed. We exploit the mechanism
|
||||
* described at http://www.d6.com/users/checker/pdfs/gdmfp.pdf.
|
||||
*
|
||||
* We want 22 bit fraction; a single precission float uses 23 bit
|
||||
* mantisa, so we only need to add 2^(23-22) (no need for the 1.5
|
||||
* multiplier as we are only dealing with positive numbers).
|
||||
*
|
||||
* Note: we have to use two separate variables here -- for some reason,
|
||||
* if we try to use just the flt variable, gcc on ARM optimises the whole
|
||||
* addition out, and it all goes pear shape, since without it, the bits
|
||||
* in the float will not be correctly aligned.
|
||||
*/
|
||||
flt2.f = flt.f + 2.0;
|
||||
flt2.i &= 0x7FFFFF;
|
||||
|
||||
/* Now we correct the estimate */
|
||||
y_1 = (flt2.i >> 11) * (flt2.i >> 11);
|
||||
y_1 = (y_1 >> 8) * (x >> 8);
|
||||
|
||||
y_1 = f - y_1;
|
||||
flt2.i = (flt2.i >> 11) * (y_1 >> 11);
|
||||
|
||||
/* If the original argument is less than 342, we do another
|
||||
* iteration to improve precission (for arguments >= 342, the single
|
||||
* iteration produces generally better results).
|
||||
*/
|
||||
if (x < 171)
|
||||
{
|
||||
y_1 = (flt2.i >> 11) * (flt2.i >> 11);
|
||||
y_1 = (y_1 >> 8) * (x >> 8);
|
||||
|
||||
y_1 = f - y_1;
|
||||
flt2.i = (flt2.i >> 11) * (y_1 >> 11);
|
||||
}
|
||||
|
||||
/* Invert, round and convert from 10.22 to an integer
|
||||
* 0x1e3c68 is a magical rounding constant that produces slightly
|
||||
* better results than 0x200000.
|
||||
*/
|
||||
return (number * flt2.i + 0x1e3c68) >> 22;
|
||||
#endif
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_fixed_mul (CoglFixed a,
|
||||
CoglFixed b)
|
||||
{
|
||||
#ifdef __arm__
|
||||
/* This provides about 12% speedeup on the gcc -O2 optimised
|
||||
* C version
|
||||
*
|
||||
* Based on code found in the following thread:
|
||||
* http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2006-August/014405.html
|
||||
*/
|
||||
int res_low, res_hi;
|
||||
|
||||
__asm__ ("smull %0, %1, %2, %3 \n"
|
||||
"mov %0, %0, lsr %4 \n"
|
||||
"add %1, %0, %1, lsl %5 \n"
|
||||
: "=r"(res_hi), "=r"(res_low) \
|
||||
: "r"(a), "r"(b), "i"(COGL_FIXED_Q), "i"(32 - COGL_FIXED_Q));
|
||||
|
||||
return (CoglFixed) res_low;
|
||||
#else
|
||||
gint64 r = (gint64) a * (gint64) b;
|
||||
|
||||
return (CoglFixed) (r >> COGL_FIXED_Q);
|
||||
#endif
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_fixed_div (CoglFixed a,
|
||||
CoglFixed b)
|
||||
{
|
||||
return (CoglFixed) ((((gint64) a) << COGL_FIXED_Q) / b);
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_fixed_mul_div (CoglFixed a,
|
||||
CoglFixed b,
|
||||
CoglFixed c)
|
||||
{
|
||||
CoglFixed ab = cogl_fixed_mul (a, b);
|
||||
CoglFixed quo = cogl_fixed_div (ab, c);
|
||||
|
||||
return quo;
|
||||
}
|
||||
|
||||
/*
|
||||
* The log2x() and pow2x() functions
|
||||
*
|
||||
* The implementation of the log2x() and pow2x() exploits the
|
||||
* well-documented fact that the exponent part of IEEE floating
|
||||
* number provides a good estimate of log2 of that number, while
|
||||
* the mantissa serves as a good error-correction.
|
||||
*
|
||||
* The implementation here uses a quadratic error correction as
|
||||
* described by Ian Stephenson at:
|
||||
* http://www.dctsystems.co.uk/Software/power.html.
|
||||
*/
|
||||
|
||||
CoglFixed
|
||||
cogl_fixed_log2 (unsigned int x)
|
||||
{
|
||||
/* Note: we could easily have a version for CoglFixed x, but the int
|
||||
* precision is enough for the current purposes.
|
||||
*/
|
||||
union
|
||||
{
|
||||
float f;
|
||||
CoglFixed i;
|
||||
} flt;
|
||||
|
||||
CoglFixed magic = 0x58bb;
|
||||
CoglFixed y;
|
||||
|
||||
/*
|
||||
* Convert x to float, then extract exponent.
|
||||
*
|
||||
* We want the result to be 16.16 fixed, so we shift (23-16) bits only
|
||||
*/
|
||||
flt.f = x;
|
||||
flt.i >>= 7;
|
||||
flt.i -= COGL_FIXED_FROM_INT (127);
|
||||
|
||||
y = COGL_FIXED_FRACTION (flt.i);
|
||||
|
||||
y = COGL_FIXED_MUL ((y - COGL_FIXED_MUL (y, y)), magic);
|
||||
|
||||
return flt.i + y;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
cogl_fixed_pow2 (CoglFixed x)
|
||||
{
|
||||
/* Note: we could easily have a version that produces CoglFixed result,
|
||||
* but the range would be limited to x < 15, and the int precision
|
||||
* is enough for the current purposes.
|
||||
*/
|
||||
|
||||
union
|
||||
{
|
||||
float f;
|
||||
guint32 i;
|
||||
} flt;
|
||||
|
||||
CoglFixed magic = 0x56f7;
|
||||
CoglFixed y;
|
||||
|
||||
flt.i = x;
|
||||
|
||||
/*
|
||||
* Reverse of the log2x function -- convert the fixed value to a suitable
|
||||
* floating point exponent, and mantisa adjusted with quadratic error
|
||||
* correction y.
|
||||
*/
|
||||
y = COGL_FIXED_FRACTION (x);
|
||||
y = COGL_FIXED_MUL ((y - COGL_FIXED_MUL (y, y)), magic);
|
||||
|
||||
/* Shift the exponent into it's position in the floating point
|
||||
* representation; as our number is not int but 16.16 fixed, shift only
|
||||
* by (23 - 16)
|
||||
*/
|
||||
flt.i += (COGL_FIXED_FROM_INT (127) - y);
|
||||
flt.i <<= 7;
|
||||
|
||||
return COGL_FLOAT_TO_UINT (flt.f);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
cogl_fixed_pow (unsigned int x,
|
||||
CoglFixed y)
|
||||
{
|
||||
return cogl_fixed_pow2 (COGL_FIXED_MUL (y, cogl_fixed_log2 (x)));
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_angle_cos (CoglAngle angle)
|
||||
{
|
||||
CoglAngle a = angle + 256;
|
||||
|
||||
return cogl_angle_sin (a);
|
||||
}
|
||||
|
||||
CoglFixed
|
||||
cogl_fixed_cos (CoglFixed angle)
|
||||
{
|
||||
CoglFixed a = angle + COGL_FIXED_PI_2;
|
||||
|
||||
return cogl_fixed_sin (a);
|
||||
}
|
@ -1,804 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_FIXED_H__
|
||||
#define __COGL_FIXED_H__
|
||||
|
||||
#include <cogl/cogl-types.h>
|
||||
|
||||
/**
|
||||
* SECTION:cogl-fixed
|
||||
* @short_description: Fixed Point API
|
||||
*
|
||||
* COGL has a fixed point API targeted at platforms without a floating
|
||||
* point unit, such as embedded devices. On such platforms this API should
|
||||
* be preferred to the floating point one as it does not trigger the slow
|
||||
* path of software emulation, relying on integer math for fixed-to-floating
|
||||
* and floating-to-fixed notations conversion.
|
||||
*
|
||||
* It is not recommened for use on platforms with a floating point unit
|
||||
* (e.g. desktop systems), nor for use in language bindings.
|
||||
*
|
||||
* Basic rules of Fixed Point arithmethic:
|
||||
* <itemizedlist>
|
||||
* <listitem>
|
||||
* <para>Two fixed point numbers can be directly added, subtracted and
|
||||
* have their modulus taken.</para>
|
||||
* </listitem>
|
||||
* <listitem>
|
||||
* <para>To add other numerical type to a fixed point number it has to
|
||||
* be first converted to fixed point.</para>
|
||||
* </listitem>
|
||||
* <listitem>
|
||||
* <para>A fixed point number can be directly multiplied or divided by
|
||||
* an integer.</para>
|
||||
* </listitem>
|
||||
* <listitem>
|
||||
* <para>Two fixed point numbers can only be multiplied and divided by
|
||||
* the provided %COGL_FIXED_MUL and %COGL_FIXED_DIV macros.</para>
|
||||
* </listitem>
|
||||
* </itemizedlist>
|
||||
*
|
||||
* The fixed point API is available since COGL 1.0.
|
||||
*/
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* COGL_FIXED_BITS:
|
||||
*
|
||||
* Evaluates to the number of bits used by the #CoglFixed type.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_BITS (32)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_Q:
|
||||
*
|
||||
* Evaluates to the number of bits used for the non-integer part
|
||||
* of the #CoglFixed type.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_Q (COGL_FIXED_BITS - 16)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_1:
|
||||
*
|
||||
* The number 1 expressed as a #CoglFixed number.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_1 (1 << COGL_FIXED_Q)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_0_5:
|
||||
*
|
||||
* The number 0.5 expressed as a #CoglFixed number.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_0_5 (32768)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_EPSILON:
|
||||
*
|
||||
* A very small number expressed as a #CoglFixed number.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_EPSILON (1)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_MAX:
|
||||
*
|
||||
* The biggest number representable using #CoglFixed
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_MAX (0x7fffffff)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_MIN:
|
||||
*
|
||||
* The smallest number representable using #CoglFixed
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_MIN (0x80000000)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_PI:
|
||||
*
|
||||
* The number pi, expressed as a #CoglFixed number.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_PI (0x0003243f)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_2_PI:
|
||||
*
|
||||
* Two times pi, expressed as a #CoglFixed number.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_2_PI (0x0006487f)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_PI_2:
|
||||
*
|
||||
* Half pi, expressed as a #CoglFixed number.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_PI_2 (0x00019220)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_PI_4:
|
||||
*
|
||||
* pi / 4, expressed as #CoglFixed number.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_PI_4 (0x0000c910)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_360:
|
||||
*
|
||||
* Evaluates to the number 360 in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_360 (COGL_FIXED_FROM_INT (360))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_270:
|
||||
*
|
||||
* Evaluates to the number 270 in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_270 (COGL_FIXED_FROM_INT (270))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_255:
|
||||
*
|
||||
* Evaluates to the number 255 in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_255 (COGL_FIXED_FROM_INT (255))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_240:
|
||||
*
|
||||
* Evaluates to the number 240 in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_240 (COGL_FIXED_FROM_INT (240))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_180:
|
||||
*
|
||||
* Evaluates to the number 180 in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_180 (COGL_FIXED_FROM_INT (180))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_120:
|
||||
*
|
||||
* Evaluates to the number 120 in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_120 (COGL_FIXED_FROM_INT (120))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_90:
|
||||
*
|
||||
* Evaluates to the number 90 in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_90 (COGL_FIXED_FROM_INT (90))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_60:
|
||||
*
|
||||
* Evaluates to the number 60 in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_60 (COGL_FIXED_FROM_INT (60))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_45:
|
||||
*
|
||||
* Evaluates to the number 45 in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_45 (COGL_FIXED_FROM_INT (45))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_30:
|
||||
*
|
||||
* Evaluates to the number 30 in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_30 (COGL_FIXED_FROM_INT (30))
|
||||
|
||||
/**
|
||||
* COGL_RADIANS_TO_DEGREES:
|
||||
*
|
||||
* Evaluates to 180 / pi in fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_RADIANS_TO_DEGREES (0x394bb8)
|
||||
|
||||
/*
|
||||
* conversion macros
|
||||
*/
|
||||
|
||||
/**
|
||||
* COGL_FIXED_FROM_FLOAT:
|
||||
* @x: a floating point number
|
||||
*
|
||||
* Converts @x from a floating point to a fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_FROM_FLOAT(x) ((float) cogl_double_to_fixed (x))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_TO_FLOAT:
|
||||
* @x: a #CoglFixed number
|
||||
*
|
||||
* Converts @x from a fixed point to a floating point notation, in
|
||||
* single precision.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_TO_FLOAT(x) ((float) ((int)(x) / 65536.0))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_FROM_DOUBLE:
|
||||
* @x: a floating point number
|
||||
*
|
||||
* Converts @x from a double precision, floating point to a fixed
|
||||
* point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_FROM_DOUBLE(x) (cogl_double_to_fixed (x))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_TO_DOUBLE:
|
||||
* @x: a #CoglFixed number
|
||||
*
|
||||
* Converts @x from a fixed point to a floating point notation, in
|
||||
* double precision.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_TO_DOUBLE(x) ((double) ((int)(x) / 65536.0))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_FROM_INT:
|
||||
* @x: an integer number
|
||||
*
|
||||
* Converts @x from an integer to a fixed point notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_FROM_INT(x) ((x) << COGL_FIXED_Q)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_TO_INT:
|
||||
* @x: a #CoglFixed number
|
||||
*
|
||||
* Converts @x from a fixed point notation to an integer, dropping
|
||||
* the fractional part without rounding.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_TO_INT(x) ((x) >> COGL_FIXED_Q)
|
||||
|
||||
/**
|
||||
* COGL_FLOAT_TO_INT:
|
||||
* @x: a floatint point number
|
||||
*
|
||||
* Converts @x from a floating point notation to a signed integer.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FLOAT_TO_INT(x) (cogl_double_to_int ((x)))
|
||||
|
||||
/**
|
||||
* COGL_FLOAT_TO_UINT:
|
||||
* @x: a floatint point number
|
||||
*
|
||||
* Converts @x from a floating point notation to an unsigned integer.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FLOAT_TO_UINT(x) (cogl_double_to_uint ((x)))
|
||||
|
||||
/*
|
||||
* fixed point math functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* COGL_FIXED_FRACTION:
|
||||
* @x: a #CoglFixed number
|
||||
*
|
||||
* Retrieves the fractionary part of @x.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_FRACTION(x) ((x) & ((1 << COGL_FIXED_Q) - 1))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_FLOOR:
|
||||
* @x: a #CoglFixed number
|
||||
*
|
||||
* Rounds down a fixed point number to the previous integer.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_FLOOR(x) (((x) >= 0) ? ((x) >> COGL_FIXED_Q) \
|
||||
: ~((~(x)) >> COGL_FIXED_Q))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_CEIL:
|
||||
* @x: a #CoglFixed number
|
||||
*
|
||||
* Rounds up a fixed point number to the next integer.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_CEIL(x) (COGL_FIXED_FLOOR ((x) + 0xffff))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_MUL:
|
||||
* @a: a #CoglFixed number
|
||||
* @b: a #CoglFixed number
|
||||
*
|
||||
* Computes (a * b).
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_MUL(a,b) (cogl_fixed_mul ((a), (b)))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_DIV:
|
||||
* @a: a #CoglFixed number
|
||||
* @b: a #CoglFixed number
|
||||
*
|
||||
* Computes (a / b).
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_DIV(a,b) (cogl_fixed_div ((a), (b)))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_MUL_DIV:
|
||||
* @a: a #CoglFixed number
|
||||
* @b: a #CoglFixed number
|
||||
* @c: a #CoglFixed number
|
||||
*
|
||||
* Computes ((a * b) / c). It is logically equivalent to:
|
||||
*
|
||||
* |[
|
||||
* res = COGL_FIXED_DIV (COGL_FIXED_MUL (a, b), c);
|
||||
* ]|
|
||||
*
|
||||
* But it is shorter to type.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_MUL_DIV(a,b,c) (cogl_fixed_mul_div ((a), (b), (c)))
|
||||
|
||||
/**
|
||||
* COGL_FIXED_FAST_MUL:
|
||||
* @a: a #CoglFixed number
|
||||
* @b: a #CoglFixed number
|
||||
*
|
||||
* Fast version of %COGL_FIXED_MUL, implemented as a macro.
|
||||
*
|
||||
* <note>This macro might lose precision. If the precision of the result
|
||||
* is important use %COGL_FIXED_MUL instead.</note>
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_FAST_MUL(a,b) ((a) >> 8) * ((b) >> 8)
|
||||
|
||||
/**
|
||||
* COGL_FIXED_FAST_DIV:
|
||||
* @a: a #CoglFixed number
|
||||
* @b: a #CoglFixed number
|
||||
*
|
||||
* Fast version of %COGL_FIXED_DIV, implemented as a macro.
|
||||
*
|
||||
* <note>This macro might lose precision. If the precision of the result
|
||||
* is important use %COGL_FIXED_DIV instead.</note>
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_FIXED_FAST_DIV(a,b) ((((a) << 8) / (b)) << 8)
|
||||
|
||||
/**
|
||||
* cogl_fixed_sin:
|
||||
* @angle: a #CoglFixed number
|
||||
*
|
||||
* Computes the sine of @angle.
|
||||
*
|
||||
* Return value: the sine of the passed angle, in fixed point notation
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglFixed
|
||||
cogl_fixed_sin (CoglFixed angle);
|
||||
|
||||
/**
|
||||
* cogl_fixed_tan:
|
||||
* @angle: a #CoglFixed number
|
||||
*
|
||||
* Computes the tangent of @angle.
|
||||
*
|
||||
* Return value: the tangent of the passed angle, in fixed point notation
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglFixed
|
||||
cogl_fixed_tan (CoglFixed angle);
|
||||
|
||||
/**
|
||||
* cogl_fixed_cos:
|
||||
* @angle: a #CoglFixed number
|
||||
*
|
||||
* Computes the cosine of @angle.
|
||||
*
|
||||
* Return value: the cosine of the passed angle, in fixed point notation
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglFixed cogl_fixed_cos (CoglFixed angle);
|
||||
|
||||
/**
|
||||
* cogl_fixed_atan:
|
||||
* @a: a #CoglFixed number
|
||||
*
|
||||
* Computes the arc tangent of @a.
|
||||
*
|
||||
* Return value: the arc tangent of the passed value, in fixed point notation
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglFixed
|
||||
cogl_fixed_atan (CoglFixed a);
|
||||
|
||||
/**
|
||||
* cogl_fixed_atan2:
|
||||
* @a: the numerator as a #CoglFixed number
|
||||
* @b: the denominator as a #CoglFixed number
|
||||
*
|
||||
* Computes the arc tangent of @a / @b but uses the sign of both
|
||||
* arguments to return the angle in right quadrant.
|
||||
*
|
||||
* Return value: the arc tangent of the passed fraction, in fixed point
|
||||
* notation
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglFixed
|
||||
cogl_fixed_atan2 (CoglFixed a,
|
||||
CoglFixed b);
|
||||
|
||||
/*< public >*/
|
||||
|
||||
/* Fixed point math routines */
|
||||
G_INLINE_FUNC CoglFixed
|
||||
cogl_fixed_mul (CoglFixed a,
|
||||
CoglFixed b);
|
||||
|
||||
G_INLINE_FUNC CoglFixed
|
||||
cogl_fixed_div (CoglFixed a,
|
||||
CoglFixed b);
|
||||
|
||||
G_INLINE_FUNC CoglFixed
|
||||
cogl_fixed_mul_div (CoglFixed a,
|
||||
CoglFixed b,
|
||||
CoglFixed c);
|
||||
|
||||
/**
|
||||
* COGL_SQRTI_ARG_MAX:
|
||||
*
|
||||
* Maximum argument that can be passed to cogl_sqrti() function.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#ifndef __SSE2__
|
||||
#define COGL_SQRTI_ARG_MAX 0x3fffff
|
||||
#else
|
||||
#define COGL_SQRTI_ARG_MAX INT_MAX
|
||||
#endif
|
||||
|
||||
/**
|
||||
* COGL_SQRTI_ARG_5_PERCENT:
|
||||
*
|
||||
* Maximum argument that can be passed to cogl_sqrti() for which the
|
||||
* resulting error is < 5%
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#ifndef __SSE2__
|
||||
#define COGL_SQRTI_ARG_5_PERCENT 210
|
||||
#else
|
||||
#define COGL_SQRTI_ARG_5_PERCENT INT_MAX
|
||||
#endif
|
||||
|
||||
/**
|
||||
* COGL_SQRTI_ARG_10_PERCENT:
|
||||
*
|
||||
* Maximum argument that can be passed to cogl_sqrti() for which the
|
||||
* resulting error is < 10%
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#ifndef __SSE2__
|
||||
#define COGL_SQRTI_ARG_10_PERCENT 5590
|
||||
#else
|
||||
#define COGL_SQRTI_ARG_10_PERCENT INT_MAX
|
||||
#endif
|
||||
|
||||
/**
|
||||
* cogl_fixed_sqrt:
|
||||
* @x: a #CoglFixed number
|
||||
*
|
||||
* Computes the square root of @x.
|
||||
*
|
||||
* Return value: the square root of the passed value, in floating point
|
||||
* notation
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglFixed
|
||||
cogl_fixed_sqrt (CoglFixed x);
|
||||
|
||||
/**
|
||||
* cogl_fixed_log2:
|
||||
* @x: value to calculate base 2 logarithm from
|
||||
*
|
||||
* Calculates base 2 logarithm.
|
||||
*
|
||||
* This function is some 2.5 times faster on x86, and over 12 times faster on
|
||||
* fpu-less arm, than using libc log().
|
||||
*
|
||||
* Return value: base 2 logarithm.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglFixed
|
||||
cogl_fixed_log2 (unsigned int x);
|
||||
|
||||
/**
|
||||
* cogl_fixed_pow2:
|
||||
* @x: a #CoglFixed number
|
||||
*
|
||||
* Calculates 2 to the @x power.
|
||||
*
|
||||
* This function is around 11 times faster on x86, and around 22 times faster
|
||||
* on fpu-less arm than libc pow(2, x).
|
||||
*
|
||||
* Return value: the power of 2 to the passed value
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
unsigned int
|
||||
cogl_fixed_pow2 (CoglFixed x);
|
||||
|
||||
/**
|
||||
* cogl_fixed_pow:
|
||||
* @x: base
|
||||
* @y: #CoglFixed exponent
|
||||
*
|
||||
* Calculates @x to the @y power.
|
||||
*
|
||||
* Return value: the power of @x to the @y
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
unsigned int
|
||||
cogl_fixed_pow (unsigned int x,
|
||||
CoglFixed y);
|
||||
|
||||
/**
|
||||
* cogl_sqrti:
|
||||
* @x: integer value
|
||||
*
|
||||
* Very fast fixed point implementation of square root for integers.
|
||||
*
|
||||
* This function is at least 6x faster than clib sqrt() on x86, and (this is
|
||||
* not a typo!) about 500x faster on ARM without FPU. It's error is less than
|
||||
* 5% for arguments smaller than %COGL_SQRTI_ARG_5_PERCENT and less than 10%
|
||||
* for narguments smaller than %COGL_SQRTI_ARG_10_PERCENT. The maximum
|
||||
* argument that can be passed to this function is %COGL_SQRTI_ARG_MAX.
|
||||
*
|
||||
* Return value: integer square root.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
int
|
||||
cogl_sqrti (int x);
|
||||
|
||||
/**
|
||||
* COGL_ANGLE_FROM_DEG:
|
||||
* @x: an angle in degrees in floating point notation
|
||||
*
|
||||
* Converts an angle in degrees into a #CoglAngle.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_ANGLE_FROM_DEG(x) (COGL_FLOAT_TO_INT (((float)(x) * 1024.0f) / 360.0f))
|
||||
|
||||
/**
|
||||
* COGL_ANGLE_TO_DEG:
|
||||
* @x: a #CoglAngle
|
||||
*
|
||||
* Converts a #CoglAngle into an angle in degrees, using floatint point
|
||||
* notation.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_ANGLE_TO_DEG(x) (((float)(x) * 360.0) / 1024.0)
|
||||
|
||||
/**
|
||||
* COGL_ANGLE_FROM_DEGX:
|
||||
* @x: an angle in degrees in fixed point notation
|
||||
*
|
||||
* Converts an angle in degrees into a #CoglAngle.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_ANGLE_FROM_DEGX(x) (COGL_FIXED_TO_INT ((((x) / 360) * 1024) + COGL_FIXED_0_5))
|
||||
|
||||
/**
|
||||
* COGL_ANGLE_TO_DEGX:
|
||||
* @x: a #CoglAngle
|
||||
*
|
||||
* Converts a #CoglAngle into an angle in degrees, using fixed point notation
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
#define COGL_ANGLE_TO_DEGX(x) (COGL_FIXED_FROM_INT ((x) * 45) / 128)
|
||||
|
||||
/**
|
||||
* cogl_angle_sin:
|
||||
* @angle: an angle expressed using #CoglAngle
|
||||
*
|
||||
* Computes the sine of @angle
|
||||
*
|
||||
* Return value: the sine of the passed angle
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglFixed
|
||||
cogl_angle_sin (CoglAngle angle);
|
||||
|
||||
/**
|
||||
* cogl_angle_tan:
|
||||
* @angle: an angle expressed using #CoglAngle
|
||||
*
|
||||
* Computes the tangent of @angle
|
||||
*
|
||||
* Return value: the tangent of the passed angle
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglFixed
|
||||
cogl_angle_tan (CoglAngle angle);
|
||||
|
||||
/**
|
||||
* cogl_angle_cos:
|
||||
* @angle: an angle expressed using #CoglAngle
|
||||
*
|
||||
* Computes the cosine of @angle
|
||||
*
|
||||
* Return value: the cosine of the passed angle
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
CoglFixed
|
||||
cogl_angle_cos (CoglAngle angle);
|
||||
|
||||
/*< private >*/
|
||||
|
||||
#if defined (G_CAN_INLINE)
|
||||
G_INLINE_FUNC CoglFixed
|
||||
cogl_fixed_mul (CoglFixed a,
|
||||
CoglFixed b)
|
||||
{
|
||||
# ifdef __arm__
|
||||
int res_low, res_hi;
|
||||
|
||||
__asm__ ("smull %0, %1, %2, %3 \n"
|
||||
"mov %0, %0, lsr %4 \n"
|
||||
"add %1, %0, %1, lsl %5 \n"
|
||||
: "=r"(res_hi), "=r"(res_low)\
|
||||
: "r"(a), "r"(b), "i"(COGL_FIXED_Q), "i"(32 - COGL_FIXED_Q));
|
||||
|
||||
return (CoglFixed) res_low;
|
||||
# else
|
||||
long long r = (long long) a * (long long) b;
|
||||
|
||||
return (unsigned int)(r >> COGL_FIXED_Q);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (G_CAN_INLINE)
|
||||
G_INLINE_FUNC CoglFixed
|
||||
cogl_fixed_div (CoglFixed a,
|
||||
CoglFixed b)
|
||||
{
|
||||
return (CoglFixed) ((((gint64) a) << COGL_FIXED_Q) / b);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(G_CAN_INLINE)
|
||||
G_INLINE_FUNC CoglFixed
|
||||
cogl_fixed_mul_div (CoglFixed a,
|
||||
CoglFixed b,
|
||||
CoglFixed c)
|
||||
{
|
||||
CoglFixed ab = cogl_fixed_mul (a, b);
|
||||
CoglFixed quo = cogl_fixed_div (ab, c);
|
||||
|
||||
return quo;
|
||||
}
|
||||
#endif
|
||||
|
||||
CoglFixed
|
||||
cogl_double_to_fixed (double value);
|
||||
|
||||
int
|
||||
cogl_double_to_int (double value);
|
||||
|
||||
unsigned int
|
||||
cogl_double_to_uint (double value);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_FIXED_H__ */
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Neil Roberts <neil@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_FLAGS_H
|
||||
#define __COGL_FLAGS_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* These are macros used to implement a fixed-size array of bits. This
|
||||
should be used instead of CoglBitmask when the maximum bit number
|
||||
that will be set is known at compile time, for example when setting
|
||||
for recording a set of known available features */
|
||||
|
||||
/* The bits are stored in an array of unsigned ints. It would probably
|
||||
make sense to use unsigned long instead because then on 64-bit
|
||||
systems where it can handle 64-bits just as easily and it can test
|
||||
more bits. However GDebugKey uses a guint for the mask and we need
|
||||
to fit the masks into this */
|
||||
|
||||
/* To use these macros, you would typically have an enum defining the
|
||||
available bits with an extra last enum to define the maximum
|
||||
value. Then to store the flags you would declare an array of
|
||||
unsigned ints sized using COGL_FLAGS_N_INTS_FOR_SIZE, eg:
|
||||
|
||||
typedef enum { FEATURE_A, FEATURE_B, FEATURE_C, N_FEATURES } Features;
|
||||
|
||||
unsigned int feature_flags[COGL_FLAGS_N_INTS_FOR_SIZE (N_FEATURES)];
|
||||
*/
|
||||
|
||||
#define COGL_FLAGS_N_INTS_FOR_SIZE(size) \
|
||||
(((size) + \
|
||||
(sizeof (unsigned int) * 8 - 1)) \
|
||||
/ (sizeof (unsigned int) * 8))
|
||||
|
||||
/* @flag is expected to be constant so these should result in a
|
||||
constant expression. This means that setting a flag is equivalent
|
||||
to just setting in a bit in a global variable at a known
|
||||
location */
|
||||
#define COGL_FLAGS_GET_INDEX(flag) \
|
||||
((flag) / (sizeof (unsigned int) * 8))
|
||||
#define COGL_FLAGS_GET_MASK(flag) \
|
||||
(1U << ((unsigned int) (flag) & \
|
||||
(sizeof (unsigned int) * 8 - 1)))
|
||||
|
||||
#define COGL_FLAGS_GET(array, flag) \
|
||||
(!!((array)[COGL_FLAGS_GET_INDEX (flag)] & \
|
||||
COGL_FLAGS_GET_MASK (flag)))
|
||||
|
||||
/* The expectation here is that @value will be constant so the if
|
||||
statement will be optimised out */
|
||||
#define COGL_FLAGS_SET(array, flag, value) \
|
||||
G_STMT_START { \
|
||||
if (value) \
|
||||
((array)[COGL_FLAGS_GET_INDEX (flag)] |= \
|
||||
COGL_FLAGS_GET_MASK (flag)); \
|
||||
else \
|
||||
((array)[COGL_FLAGS_GET_INDEX (flag)] &= \
|
||||
~COGL_FLAGS_GET_MASK (flag)); \
|
||||
} G_STMT_END
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_FLAGS_H */
|
||||
|
@ -1,358 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_FRAMEBUFFER_PRIVATE_H
|
||||
#define __COGL_FRAMEBUFFER_PRIVATE_H
|
||||
|
||||
#include "cogl-object-private.h"
|
||||
#include "cogl-matrix-stack.h"
|
||||
#include "cogl-clip-state-private.h"
|
||||
#include "cogl-journal-private.h"
|
||||
|
||||
#ifdef COGL_HAS_XLIB_SUPPORT
|
||||
#include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef COGL_HAS_GLX_SUPPORT
|
||||
#include <GL/glx.h>
|
||||
#include <GL/glxext.h>
|
||||
#endif
|
||||
|
||||
typedef enum _CoglFramebufferType {
|
||||
COGL_FRAMEBUFFER_TYPE_ONSCREEN,
|
||||
COGL_FRAMEBUFFER_TYPE_OFFSCREEN
|
||||
} CoglFramebufferType;
|
||||
|
||||
struct _CoglFramebuffer
|
||||
{
|
||||
CoglObject _parent;
|
||||
CoglContext *context;
|
||||
CoglFramebufferType type;
|
||||
int width;
|
||||
int height;
|
||||
/* Format of the pixels in the framebuffer (including the expected
|
||||
premult state) */
|
||||
CoglPixelFormat format;
|
||||
gboolean allocated;
|
||||
|
||||
CoglMatrixStack *modelview_stack;
|
||||
CoglMatrixStack *projection_stack;
|
||||
float viewport_x;
|
||||
float viewport_y;
|
||||
float viewport_width;
|
||||
float viewport_height;
|
||||
|
||||
CoglClipState clip_state;
|
||||
|
||||
gboolean dirty_bitmasks;
|
||||
int red_bits;
|
||||
int blue_bits;
|
||||
int green_bits;
|
||||
int alpha_bits;
|
||||
|
||||
/* We journal the textured rectangles we want to submit to OpenGL so
|
||||
* we have an oppertunity to batch them together into less draw
|
||||
* calls. */
|
||||
CoglJournal *journal;
|
||||
|
||||
/* The scene of a given framebuffer may depend on images in other
|
||||
* framebuffers... */
|
||||
GList *deps;
|
||||
|
||||
/* As part of an optimization for reading-back single pixels from a
|
||||
* framebuffer in some simple cases where the geometry is still
|
||||
* available in the journal we need to track the bounds of the last
|
||||
* region cleared, its color and we need to track when something
|
||||
* does in fact draw to that region so it is no longer clear.
|
||||
*/
|
||||
float clear_color_red;
|
||||
float clear_color_green;
|
||||
float clear_color_blue;
|
||||
float clear_color_alpha;
|
||||
int clear_clip_x0;
|
||||
int clear_clip_y0;
|
||||
int clear_clip_x1;
|
||||
int clear_clip_y1;
|
||||
gboolean clear_clip_dirty;
|
||||
};
|
||||
|
||||
typedef struct _CoglOffscreen
|
||||
{
|
||||
CoglFramebuffer _parent;
|
||||
GLuint fbo_handle;
|
||||
GSList *renderbuffers;
|
||||
CoglHandle texture;
|
||||
} CoglOffscreen;
|
||||
|
||||
/* Flags to pass to _cogl_offscreen_new_to_texture_full */
|
||||
typedef enum
|
||||
{
|
||||
COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL = 1
|
||||
} CoglOffscreenFlags;
|
||||
|
||||
#define COGL_OFFSCREEN(X) ((CoglOffscreen *)(X))
|
||||
|
||||
struct _CoglOnscreen
|
||||
{
|
||||
CoglFramebuffer _parent;
|
||||
|
||||
#ifdef COGL_HAS_X11_SUPPORT
|
||||
guint32 foreign_xid;
|
||||
CoglOnscreenX11MaskCallback foreign_update_mask_callback;
|
||||
void *foreign_update_mask_data;
|
||||
#endif
|
||||
|
||||
gboolean swap_throttled;
|
||||
|
||||
void *winsys;
|
||||
};
|
||||
|
||||
void
|
||||
_cogl_framebuffer_state_init (void);
|
||||
|
||||
void
|
||||
_cogl_framebuffer_winsys_update_size (CoglFramebuffer *framebuffer,
|
||||
int width, int height);
|
||||
|
||||
void
|
||||
_cogl_clear4f (unsigned long buffers,
|
||||
float red,
|
||||
float green,
|
||||
float blue,
|
||||
float alpha);
|
||||
|
||||
void
|
||||
_cogl_framebuffer_clear (CoglFramebuffer *framebuffer,
|
||||
unsigned long buffers,
|
||||
const CoglColor *color);
|
||||
|
||||
void
|
||||
_cogl_framebuffer_clear4f (CoglFramebuffer *framebuffer,
|
||||
unsigned long buffers,
|
||||
float red,
|
||||
float green,
|
||||
float blue,
|
||||
float alpha);
|
||||
|
||||
void
|
||||
_cogl_framebuffer_dirty (CoglFramebuffer *framebuffer);
|
||||
|
||||
CoglClipState *
|
||||
_cogl_framebuffer_get_clip_state (CoglFramebuffer *framebuffer);
|
||||
|
||||
/*
|
||||
* _cogl_framebuffer_get_clip_stack:
|
||||
* @framebuffer: A #CoglFramebuffer
|
||||
*
|
||||
* Gets a pointer to the current clip stack. This can be used to later
|
||||
* return to the same clip stack state with
|
||||
* _cogl_framebuffer_set_clip_stack(). A reference is not taken on the
|
||||
* stack so if you want to keep it you should call
|
||||
* _cogl_clip_stack_ref().
|
||||
*
|
||||
* Return value: a pointer to the @framebuffer clip stack.
|
||||
*/
|
||||
CoglClipStack *
|
||||
_cogl_framebuffer_get_clip_stack (CoglFramebuffer *framebuffer);
|
||||
|
||||
/*
|
||||
* _cogl_framebuffer_set_clip_stack:
|
||||
* @framebuffer: A #CoglFramebuffer
|
||||
* @stack: a pointer to the replacement clip stack
|
||||
*
|
||||
* Replaces the @framebuffer clip stack with @stack.
|
||||
*/
|
||||
void
|
||||
_cogl_framebuffer_set_clip_stack (CoglFramebuffer *framebuffer,
|
||||
CoglClipStack *stack);
|
||||
|
||||
void
|
||||
_cogl_framebuffer_set_viewport (CoglFramebuffer *framebuffer,
|
||||
float x,
|
||||
float y,
|
||||
float width,
|
||||
float height);
|
||||
float
|
||||
_cogl_framebuffer_get_viewport_x (CoglFramebuffer *framebuffer);
|
||||
|
||||
float
|
||||
_cogl_framebuffer_get_viewport_y (CoglFramebuffer *framebuffer);
|
||||
|
||||
float
|
||||
_cogl_framebuffer_get_viewport_width (CoglFramebuffer *framebuffer);
|
||||
|
||||
float
|
||||
_cogl_framebuffer_get_viewport_height (CoglFramebuffer *framebuffer);
|
||||
|
||||
void
|
||||
_cogl_framebuffer_get_viewport4fv (CoglFramebuffer *framebuffer,
|
||||
float *viewport);
|
||||
|
||||
CoglMatrixStack *
|
||||
_cogl_framebuffer_get_modelview_stack (CoglFramebuffer *framebuffer);
|
||||
|
||||
CoglMatrixStack *
|
||||
_cogl_framebuffer_get_projection_stack (CoglFramebuffer *framebuffer);
|
||||
|
||||
void
|
||||
_cogl_framebuffer_add_dependency (CoglFramebuffer *framebuffer,
|
||||
CoglFramebuffer *dependency);
|
||||
|
||||
void
|
||||
_cogl_framebuffer_remove_all_dependencies (CoglFramebuffer *framebuffer);
|
||||
|
||||
void
|
||||
_cogl_framebuffer_flush_journal (CoglFramebuffer *framebuffer);
|
||||
|
||||
void
|
||||
_cogl_framebuffer_flush_dependency_journals (CoglFramebuffer *framebuffer);
|
||||
|
||||
gboolean
|
||||
_cogl_framebuffer_try_fast_read_pixel (CoglFramebuffer *framebuffer,
|
||||
int x,
|
||||
int y,
|
||||
CoglReadPixelsFlags source,
|
||||
CoglPixelFormat format,
|
||||
guint8 *pixel);
|
||||
|
||||
typedef enum _CoglFramebufferFlushFlags
|
||||
{
|
||||
/* XXX: When using this, that imples you are going to manually load the
|
||||
* modelview matrix (via glLoadMatrix). _cogl_matrix_stack_flush_to_gl wont
|
||||
* be called for framebuffer->modelview_stack, and the modelview_stack will
|
||||
* also be marked as dirty. */
|
||||
COGL_FRAMEBUFFER_FLUSH_SKIP_MODELVIEW = 1L<<0,
|
||||
/* Similarly this flag implies you are going to flush the clip state
|
||||
yourself */
|
||||
COGL_FRAMEBUFFER_FLUSH_SKIP_CLIP_STATE = 1L<<1,
|
||||
/* When using this all that will be updated is the glBindFramebuffer
|
||||
* state and corresponding winsys state to make the framebuffer
|
||||
* current if it is a CoglOnscreen framebuffer. */
|
||||
COGL_FRAMEBUFFER_FLUSH_BIND_ONLY = 1L<<2
|
||||
} CoglFramebufferFlushFlags;
|
||||
|
||||
void
|
||||
_cogl_framebuffer_flush_state (CoglFramebuffer *draw_buffer,
|
||||
CoglFramebuffer *read_buffer,
|
||||
CoglFramebufferFlushFlags flags);
|
||||
|
||||
CoglFramebuffer *
|
||||
_cogl_get_read_framebuffer (void);
|
||||
|
||||
GSList *
|
||||
_cogl_create_framebuffer_stack (void);
|
||||
|
||||
void
|
||||
_cogl_free_framebuffer_stack (GSList *stack);
|
||||
|
||||
/*
|
||||
* _cogl_offscreen_new_to_texture_full:
|
||||
* @texhandle: A handle to the texture to target
|
||||
* @create_flags: Flags specifying how to create the FBO
|
||||
* @level: The mipmap level within the texture to target
|
||||
*
|
||||
* Creates a new offscreen buffer which will target the given
|
||||
* texture. By default the buffer will have a depth and stencil
|
||||
* buffer. This can be disabled by passing
|
||||
* %COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL in @create_flags.
|
||||
*
|
||||
* Return value: the new CoglOffscreen object.
|
||||
*/
|
||||
CoglHandle
|
||||
_cogl_offscreen_new_to_texture_full (CoglHandle texhandle,
|
||||
CoglOffscreenFlags create_flags,
|
||||
unsigned int level);
|
||||
|
||||
/*
|
||||
* _cogl_push_framebuffers:
|
||||
* @draw_buffer: A pointer to the buffer used for drawing
|
||||
* @read_buffer: A pointer to the buffer used for reading back pixels
|
||||
*
|
||||
* Redirects drawing and reading to the specified framebuffers as in
|
||||
* cogl_push_framebuffer() except that it allows the draw and read
|
||||
* buffer to be different. The buffers are pushed as a pair so that
|
||||
* they can later both be restored with a single call to
|
||||
* cogl_pop_framebuffer().
|
||||
*/
|
||||
void
|
||||
_cogl_push_framebuffers (CoglFramebuffer *draw_buffer,
|
||||
CoglFramebuffer *read_buffer);
|
||||
|
||||
/*
|
||||
* _cogl_blit_framebuffer:
|
||||
* @src_x: Source x position
|
||||
* @src_y: Source y position
|
||||
* @dst_x: Destination x position
|
||||
* @dst_y: Destination y position
|
||||
* @width: Width of region to copy
|
||||
* @height: Height of region to copy
|
||||
*
|
||||
* This blits a region of the color buffer of the current draw buffer
|
||||
* to the current read buffer. The draw and read buffers can be set up
|
||||
* using _cogl_push_framebuffers(). This function should only be
|
||||
* called if the COGL_FEATURE_OFFSCREEN_BLIT feature is
|
||||
* advertised. The two buffers must both be offscreen and have the
|
||||
* same format.
|
||||
*
|
||||
* Note that this function differs a lot from the glBlitFramebuffer
|
||||
* function provided by the GL_EXT_framebuffer_blit extension. Notably
|
||||
* it doesn't support having different sizes for the source and
|
||||
* destination rectangle. This isn't supported by the corresponding
|
||||
* GL_ANGLE_framebuffer_blit extension on GLES2.0 and it doesn't seem
|
||||
* like a particularly useful feature. If the application wanted to
|
||||
* scale the results it may make more sense to draw a primitive
|
||||
* instead.
|
||||
*
|
||||
* We can only really support blitting between two offscreen buffers
|
||||
* for this function on GLES2.0. This is because we effectively render
|
||||
* upside down to offscreen buffers to maintain Cogl's representation
|
||||
* of the texture coordinate system where 0,0 is the top left of the
|
||||
* texture. If we were to blit from an offscreen to an onscreen buffer
|
||||
* then we would need to mirror the blit along the x-axis but the GLES
|
||||
* extension does not support this.
|
||||
*
|
||||
* The GL function is documented to be affected by the scissor. This
|
||||
* function therefore ensure that an empty clip stack is flushed
|
||||
* before performing the blit which means the scissor is effectively
|
||||
* ignored.
|
||||
*
|
||||
* The function also doesn't support specifying the buffers to copy
|
||||
* and instead only the color buffer is copied. When copying the depth
|
||||
* or stencil buffers the extension on GLES2.0 only supports copying
|
||||
* the full buffer which would be awkward to document with this
|
||||
* API. If we wanted to support that feature it may be better to have
|
||||
* a separate function to copy the entire buffer for a given mask.
|
||||
*/
|
||||
void
|
||||
_cogl_blit_framebuffer (unsigned int src_x,
|
||||
unsigned int src_y,
|
||||
unsigned int dst_x,
|
||||
unsigned int dst_y,
|
||||
unsigned int width,
|
||||
unsigned int height);
|
||||
|
||||
CoglOnscreen *
|
||||
_cogl_onscreen_new (void);
|
||||
|
||||
#endif /* __COGL_FRAMEBUFFER_PRIVATE_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,226 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_FRAMEBUFFER_H
|
||||
#define __COGL_FRAMEBUFFER_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#ifdef COGL_ENABLE_EXPERIMENTAL_API
|
||||
#define cogl_onscreen_new cogl_onscreen_new_EXP
|
||||
|
||||
#define COGL_FRAMEBUFFER(X) ((CoglFramebuffer *)(X))
|
||||
|
||||
#define cogl_framebuffer_allocate cogl_framebuffer_allocate_EXP
|
||||
gboolean
|
||||
cogl_framebuffer_allocate (CoglFramebuffer *framebuffer,
|
||||
GError **error);
|
||||
|
||||
#define cogl_framebuffer_get_width cogl_framebuffer_get_width_EXP
|
||||
int
|
||||
cogl_framebuffer_get_width (CoglFramebuffer *framebuffer);
|
||||
|
||||
#define cogl_framebuffer_get_height cogl_framebuffer_get_height_EXP
|
||||
int
|
||||
cogl_framebuffer_get_height (CoglFramebuffer *framebuffer);
|
||||
|
||||
#define cogl_framebuffer_swap_buffers cogl_framebuffer_swap_buffers_EXP
|
||||
void
|
||||
cogl_framebuffer_swap_buffers (CoglFramebuffer *framebuffer);
|
||||
|
||||
#define cogl_framebuffer_swap_region cogl_framebuffer_swap_region_EXP
|
||||
void
|
||||
cogl_framebuffer_swap_region (CoglFramebuffer *framebuffer,
|
||||
int *rectangles,
|
||||
int n_rectangles);
|
||||
|
||||
|
||||
typedef void (*CoglSwapBuffersNotify) (CoglFramebuffer *framebuffer,
|
||||
void *user_data);
|
||||
|
||||
#define cogl_framebuffer_add_swap_buffers_callback \
|
||||
cogl_framebuffer_add_swap_buffers_callback_EXP
|
||||
unsigned int
|
||||
cogl_framebuffer_add_swap_buffers_callback (CoglFramebuffer *framebuffer,
|
||||
CoglSwapBuffersNotify callback,
|
||||
void *user_data);
|
||||
|
||||
#define cogl_framebuffer_remove_swap_buffers_callback \
|
||||
cogl_framebuffer_remove_swap_buffers_callback_EXP
|
||||
void
|
||||
cogl_framebuffer_remove_swap_buffers_callback (CoglFramebuffer *framebuffer,
|
||||
unsigned int id);
|
||||
|
||||
|
||||
typedef struct _CoglOnscreen CoglOnscreen;
|
||||
#define COGL_ONSCREEN(X) ((CoglOnscreen *)(X))
|
||||
|
||||
CoglOnscreen *
|
||||
cogl_onscreen_new (CoglContext *context, int width, int height);
|
||||
|
||||
#ifdef COGL_HAS_X11
|
||||
typedef void (*CoglOnscreenX11MaskCallback) (CoglOnscreen *onscreen,
|
||||
guint32 event_mask,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* cogl_onscreen_x11_set_foreign_window_xid:
|
||||
* @onscreen: The unallocated framebuffer to associated with an X
|
||||
* window.
|
||||
* @xid: The XID of an existing X window
|
||||
* @update: A callback that notifies of updates to what Cogl requires
|
||||
* to be in the core X protocol event mask.
|
||||
*
|
||||
* Ideally we would recommend that you let Cogl be responsible for
|
||||
* creating any X window required to back an onscreen framebuffer but
|
||||
* if you really need to target a window created manually this
|
||||
* function can be called before @onscreen has been allocated to set a
|
||||
* foreign XID for your existing X window.
|
||||
*
|
||||
* Since Cogl needs, for example, to track changes to the size of an X
|
||||
* window it requires that certain events be selected for via the core
|
||||
* X protocol. This requirement may also be changed asynchronously so
|
||||
* you must pass in an @update callback to inform you of Cogl's
|
||||
* required event mask.
|
||||
*
|
||||
* For example if you are using Xlib you could use this API roughly
|
||||
* as follows:
|
||||
* [{
|
||||
* static void
|
||||
* my_update_cogl_x11_event_mask (CoglOnscreen *onscreen,
|
||||
* guint32 event_mask,
|
||||
* void *user_data)
|
||||
* {
|
||||
* XSetWindowAttributes attrs;
|
||||
* MyData *data = user_data;
|
||||
* attrs.event_mask = event_mask | data->my_event_mask;
|
||||
* XChangeWindowAttributes (data->xdpy,
|
||||
* data->xwin,
|
||||
* CWEventMask,
|
||||
* &attrs);
|
||||
* }
|
||||
*
|
||||
* {
|
||||
* *snip*
|
||||
* cogl_onscreen_x11_set_foreign_window_xid (onscreen,
|
||||
* data->xwin,
|
||||
* my_update_cogl_x11_event_mask,
|
||||
* data);
|
||||
* *snip*
|
||||
* }
|
||||
* }]
|
||||
*
|
||||
* Since: 2.0
|
||||
* Stability: Unstable
|
||||
*/
|
||||
#define cogl_onscreen_x11_set_foreign_window_xid \
|
||||
cogl_onscreen_x11_set_foreign_window_xid_EXP
|
||||
void
|
||||
cogl_onscreen_x11_set_foreign_window_xid (CoglOnscreen *onscreen,
|
||||
guint32 xid,
|
||||
CoglOnscreenX11MaskCallback update,
|
||||
void *user_data);
|
||||
|
||||
#define cogl_onscreen_x11_get_window_xid cogl_onscreen_x11_get_window_xid_EXP
|
||||
guint32
|
||||
cogl_onscreen_x11_get_window_xid (CoglOnscreen *onscreen);
|
||||
|
||||
#define cogl_onscreen_x11_get_visual_xid cogl_onscreen_x11_get_visual_xid_EXP
|
||||
guint32
|
||||
cogl_onscreen_x11_get_visual_xid (CoglOnscreen *onscreen);
|
||||
#endif /* COGL_HAS_X11 */
|
||||
|
||||
#define cogl_onscreen_set_swap_throttled cogl_onscreen_set_swap_throttled_EXP
|
||||
void
|
||||
cogl_onscreen_set_swap_throttled (CoglOnscreen *onscreen,
|
||||
gboolean throttled);
|
||||
|
||||
/**
|
||||
* cogl_onscreen_show:
|
||||
* @onscreen: The onscreen framebuffer to make visible
|
||||
*
|
||||
* This requests to make @onscreen visible to the user.
|
||||
*
|
||||
* Actually the precise semantics of this function depend on the
|
||||
* window system currently in use, and if you don't have a
|
||||
* multi-windowining system this function may in-fact do nothing.
|
||||
*
|
||||
* This function will implicitly allocate the given @onscreen
|
||||
* framebuffer before showing it if it hasn't already been allocated.
|
||||
*
|
||||
* <note>Since Cogl doesn't explicitly track the visibility status of
|
||||
* onscreen framebuffers it wont try to avoid redundant window system
|
||||
* requests e.g. to show an already visible window. This also means
|
||||
* that it's acceptable to alternatively use native APIs to show and
|
||||
* hide windows without confusing Cogl.</note>
|
||||
*
|
||||
* Since: 2.0
|
||||
* Stability: Unstable
|
||||
*/
|
||||
#define cogl_onscreen_show cogl_onscreen_show_EXP
|
||||
void
|
||||
cogl_onscreen_show (CoglOnscreen *onscreen);
|
||||
|
||||
/**
|
||||
* cogl_onscreen_hide:
|
||||
* @onscreen: The onscreen framebuffer to make invisible
|
||||
*
|
||||
* This requests to make @onscreen invisible to the user.
|
||||
*
|
||||
* Actually the precise semantics of this function depend on the
|
||||
* window system currently in use, and if you don't have a
|
||||
* multi-windowining system this function may in-fact do nothing.
|
||||
*
|
||||
* This function does not implicitly allocate the given @onscreen
|
||||
* framebuffer before hiding it.
|
||||
*
|
||||
* <note>Since Cogl doesn't explicitly track the visibility status of
|
||||
* onscreen framebuffers it wont try to avoid redundant window system
|
||||
* requests e.g. to show an already visible window. This also means
|
||||
* that it's acceptable to alternatively use native APIs to show and
|
||||
* hide windows without confusing Cogl.</note>
|
||||
*
|
||||
* Since: 2.0
|
||||
* Stability: Unstable
|
||||
*/
|
||||
#define cogl_onscreen_hide cogl_onscreen_hide_EXP
|
||||
void
|
||||
cogl_onscreen_hide (CoglOnscreen *onscreen);
|
||||
|
||||
#define cogl_get_draw_framebuffer cogl_get_draw_framebuffer_EXP
|
||||
CoglFramebuffer *
|
||||
cogl_get_draw_framebuffer (void);
|
||||
|
||||
#endif /* COGL_ENABLE_EXPERIMENTAL_API */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_FRAMEBUFFER_H */
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#ifndef __COGL_GTYPE_PRIVATE_H__
|
||||
#define __COGL_GTYPE_PRIVATE_H__
|
||||
|
||||
#define COGL_GTYPE_DEFINE_BOXED(Name, underscore_name, copy_func, free_func) \
|
||||
GType \
|
||||
cogl_gtype_ ## underscore_name ## _get_type (void) \
|
||||
{ \
|
||||
static volatile gsize type_volatile = 0; \
|
||||
if (g_once_init_enter (&type_volatile)) \
|
||||
{ \
|
||||
GType type = \
|
||||
g_boxed_type_register_static (g_intern_static_string ("Cogl" Name), \
|
||||
(GBoxedCopyFunc)copy_func, \
|
||||
(GBoxedFreeFunc)free_func); \
|
||||
g_once_init_leave (&type_volatile, type); \
|
||||
} \
|
||||
return type_volatile; \
|
||||
}
|
||||
|
||||
#endif /* __COGL_GTYPE_PRIVATE_H__ */
|
||||
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* This file is just kept for compatability while we eradicate
|
||||
* CoglHandle
|
||||
*/
|
||||
|
||||
#ifndef __COGL_HANDLE_H
|
||||
#define __COGL_HANDLE_H
|
||||
|
||||
#include "cogl-object-private.h"
|
||||
|
||||
#endif /* __COGL_HANDLE_H */
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_INDEX_ARRAY_PRIVATE_H
|
||||
#define __COGL_INDEX_ARRAY_PRIVATE_H
|
||||
|
||||
#include "cogl-buffer-private.h"
|
||||
|
||||
struct _CoglIndexArray
|
||||
{
|
||||
CoglBuffer _parent;
|
||||
};
|
||||
|
||||
#endif /* __COGL_INDEX_ARRAY_PRIVATE_H */
|
||||
|
@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl-object-private.h"
|
||||
#include "cogl-indices.h"
|
||||
#include "cogl-indices-private.h"
|
||||
|
||||
static void _cogl_index_array_free (CoglIndexArray *indices);
|
||||
|
||||
COGL_BUFFER_DEFINE (IndexArray, index_array);
|
||||
|
||||
/* XXX: Unlike the wiki design this just takes a size. A single
|
||||
* indices buffer should be able to contain multiple ranges of indices
|
||||
* which the wiki design doesn't currently consider. */
|
||||
CoglIndexArray *
|
||||
cogl_index_array_new (gsize bytes)
|
||||
{
|
||||
CoglIndexArray *indices = g_slice_new (CoglIndexArray);
|
||||
gboolean use_malloc;
|
||||
|
||||
if (!cogl_features_available (COGL_FEATURE_VBOS))
|
||||
use_malloc = TRUE;
|
||||
else
|
||||
use_malloc = FALSE;
|
||||
|
||||
/* parent's constructor */
|
||||
_cogl_buffer_initialize (COGL_BUFFER (indices),
|
||||
bytes,
|
||||
use_malloc,
|
||||
COGL_BUFFER_BIND_TARGET_INDEX_ARRAY,
|
||||
COGL_BUFFER_USAGE_HINT_INDEX_ARRAY,
|
||||
COGL_BUFFER_UPDATE_HINT_STATIC);
|
||||
|
||||
return _cogl_index_array_object_new (indices);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_index_array_free (CoglIndexArray *indices)
|
||||
{
|
||||
/* parent's destructor */
|
||||
_cogl_buffer_fini (COGL_BUFFER (indices));
|
||||
|
||||
g_slice_free (CoglIndexArray, indices);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_index_array_allocate (CoglIndexArray *indices,
|
||||
GError *error)
|
||||
{
|
||||
/* TODO */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* XXX: do we want a convenience function like this as an alternative
|
||||
* to using cogl_buffer_set_data? The advantage of this is that we can
|
||||
* track meta data such as the indices type and max_index_value for a
|
||||
* range as part of the indices array. If we just leave people to use
|
||||
* cogl_buffer_set_data then we either need a way to specify the type
|
||||
* and max index value at draw time or we'll want a separate way to
|
||||
* declare the type and max value for a range after uploading the
|
||||
* data.
|
||||
*
|
||||
* XXX: I think in the end it'll be that CoglIndices are to
|
||||
* CoglIndexArrays as CoglAttributes are to CoglVertices. I.e
|
||||
* a CoglIndexArray is a lite subclass of CoglBuffer that simply
|
||||
* implies that the buffer will later be bound as indices but doesn't
|
||||
* track more detailed meta data. CoglIndices build on a
|
||||
* CoglIndexArray and define the type and max_index_value for some
|
||||
* sub-range of a CoglIndexArray.
|
||||
*
|
||||
* XXX: The double plurel form that "Indices" "Array" implies could be
|
||||
* a bit confusing. Also to be a bit more consistent with
|
||||
* CoglVertexArray vs CoglAttribute it might be best to rename so
|
||||
* we have CoglIndexArray vs CoglIndices? maybe even
|
||||
* CoglIndexRange :-/ ?
|
||||
*
|
||||
* CoglBuffer
|
||||
* CoglVertexArray (buffer sub-class)
|
||||
* CoglPrimitive (defines meta data for sub-region of array)
|
||||
* CoglPixelArray (buffer sub-class)
|
||||
* CoglIndexArray (buffer sub-class)
|
||||
* CoglIndices (defines meta data for sub-region of array)
|
||||
*
|
||||
*/
|
||||
#if 0
|
||||
void
|
||||
cogl_index_array_set_data (CoglIndexArray *indices,
|
||||
CoglIndicesType type,
|
||||
int max_index_value,
|
||||
gsize write_offset,
|
||||
void *user_indices,
|
||||
int n_indices)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = indices->ranges; l; l = l->next)
|
||||
{
|
||||
|
||||
}
|
||||
cogl_buffer_set
|
||||
}
|
||||
#endif
|
||||
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_INDEX_ARRAY_H__
|
||||
#define __COGL_INDEX_ARRAY_H__
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-vertex-indices
|
||||
* @short_description: Functions for creating and manipulating vertex
|
||||
* indices.
|
||||
*
|
||||
* FIXME
|
||||
*/
|
||||
|
||||
typedef struct _CoglIndexArray CoglIndexArray;
|
||||
|
||||
/**
|
||||
* cogl_index_array_new:
|
||||
* @bytes: The number of bytes to allocate for vertex attribute data.
|
||||
*
|
||||
* Declares a new #CoglIndexArray of @size bytes to contain vertex
|
||||
* indices. Once declared, data can be set using
|
||||
* cogl_buffer_set_data() or by mapping it into the application's
|
||||
* address space using cogl_buffer_map().
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
CoglIndexArray *
|
||||
cogl_index_array_new (gsize bytes);
|
||||
|
||||
/**
|
||||
* cogl_is_indices_array:
|
||||
* @object: A #CoglObject
|
||||
*
|
||||
* Gets whether the given object references a #CoglIndexArray.
|
||||
*
|
||||
* Returns: %TRUE if the handle references a #CoglIndexArray,
|
||||
* %FALSE otherwise
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
gboolean
|
||||
cogl_is_indices_array (void *object);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_INDEX_ARRAY_H__ */
|
||||
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_INDICES_PRIVATE_H
|
||||
#define __COGL_INDICES_PRIVATE_H
|
||||
|
||||
#include "cogl-object-private.h"
|
||||
#include "cogl-index-array-private.h"
|
||||
#include "cogl-types.h"
|
||||
|
||||
struct _CoglIndices
|
||||
{
|
||||
CoglObject _parent;
|
||||
|
||||
CoglIndexArray *array;
|
||||
size_t offset;
|
||||
|
||||
CoglIndicesType type;
|
||||
|
||||
int immutable_ref;
|
||||
};
|
||||
|
||||
CoglIndices *
|
||||
_cogl_indices_immutable_ref (CoglIndices *indices);
|
||||
|
||||
void
|
||||
_cogl_indices_immutable_unref (CoglIndices *indices);
|
||||
|
||||
#endif /* __COGL_INDICES_PRIVATE_H */
|
||||
|
@ -1,253 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
* Neil Roberts <neil@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl-object-private.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-indices.h"
|
||||
#include "cogl-indices-private.h"
|
||||
#include "cogl-index-array.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
static void _cogl_indices_free (CoglIndices *indices);
|
||||
|
||||
COGL_OBJECT_DEFINE (Indices, indices);
|
||||
|
||||
static size_t
|
||||
sizeof_indices_type (CoglIndicesType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case COGL_INDICES_TYPE_UNSIGNED_BYTE:
|
||||
return 1;
|
||||
case COGL_INDICES_TYPE_UNSIGNED_SHORT:
|
||||
return 2;
|
||||
case COGL_INDICES_TYPE_UNSIGNED_INT:
|
||||
return 4;
|
||||
}
|
||||
g_return_val_if_reached (0);
|
||||
}
|
||||
|
||||
CoglIndices *
|
||||
cogl_indices_new_for_array (CoglIndicesType type,
|
||||
CoglIndexArray *array,
|
||||
gsize offset)
|
||||
{
|
||||
CoglIndices *indices = g_slice_new (CoglIndices);
|
||||
|
||||
indices->array = cogl_object_ref (array);
|
||||
indices->offset = offset;
|
||||
|
||||
indices->type = type;
|
||||
|
||||
indices->immutable_ref = 0;
|
||||
|
||||
return _cogl_indices_object_new (indices);
|
||||
}
|
||||
|
||||
CoglIndices *
|
||||
cogl_indices_new (CoglIndicesType type,
|
||||
const void *indices_data,
|
||||
int n_indices)
|
||||
{
|
||||
size_t array_bytes = sizeof_indices_type (type) * n_indices;
|
||||
CoglIndexArray *array = cogl_index_array_new (array_bytes);
|
||||
CoglBuffer *buffer = COGL_BUFFER (array);
|
||||
CoglIndices *indices;
|
||||
|
||||
cogl_buffer_set_data (buffer,
|
||||
0,
|
||||
indices_data,
|
||||
array_bytes);
|
||||
|
||||
indices = cogl_indices_new_for_array (type, array, 0);
|
||||
cogl_object_unref (array);
|
||||
|
||||
return indices;
|
||||
}
|
||||
|
||||
CoglIndexArray *
|
||||
cogl_indices_get_array (CoglIndices *indices)
|
||||
{
|
||||
return indices->array;
|
||||
}
|
||||
|
||||
CoglIndicesType
|
||||
cogl_indices_get_type (CoglIndices *indices)
|
||||
{
|
||||
g_return_val_if_fail (cogl_is_indices (indices),
|
||||
COGL_INDICES_TYPE_UNSIGNED_BYTE);
|
||||
return indices->type;
|
||||
}
|
||||
|
||||
gsize
|
||||
cogl_indices_get_offset (CoglIndices *indices)
|
||||
{
|
||||
g_return_val_if_fail (cogl_is_indices (indices), 0);
|
||||
|
||||
return indices->offset;
|
||||
}
|
||||
|
||||
static void
|
||||
warn_about_midscene_changes (void)
|
||||
{
|
||||
static gboolean seen = FALSE;
|
||||
if (!seen)
|
||||
{
|
||||
g_warning ("Mid-scene modification of indices has "
|
||||
"undefined results\n");
|
||||
seen = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cogl_indices_set_offset (CoglIndices *indices,
|
||||
gsize offset)
|
||||
{
|
||||
g_return_if_fail (cogl_is_indices (indices));
|
||||
|
||||
if (G_UNLIKELY (indices->immutable_ref))
|
||||
warn_about_midscene_changes ();
|
||||
|
||||
indices->offset = offset;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_indices_free (CoglIndices *indices)
|
||||
{
|
||||
cogl_object_unref (indices->array);
|
||||
g_slice_free (CoglIndices, indices);
|
||||
}
|
||||
|
||||
CoglIndices *
|
||||
_cogl_indices_immutable_ref (CoglIndices *indices)
|
||||
{
|
||||
g_return_val_if_fail (cogl_is_indices (indices), NULL);
|
||||
|
||||
indices->immutable_ref++;
|
||||
_cogl_buffer_immutable_ref (COGL_BUFFER (indices->array));
|
||||
return indices;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_indices_immutable_unref (CoglIndices *indices)
|
||||
{
|
||||
g_return_if_fail (cogl_is_indices (indices));
|
||||
g_return_if_fail (indices->immutable_ref > 0);
|
||||
|
||||
indices->immutable_ref--;
|
||||
_cogl_buffer_immutable_unref (COGL_BUFFER (indices->array));
|
||||
}
|
||||
|
||||
CoglIndices *
|
||||
cogl_get_rectangle_indices (int n_rectangles)
|
||||
{
|
||||
int n_indices = n_rectangles * 6;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
|
||||
/* Check if the largest index required will fit in a byte array... */
|
||||
if (n_indices <= 256 / 4 * 6)
|
||||
{
|
||||
/* Generate the byte array if we haven't already */
|
||||
if (ctx->rectangle_byte_indices == NULL)
|
||||
{
|
||||
guint8 *byte_array = g_malloc (256 / 4 * 6 * sizeof (guint8));
|
||||
guint8 *p = byte_array;
|
||||
int i, vert_num = 0;
|
||||
|
||||
for (i = 0; i < 256 / 4; i++)
|
||||
{
|
||||
*(p++) = vert_num + 0;
|
||||
*(p++) = vert_num + 1;
|
||||
*(p++) = vert_num + 2;
|
||||
*(p++) = vert_num + 0;
|
||||
*(p++) = vert_num + 2;
|
||||
*(p++) = vert_num + 3;
|
||||
vert_num += 4;
|
||||
}
|
||||
|
||||
ctx->rectangle_byte_indices
|
||||
= cogl_indices_new (COGL_INDICES_TYPE_UNSIGNED_BYTE,
|
||||
byte_array,
|
||||
256 / 4 * 6);
|
||||
|
||||
g_free (byte_array);
|
||||
}
|
||||
|
||||
return ctx->rectangle_byte_indices;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctx->rectangle_short_indices_len < n_indices)
|
||||
{
|
||||
guint16 *short_array;
|
||||
guint16 *p;
|
||||
int i, vert_num = 0;
|
||||
|
||||
if (ctx->rectangle_short_indices != NULL)
|
||||
cogl_object_unref (ctx->rectangle_short_indices);
|
||||
/* Pick a power of two >= MAX (512, n_indices) */
|
||||
if (ctx->rectangle_short_indices_len == 0)
|
||||
ctx->rectangle_short_indices_len = 512;
|
||||
while (ctx->rectangle_short_indices_len < n_indices)
|
||||
ctx->rectangle_short_indices_len *= 2;
|
||||
|
||||
/* Over-allocate to generate a whole number of quads */
|
||||
p = short_array = g_malloc ((ctx->rectangle_short_indices_len
|
||||
+ 5) / 6 * 6
|
||||
* sizeof (guint16));
|
||||
|
||||
/* Fill in the complete quads */
|
||||
for (i = 0; i < ctx->rectangle_short_indices_len; i += 6)
|
||||
{
|
||||
*(p++) = vert_num + 0;
|
||||
*(p++) = vert_num + 1;
|
||||
*(p++) = vert_num + 2;
|
||||
*(p++) = vert_num + 0;
|
||||
*(p++) = vert_num + 2;
|
||||
*(p++) = vert_num + 3;
|
||||
vert_num += 4;
|
||||
}
|
||||
|
||||
ctx->rectangle_short_indices
|
||||
= cogl_indices_new (COGL_INDICES_TYPE_UNSIGNED_SHORT,
|
||||
short_array,
|
||||
ctx->rectangle_short_indices_len);
|
||||
|
||||
g_free (short_array);
|
||||
}
|
||||
|
||||
return ctx->rectangle_short_indices;
|
||||
}
|
||||
}
|
||||
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_INDICES_H__
|
||||
#define __COGL_INDICES_H__
|
||||
|
||||
#include <cogl/cogl-index-array.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-index-range
|
||||
* @short_description: Fuctions for declaring a range of vertex indices
|
||||
* stored in a #CoglIndexArray.
|
||||
*
|
||||
* FIXME
|
||||
*/
|
||||
|
||||
typedef struct _CoglIndices CoglIndices;
|
||||
|
||||
CoglIndices *
|
||||
cogl_indices_new (CoglIndicesType type,
|
||||
const void *indices_data,
|
||||
int n_indices);
|
||||
|
||||
CoglIndices *
|
||||
cogl_indices_new_for_array (CoglIndicesType type,
|
||||
CoglIndexArray *array,
|
||||
gsize offset);
|
||||
|
||||
CoglIndexArray *
|
||||
cogl_indices_get_array (CoglIndices *indices);
|
||||
|
||||
CoglIndicesType
|
||||
cogl_indices_get_type (CoglIndices *indices);
|
||||
|
||||
gsize
|
||||
cogl_indices_get_offset (CoglIndices *indices);
|
||||
|
||||
void
|
||||
cogl_indices_set_offset (CoglIndices *indices,
|
||||
gsize offset);
|
||||
|
||||
CoglIndices *
|
||||
cogl_get_rectangle_indices (int n_rectangles);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_INDICES_H__ */
|
||||
|
@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_INTERNAL_H
|
||||
#define __COGL_INTERNAL_H
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-matrix-stack.h"
|
||||
#include "cogl-bitmask.h"
|
||||
|
||||
#ifdef COGL_HAS_XLIB_SUPPORT
|
||||
#include <X11/Xutil.h>
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COGL_FRONT_WINDING_CLOCKWISE,
|
||||
COGL_FRONT_WINDING_COUNTER_CLOCKWISE
|
||||
} CoglFrontWinding;
|
||||
|
||||
typedef enum {
|
||||
COGL_BOXED_NONE,
|
||||
COGL_BOXED_INT,
|
||||
COGL_BOXED_FLOAT,
|
||||
COGL_BOXED_MATRIX
|
||||
} CoglBoxedType;
|
||||
|
||||
typedef struct _CoglBoxedValue
|
||||
{
|
||||
CoglBoxedType type;
|
||||
int size, count;
|
||||
gboolean transpose;
|
||||
|
||||
union {
|
||||
float float_value[4];
|
||||
int int_value[4];
|
||||
float matrix[16];
|
||||
float *float_array;
|
||||
int *int_array;
|
||||
void *array;
|
||||
} v;
|
||||
} CoglBoxedValue;
|
||||
|
||||
#ifdef COGL_GL_DEBUG
|
||||
|
||||
const char *
|
||||
cogl_gl_error_to_string (GLenum error_code);
|
||||
|
||||
#define GE(x) G_STMT_START { \
|
||||
GLenum __err; \
|
||||
(x); \
|
||||
while ((__err = glGetError ()) != GL_NO_ERROR) \
|
||||
{ \
|
||||
g_warning ("%s: GL error (%d): %s\n", \
|
||||
G_STRLOC, \
|
||||
__err, \
|
||||
cogl_gl_error_to_string (__err)); \
|
||||
} } G_STMT_END
|
||||
|
||||
#define GE_RET(ret, x) G_STMT_START { \
|
||||
GLenum __err; \
|
||||
ret = (x); \
|
||||
while ((__err = glGetError ()) != GL_NO_ERROR) \
|
||||
{ \
|
||||
g_warning ("%s: GL error (%d): %s\n", \
|
||||
G_STRLOC, \
|
||||
__err, \
|
||||
cogl_gl_error_to_string (__err)); \
|
||||
} } G_STMT_END
|
||||
|
||||
#else /* !COGL_GL_DEBUG */
|
||||
|
||||
#define GE(x) (x)
|
||||
#define GE_RET(ret, x) (ret = (x))
|
||||
|
||||
#endif /* COGL_GL_DEBUG */
|
||||
|
||||
#define COGL_ENABLE_ALPHA_TEST (1<<1)
|
||||
#define COGL_ENABLE_VERTEX_ARRAY (1<<2)
|
||||
#define COGL_ENABLE_COLOR_ARRAY (1<<3)
|
||||
#define COGL_ENABLE_BACKFACE_CULLING (1<<4)
|
||||
|
||||
int
|
||||
_cogl_get_format_bpp (CoglPixelFormat format);
|
||||
|
||||
void
|
||||
_cogl_enable (unsigned long flags);
|
||||
|
||||
unsigned long
|
||||
_cogl_get_enable (void);
|
||||
|
||||
void
|
||||
_cogl_flush_face_winding (void);
|
||||
|
||||
void
|
||||
_cogl_transform_point (const CoglMatrix *matrix_mv,
|
||||
const CoglMatrix *matrix_p,
|
||||
const float *viewport,
|
||||
float *x,
|
||||
float *y);
|
||||
|
||||
#define COGL_DRIVER_ERROR (_cogl_driver_error_quark ())
|
||||
|
||||
typedef enum { /*< prefix=COGL_DRIVER_ERROR >*/
|
||||
COGL_DRIVER_ERROR_UNKNOWN_VERSION,
|
||||
COGL_DRIVER_ERROR_INVALID_VERSION
|
||||
} CoglDriverError;
|
||||
|
||||
gboolean
|
||||
_cogl_check_extension (const char *name, const char *ext);
|
||||
|
||||
GQuark
|
||||
_cogl_driver_error_quark (void);
|
||||
|
||||
#endif /* __COGL_INTERNAL_H */
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_JOURNAL_PRIVATE_H
|
||||
#define __COGL_JOURNAL_PRIVATE_H
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-clip-stack.h"
|
||||
|
||||
typedef struct _CoglJournal
|
||||
{
|
||||
CoglObject _parent;
|
||||
|
||||
GArray *entries;
|
||||
GArray *vertices;
|
||||
size_t needed_vbo_len;
|
||||
|
||||
int fast_read_pixel_count;
|
||||
|
||||
} CoglJournal;
|
||||
|
||||
/* To improve batching of geometry when submitting vertices to OpenGL we
|
||||
* log the texture rectangles we want to draw to a journal, so when we
|
||||
* later flush the journal we aim to batch data, and gl draw calls. */
|
||||
typedef struct _CoglJournalEntry
|
||||
{
|
||||
CoglPipeline *pipeline;
|
||||
int n_layers;
|
||||
CoglMatrix model_view;
|
||||
CoglClipStack *clip_stack;
|
||||
/* Offset into ctx->logged_vertices */
|
||||
size_t array_offset;
|
||||
/* XXX: These entries are pretty big now considering the padding in
|
||||
* CoglPipelineFlushOptions and CoglMatrix, so we might need to optimize this
|
||||
* later. */
|
||||
} CoglJournalEntry;
|
||||
|
||||
CoglJournal *
|
||||
_cogl_journal_new (void);
|
||||
|
||||
void
|
||||
_cogl_journal_log_quad (CoglJournal *journal,
|
||||
const float *position,
|
||||
CoglPipeline *pipeline,
|
||||
int n_layers,
|
||||
CoglHandle layer0_override_texture,
|
||||
const float *tex_coords,
|
||||
unsigned int tex_coords_len);
|
||||
|
||||
void
|
||||
_cogl_journal_flush (CoglJournal *journal,
|
||||
CoglFramebuffer *framebuffer);
|
||||
|
||||
void
|
||||
_cogl_journal_discard (CoglJournal *journal);
|
||||
|
||||
gboolean
|
||||
_cogl_journal_all_entries_within_bounds (CoglJournal *journal,
|
||||
float clip_x0,
|
||||
float clip_y0,
|
||||
float clip_x1,
|
||||
float clip_y1);
|
||||
|
||||
gboolean
|
||||
_cogl_journal_try_read_pixel (CoglJournal *journal,
|
||||
int x,
|
||||
int y,
|
||||
CoglPixelFormat format,
|
||||
guint8 *pixel,
|
||||
gboolean *found_intersection);
|
||||
|
||||
#endif /* __COGL_JOURNAL_PRIVATE_H */
|
File diff suppressed because it is too large
Load Diff
@ -1,495 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cogl.h>
|
||||
#include <cogl-material-compat.h>
|
||||
#include <cogl-pipeline.h>
|
||||
#include <cogl-pipeline-private.h>
|
||||
#include <cogl-types.h>
|
||||
#include <cogl-matrix.h>
|
||||
#include <cogl-context-private.h>
|
||||
|
||||
CoglMaterial *
|
||||
cogl_material_new (void)
|
||||
{
|
||||
return COGL_MATERIAL (cogl_pipeline_new ());
|
||||
}
|
||||
|
||||
CoglMaterial *
|
||||
cogl_material_copy (CoglMaterial *source)
|
||||
{
|
||||
return COGL_MATERIAL (cogl_pipeline_copy (COGL_PIPELINE (source)));
|
||||
}
|
||||
|
||||
CoglHandle
|
||||
cogl_material_ref (CoglHandle handle)
|
||||
{
|
||||
return cogl_object_ref (handle);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_unref (CoglHandle handle)
|
||||
{
|
||||
cogl_object_unref (handle);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_is_material (CoglHandle handle)
|
||||
{
|
||||
return cogl_is_pipeline (handle);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_color (CoglMaterial *material,
|
||||
const CoglColor *color)
|
||||
{
|
||||
cogl_pipeline_set_color (COGL_PIPELINE (material), color);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_color4ub (CoglMaterial *material,
|
||||
guint8 red,
|
||||
guint8 green,
|
||||
guint8 blue,
|
||||
guint8 alpha)
|
||||
{
|
||||
cogl_pipeline_set_color4ub (COGL_PIPELINE (material),
|
||||
red, green, blue, alpha);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_color4f (CoglMaterial *material,
|
||||
float red,
|
||||
float green,
|
||||
float blue,
|
||||
float alpha)
|
||||
{
|
||||
cogl_pipeline_set_color4f (COGL_PIPELINE (material),
|
||||
red, green, blue, alpha);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_get_color (CoglMaterial *material,
|
||||
CoglColor *color)
|
||||
{
|
||||
cogl_pipeline_get_color (COGL_PIPELINE (material), color);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_ambient (CoglMaterial *material,
|
||||
const CoglColor *ambient)
|
||||
{
|
||||
cogl_pipeline_set_ambient (COGL_PIPELINE (material), ambient);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_get_ambient (CoglMaterial *material,
|
||||
CoglColor *ambient)
|
||||
{
|
||||
cogl_pipeline_get_ambient (COGL_PIPELINE (material), ambient);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_diffuse (CoglMaterial *material,
|
||||
const CoglColor *diffuse)
|
||||
{
|
||||
cogl_pipeline_set_diffuse (COGL_PIPELINE (material), diffuse);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_get_diffuse (CoglMaterial *material,
|
||||
CoglColor *diffuse)
|
||||
{
|
||||
cogl_pipeline_get_diffuse (COGL_PIPELINE (material), diffuse);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_ambient_and_diffuse (CoglMaterial *material,
|
||||
const CoglColor *color)
|
||||
{
|
||||
cogl_pipeline_set_ambient_and_diffuse (COGL_PIPELINE (material), color);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_specular (CoglMaterial *material,
|
||||
const CoglColor *specular)
|
||||
{
|
||||
cogl_pipeline_set_specular (COGL_PIPELINE (material), specular);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_get_specular (CoglMaterial *material,
|
||||
CoglColor *specular)
|
||||
{
|
||||
cogl_pipeline_get_specular (COGL_PIPELINE (material), specular);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_shininess (CoglMaterial *material,
|
||||
float shininess)
|
||||
{
|
||||
cogl_pipeline_set_shininess (COGL_PIPELINE (material), shininess);
|
||||
}
|
||||
|
||||
float
|
||||
cogl_material_get_shininess (CoglMaterial *material)
|
||||
{
|
||||
return cogl_pipeline_get_shininess (COGL_PIPELINE (material));
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_emission (CoglMaterial *material,
|
||||
const CoglColor *emission)
|
||||
{
|
||||
cogl_pipeline_set_emission (COGL_PIPELINE (material), emission);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_get_emission (CoglMaterial *material,
|
||||
CoglColor *emission)
|
||||
{
|
||||
cogl_pipeline_get_emission (COGL_PIPELINE (material), emission);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_alpha_test_function (CoglMaterial *material,
|
||||
CoglMaterialAlphaFunc alpha_func,
|
||||
float alpha_reference)
|
||||
{
|
||||
cogl_pipeline_set_alpha_test_function (COGL_PIPELINE (material),
|
||||
alpha_func,
|
||||
alpha_reference);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_material_set_blend (CoglMaterial *material,
|
||||
const char *blend_string,
|
||||
GError **error)
|
||||
{
|
||||
return cogl_pipeline_set_blend (COGL_PIPELINE (material),
|
||||
blend_string,
|
||||
error);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_blend_constant (CoglMaterial *material,
|
||||
const CoglColor *constant_color)
|
||||
{
|
||||
cogl_pipeline_set_blend_constant (COGL_PIPELINE (material), constant_color);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_point_size (CoglMaterial *material,
|
||||
float point_size)
|
||||
{
|
||||
cogl_pipeline_set_point_size (COGL_PIPELINE (material), point_size);
|
||||
}
|
||||
|
||||
float
|
||||
cogl_material_get_point_size (CoglMaterial *material)
|
||||
{
|
||||
return cogl_pipeline_get_point_size (COGL_PIPELINE (material));
|
||||
}
|
||||
|
||||
CoglHandle
|
||||
cogl_material_get_user_program (CoglMaterial *material)
|
||||
{
|
||||
return cogl_pipeline_get_user_program (COGL_PIPELINE (material));
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_user_program (CoglMaterial *material,
|
||||
CoglHandle program)
|
||||
{
|
||||
cogl_pipeline_set_user_program (COGL_PIPELINE (material), program);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_layer (CoglMaterial *material,
|
||||
int layer_index,
|
||||
CoglHandle texture)
|
||||
{
|
||||
cogl_pipeline_set_layer_texture (COGL_PIPELINE (material),
|
||||
layer_index, texture);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_remove_layer (CoglMaterial *material,
|
||||
int layer_index)
|
||||
{
|
||||
cogl_pipeline_remove_layer (COGL_PIPELINE (material), layer_index);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_material_set_layer_combine (CoglMaterial *material,
|
||||
int layer_index,
|
||||
const char *blend_string,
|
||||
GError **error)
|
||||
{
|
||||
return cogl_pipeline_set_layer_combine (COGL_PIPELINE (material),
|
||||
layer_index,
|
||||
blend_string,
|
||||
error);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_layer_combine_constant (CoglMaterial *material,
|
||||
int layer_index,
|
||||
const CoglColor *constant)
|
||||
{
|
||||
cogl_pipeline_set_layer_combine_constant (COGL_PIPELINE (material),
|
||||
layer_index,
|
||||
constant);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_layer_matrix (CoglMaterial *material,
|
||||
int layer_index,
|
||||
const CoglMatrix *matrix)
|
||||
{
|
||||
cogl_pipeline_set_layer_matrix (COGL_PIPELINE (material),
|
||||
layer_index, matrix);
|
||||
}
|
||||
|
||||
G_CONST_RETURN GList *
|
||||
cogl_material_get_layers (CoglMaterial *material)
|
||||
{
|
||||
return _cogl_pipeline_get_layers (COGL_PIPELINE (material));
|
||||
}
|
||||
|
||||
int
|
||||
cogl_material_get_n_layers (CoglMaterial *material)
|
||||
{
|
||||
return cogl_pipeline_get_n_layers (COGL_PIPELINE (material));
|
||||
}
|
||||
|
||||
CoglMaterialLayerType
|
||||
cogl_material_layer_get_type (CoglMaterialLayer *layer)
|
||||
{
|
||||
return COGL_MATERIAL_LAYER_TYPE_TEXTURE;
|
||||
}
|
||||
|
||||
CoglHandle
|
||||
cogl_material_layer_get_texture (CoglMaterialLayer *layer)
|
||||
{
|
||||
return _cogl_pipeline_layer_get_texture (COGL_PIPELINE_LAYER (layer));
|
||||
}
|
||||
|
||||
CoglMaterialFilter
|
||||
cogl_material_layer_get_min_filter (CoglMaterialLayer *layer)
|
||||
{
|
||||
return _cogl_pipeline_layer_get_min_filter (COGL_PIPELINE_LAYER (layer));
|
||||
}
|
||||
|
||||
CoglMaterialFilter
|
||||
cogl_material_layer_get_mag_filter (CoglMaterialLayer *layer)
|
||||
{
|
||||
return _cogl_pipeline_layer_get_mag_filter (COGL_PIPELINE_LAYER (layer));
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_layer_filters (CoglMaterial *material,
|
||||
int layer_index,
|
||||
CoglMaterialFilter min_filter,
|
||||
CoglMaterialFilter mag_filter)
|
||||
{
|
||||
cogl_pipeline_set_layer_filters (COGL_PIPELINE (material),
|
||||
layer_index,
|
||||
min_filter,
|
||||
mag_filter);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_material_set_layer_point_sprite_coords_enabled (CoglMaterial *material,
|
||||
int layer_index,
|
||||
gboolean enable,
|
||||
GError **error)
|
||||
{
|
||||
CoglPipeline *pipeline = COGL_PIPELINE (material);
|
||||
return cogl_pipeline_set_layer_point_sprite_coords_enabled (pipeline,
|
||||
layer_index,
|
||||
enable,
|
||||
error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_material_get_layer_point_sprite_coords_enabled (CoglMaterial *material,
|
||||
int layer_index)
|
||||
{
|
||||
CoglPipeline *pipeline = COGL_PIPELINE (material);
|
||||
return cogl_pipeline_get_layer_point_sprite_coords_enabled (pipeline,
|
||||
layer_index);
|
||||
}
|
||||
|
||||
CoglMaterialWrapMode
|
||||
cogl_material_get_layer_wrap_mode_s (CoglMaterial *material,
|
||||
int layer_index)
|
||||
{
|
||||
return cogl_pipeline_get_layer_wrap_mode_s (COGL_PIPELINE (material),
|
||||
layer_index);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_layer_wrap_mode_s (CoglMaterial *material,
|
||||
int layer_index,
|
||||
CoglMaterialWrapMode mode)
|
||||
{
|
||||
cogl_pipeline_set_layer_wrap_mode_s (COGL_PIPELINE (material), layer_index,
|
||||
mode);
|
||||
}
|
||||
|
||||
CoglMaterialWrapMode
|
||||
cogl_material_get_layer_wrap_mode_t (CoglMaterial *material,
|
||||
int layer_index)
|
||||
{
|
||||
return cogl_pipeline_get_layer_wrap_mode_t (COGL_PIPELINE (material),
|
||||
layer_index);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_layer_wrap_mode_t (CoglMaterial *material,
|
||||
int layer_index,
|
||||
CoglMaterialWrapMode mode)
|
||||
{
|
||||
cogl_pipeline_set_layer_wrap_mode_t (COGL_PIPELINE (material), layer_index,
|
||||
mode);
|
||||
}
|
||||
|
||||
CoglMaterialWrapMode
|
||||
cogl_material_get_layer_wrap_mode_p (CoglMaterial *material,
|
||||
int layer_index)
|
||||
{
|
||||
return cogl_pipeline_get_layer_wrap_mode_p (COGL_PIPELINE (material),
|
||||
layer_index);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_layer_wrap_mode_p (CoglMaterial *material,
|
||||
int layer_index,
|
||||
CoglMaterialWrapMode mode)
|
||||
{
|
||||
cogl_pipeline_set_layer_wrap_mode_p (COGL_PIPELINE (material), layer_index,
|
||||
mode);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_layer_wrap_mode (CoglMaterial *material,
|
||||
int layer_index,
|
||||
CoglMaterialWrapMode mode)
|
||||
{
|
||||
cogl_pipeline_set_layer_wrap_mode (COGL_PIPELINE (material), layer_index,
|
||||
mode);
|
||||
}
|
||||
|
||||
CoglMaterialWrapMode
|
||||
cogl_material_layer_get_wrap_mode_s (CoglMaterialLayer *layer)
|
||||
{
|
||||
return _cogl_pipeline_layer_get_wrap_mode_s (COGL_PIPELINE_LAYER (layer));
|
||||
}
|
||||
|
||||
CoglMaterialWrapMode
|
||||
cogl_material_layer_get_wrap_mode_t (CoglMaterialLayer *layer)
|
||||
{
|
||||
return _cogl_pipeline_layer_get_wrap_mode_t (COGL_PIPELINE_LAYER (layer));
|
||||
}
|
||||
|
||||
CoglMaterialWrapMode
|
||||
cogl_material_layer_get_wrap_mode_p (CoglMaterialLayer *layer)
|
||||
{
|
||||
return _cogl_pipeline_layer_get_wrap_mode_p (COGL_PIPELINE_LAYER (layer));
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_depth_test_enabled (CoglMaterial *material,
|
||||
gboolean enable)
|
||||
{
|
||||
cogl_pipeline_set_depth_test_enabled (COGL_PIPELINE (material), enable);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_material_get_depth_test_enabled (CoglMaterial *material)
|
||||
{
|
||||
return cogl_pipeline_get_depth_test_enabled (COGL_PIPELINE (material));
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_depth_writing_enabled (CoglMaterial *material,
|
||||
gboolean enable)
|
||||
{
|
||||
cogl_pipeline_set_depth_writing_enabled (COGL_PIPELINE (material), enable);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_material_get_depth_writing_enabled (CoglMaterial *material)
|
||||
{
|
||||
return cogl_pipeline_get_depth_writing_enabled (COGL_PIPELINE (material));
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_set_depth_test_function (CoglMaterial *material,
|
||||
CoglDepthTestFunction function)
|
||||
{
|
||||
cogl_pipeline_set_depth_test_function (COGL_PIPELINE (material), function);
|
||||
}
|
||||
|
||||
CoglDepthTestFunction
|
||||
cogl_material_get_depth_test_function (CoglMaterial *material)
|
||||
{
|
||||
return cogl_pipeline_get_depth_test_function (COGL_PIPELINE (material));
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_material_set_depth_range (CoglMaterial *material,
|
||||
float near_val,
|
||||
float far_val,
|
||||
GError **error)
|
||||
{
|
||||
return cogl_pipeline_set_depth_range (COGL_PIPELINE (material),
|
||||
near_val, far_val, error);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_get_depth_range (CoglMaterial *material,
|
||||
float *near_val,
|
||||
float *far_val)
|
||||
{
|
||||
cogl_pipeline_get_depth_range (COGL_PIPELINE (material), near_val, far_val);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_material_foreach_layer (CoglMaterial *material,
|
||||
CoglMaterialLayerCallback callback,
|
||||
void *user_data)
|
||||
{
|
||||
cogl_pipeline_foreach_layer (COGL_PIPELINE (material),
|
||||
(CoglPipelineLayerCallback)callback, user_data);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,226 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 1999-2005 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 math/m_matrix.h
|
||||
* Defines basic structures for matrix-handling.
|
||||
*/
|
||||
|
||||
#ifndef _M_MATRIX_H
|
||||
#define _M_MATRIX_H
|
||||
|
||||
#include <cogl-matrix.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/*
|
||||
* \name Symbolic names to some of the entries in the matrix
|
||||
*
|
||||
* These are handy for the viewport mapping, which is expressed as a matrix.
|
||||
*/
|
||||
/*@{*/
|
||||
#define MAT_SX 0
|
||||
#define MAT_SY 5
|
||||
#define MAT_SZ 10
|
||||
#define MAT_TX 12
|
||||
#define MAT_TY 13
|
||||
#define MAT_TZ 14
|
||||
/*@}*/
|
||||
|
||||
|
||||
/*
|
||||
* Different kinds of 4x4 transformation matrices.
|
||||
* We use these to select specific optimized vertex transformation routines.
|
||||
*/
|
||||
enum CoglMatrixType {
|
||||
COGL_MATRIX_TYPE_GENERAL, /**< general 4x4 matrix */
|
||||
COGL_MATRIX_TYPE_IDENTITY, /**< identity matrix */
|
||||
COGL_MATRIX_TYPE_3D_NO_ROT, /**< orthogonal projection and others... */
|
||||
COGL_MATRIX_TYPE_PERSPECTIVE, /**< perspective projection matrix */
|
||||
COGL_MATRIX_TYPE_2D, /**< 2-D transformation */
|
||||
COGL_MATRIX_TYPE_2D_NO_ROT, /**< 2-D scale & translate only */
|
||||
COGL_MATRIX_TYPE_3D /**< 3-D transformation */
|
||||
} ;
|
||||
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Matrix type to represent 4x4 transformation matrices.
|
||||
*/
|
||||
typedef struct {
|
||||
float *m; /**< 16 matrix elements (16-byte aligned) */
|
||||
float *inv; /**< optional 16-element inverse (16-byte aligned) */
|
||||
unsigned int flags; /**< possible values determined by (of \link
|
||||
* MatFlags MAT_FLAG_* flags\endlink)
|
||||
*/
|
||||
enum CoglMatrixType type;
|
||||
} CoglMatrix;
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
_math_matrix_multiply (CoglMatrix *result,
|
||||
const CoglMatrix *a,
|
||||
const CoglMatrix *b);
|
||||
|
||||
void
|
||||
_math_matrix_multiply_array (CoglMatrix *result, const float *b);
|
||||
|
||||
void
|
||||
_math_matrix_init_from_array (CoglMatrix *matrix, const float *array);
|
||||
|
||||
void
|
||||
_math_matrix_translate (CoglMatrix *matrix, float x, float y, float z);
|
||||
|
||||
void
|
||||
_math_matrix_rotate (CoglMatrix *matrix, float angle,
|
||||
float x, float y, float z);
|
||||
|
||||
void
|
||||
_math_matrix_scale (CoglMatrix *matrix, float x, float y, float z);
|
||||
|
||||
void
|
||||
_math_matrix_ortho (CoglMatrix *matrix,
|
||||
float left, float right,
|
||||
float bottom, float top,
|
||||
float nearval, float farval);
|
||||
|
||||
void
|
||||
_math_matrix_frustum (CoglMatrix *matrix,
|
||||
float left, float right,
|
||||
float bottom, float top,
|
||||
float nearval, float farval);
|
||||
|
||||
void
|
||||
_math_matrix_viewport (CoglMatrix *matrix,
|
||||
float x, float y, float width, float height,
|
||||
float z_near, float z_far, float depth_max);
|
||||
|
||||
void
|
||||
_math_matrix_init_identity (CoglMatrix *matrix);
|
||||
|
||||
gboolean
|
||||
_math_matrix_update_inverse (CoglMatrix *matrix);
|
||||
|
||||
void
|
||||
_math_matrix_update_type_and_flags (CoglMatrix *matrix);
|
||||
|
||||
void
|
||||
_math_matrix_print (const CoglMatrix *matrix);
|
||||
|
||||
gboolean
|
||||
_math_matrix_is_length_preserving (const CoglMatrix *matrix);
|
||||
|
||||
gboolean
|
||||
_math_matrix_has_rotation (const CoglMatrix *matrix);
|
||||
|
||||
gboolean
|
||||
_math_matrix_is_general_scale (const CoglMatrix *matrix);
|
||||
|
||||
gboolean
|
||||
_math_matrix_is_dirty (const CoglMatrix *matrix);
|
||||
|
||||
|
||||
/*
|
||||
* \name Related functions that don't actually operate on CoglMatrix structs
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
void
|
||||
_math_transposef ( float to[16], const float from[16]);
|
||||
|
||||
void
|
||||
_math_transposed (double to[16], const double from[16]);
|
||||
|
||||
void
|
||||
_math_transposefd (float to[16], const double from[16]);
|
||||
|
||||
|
||||
/*
|
||||
* Transform a point (column vector) by a matrix: Q = M * P
|
||||
*/
|
||||
#define TRANSFORM_POINT( Q, M, P ) \
|
||||
Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12] * P[3]; \
|
||||
Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13] * P[3]; \
|
||||
Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14] * P[3]; \
|
||||
Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15] * P[3];
|
||||
|
||||
|
||||
#define TRANSFORM_POINT3( Q, M, P ) \
|
||||
Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12]; \
|
||||
Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13]; \
|
||||
Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14]; \
|
||||
Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15];
|
||||
|
||||
|
||||
/*
|
||||
* Transform a normal (row vector) by a matrix: [NX NY NZ] = N * MAT
|
||||
*/
|
||||
#define TRANSFORM_NORMAL( TO, N, MAT ) \
|
||||
do { \
|
||||
TO[0] = N[0] * MAT[0] + N[1] * MAT[1] + N[2] * MAT[2]; \
|
||||
TO[1] = N[0] * MAT[4] + N[1] * MAT[5] + N[2] * MAT[6]; \
|
||||
TO[2] = N[0] * MAT[8] + N[1] * MAT[9] + N[2] * MAT[10]; \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*
|
||||
* Transform a direction by a matrix.
|
||||
*/
|
||||
#define TRANSFORM_DIRECTION( TO, DIR, MAT ) \
|
||||
do { \
|
||||
TO[0] = DIR[0] * MAT[0] + DIR[1] * MAT[4] + DIR[2] * MAT[8]; \
|
||||
TO[1] = DIR[0] * MAT[1] + DIR[1] * MAT[5] + DIR[2] * MAT[9]; \
|
||||
TO[2] = DIR[0] * MAT[2] + DIR[1] * MAT[6] + DIR[2] * MAT[10];\
|
||||
} while (0)
|
||||
|
||||
|
||||
void
|
||||
_mesa_transform_vector (float u[4], const float v[4], const float m[16]);
|
||||
|
||||
|
||||
/*@}*/
|
||||
|
||||
|
||||
#endif
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_MATRIX_PRIVATE_H
|
||||
#define __COGL_MATRIX_PRIVATE_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define _COGL_MATRIX_DEBUG_PRINT(MATRIX) \
|
||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_MATRICES))) \
|
||||
{ \
|
||||
g_print ("%s:\n", G_STRFUNC); \
|
||||
_cogl_matrix_print (MATRIX); \
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_print (CoglMatrix *matrix);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_MATRIX_PRIVATE_H */
|
||||
|
@ -1,550 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Havoc Pennington <hp@pobox.com> for litl
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-matrix-stack.h"
|
||||
#include "cogl-framebuffer-private.h"
|
||||
#include "cogl-object-private.h"
|
||||
|
||||
typedef struct {
|
||||
CoglMatrix matrix;
|
||||
gboolean is_identity;
|
||||
/* count of pushes with no changes; when a change is
|
||||
* requested, we create a new state and decrement this
|
||||
*/
|
||||
int push_count;
|
||||
} CoglMatrixState;
|
||||
|
||||
/**
|
||||
* CoglMatrixStack:
|
||||
*
|
||||
* Stores a cogl-side matrix stack, which we use as a cache
|
||||
* so we can get the matrix efficiently when using indirect
|
||||
* rendering.
|
||||
*/
|
||||
struct _CoglMatrixStack
|
||||
{
|
||||
CoglObject _parent;
|
||||
|
||||
GArray *stack;
|
||||
|
||||
/* which state does GL have, NULL if unknown */
|
||||
CoglMatrixState *flushed_state;
|
||||
gboolean flushed_identity;
|
||||
|
||||
unsigned int age;
|
||||
};
|
||||
|
||||
static void _cogl_matrix_stack_free (CoglMatrixStack *stack);
|
||||
|
||||
COGL_OBJECT_INTERNAL_DEFINE (MatrixStack, matrix_stack);
|
||||
|
||||
/* XXX: this doesn't initialize the matrix! */
|
||||
static void
|
||||
_cogl_matrix_state_init (CoglMatrixState *state)
|
||||
{
|
||||
state->push_count = 0;
|
||||
state->is_identity = FALSE;
|
||||
}
|
||||
|
||||
static CoglMatrixState *
|
||||
_cogl_matrix_stack_top (CoglMatrixStack *stack)
|
||||
{
|
||||
return &g_array_index (stack->stack, CoglMatrixState, stack->stack->len - 1);
|
||||
}
|
||||
|
||||
/* XXX:
|
||||
* Operations like scale, translate, rotate etc need to have an
|
||||
* initialized state->matrix to work with, so they will pass
|
||||
* initialize = TRUE.
|
||||
*
|
||||
* _cogl_matrix_stack_load_identity and _cogl_matrix_stack_set on the
|
||||
* other hand don't so they will pass initialize = FALSE
|
||||
*
|
||||
* NB: Identity matrices are represented by setting
|
||||
* state->is_identity=TRUE in which case state->matrix will be
|
||||
* uninitialized.
|
||||
*/
|
||||
static CoglMatrixState *
|
||||
_cogl_matrix_stack_top_mutable (CoglMatrixStack *stack,
|
||||
gboolean initialize)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
CoglMatrixState *new_top;
|
||||
|
||||
state = _cogl_matrix_stack_top (stack);
|
||||
|
||||
if (state->push_count == 0)
|
||||
{
|
||||
if (state->is_identity && initialize)
|
||||
cogl_matrix_init_identity (&state->matrix);
|
||||
return state;
|
||||
}
|
||||
|
||||
state->push_count -= 1;
|
||||
|
||||
g_array_set_size (stack->stack, stack->stack->len + 1);
|
||||
new_top = &g_array_index (stack->stack, CoglMatrixState,
|
||||
stack->stack->len - 1);
|
||||
_cogl_matrix_state_init (new_top);
|
||||
|
||||
if (initialize)
|
||||
{
|
||||
if (state->is_identity)
|
||||
cogl_matrix_init_identity (&new_top->matrix);
|
||||
else
|
||||
new_top->matrix = state->matrix;
|
||||
|
||||
if (stack->flushed_state == state)
|
||||
stack->flushed_state = new_top;
|
||||
}
|
||||
|
||||
return new_top;
|
||||
}
|
||||
|
||||
CoglMatrixStack*
|
||||
_cogl_matrix_stack_new (void)
|
||||
{
|
||||
CoglMatrixStack *stack;
|
||||
CoglMatrixState *state;
|
||||
|
||||
stack = g_slice_new0 (CoglMatrixStack);
|
||||
|
||||
stack->stack = g_array_sized_new (FALSE, FALSE,
|
||||
sizeof (CoglMatrixState), 10);
|
||||
g_array_set_size (stack->stack, 1);
|
||||
state = &g_array_index (stack->stack, CoglMatrixState, 0);
|
||||
_cogl_matrix_state_init (state);
|
||||
state->is_identity = TRUE;
|
||||
|
||||
stack->age = 0;
|
||||
|
||||
return _cogl_matrix_stack_object_new (stack);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_matrix_stack_free (CoglMatrixStack *stack)
|
||||
{
|
||||
g_array_free (stack->stack, TRUE);
|
||||
g_slice_free (CoglMatrixStack, stack);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_push (CoglMatrixStack *stack)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top (stack);
|
||||
|
||||
/* we lazily create a new stack top if someone changes the matrix
|
||||
* while push_count > 0
|
||||
*/
|
||||
state->push_count += 1;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_pop (CoglMatrixStack *stack)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top (stack);
|
||||
|
||||
if (state->push_count > 0)
|
||||
{
|
||||
state->push_count -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (stack->stack->len == 1)
|
||||
{
|
||||
g_warning ("Too many matrix pops");
|
||||
return;
|
||||
}
|
||||
|
||||
if (stack->flushed_state == state)
|
||||
{
|
||||
stack->flushed_state = NULL;
|
||||
}
|
||||
|
||||
stack->age++;
|
||||
g_array_set_size (stack->stack, stack->stack->len - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_load_identity (CoglMatrixStack *stack)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top_mutable (stack, FALSE);
|
||||
|
||||
/* NB: Identity matrices are represented by setting
|
||||
* state->is_identity = TRUE and leaving state->matrix
|
||||
* uninitialized.
|
||||
*
|
||||
* This is done to optimize the heavy usage of
|
||||
* _cogl_matrix_stack_load_identity by the Cogl Journal.
|
||||
*/
|
||||
if (!state->is_identity)
|
||||
{
|
||||
state->is_identity = TRUE;
|
||||
|
||||
/* mark dirty */
|
||||
stack->flushed_state = NULL;
|
||||
stack->age++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_scale (CoglMatrixStack *stack,
|
||||
float x,
|
||||
float y,
|
||||
float z)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top_mutable (stack, TRUE);
|
||||
cogl_matrix_scale (&state->matrix, x, y, z);
|
||||
/* mark dirty */
|
||||
stack->flushed_state = NULL;
|
||||
state->is_identity = FALSE;
|
||||
stack->age++;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_translate (CoglMatrixStack *stack,
|
||||
float x,
|
||||
float y,
|
||||
float z)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top_mutable (stack, TRUE);
|
||||
cogl_matrix_translate (&state->matrix, x, y, z);
|
||||
/* mark dirty */
|
||||
stack->flushed_state = NULL;
|
||||
state->is_identity = FALSE;
|
||||
stack->age++;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_rotate (CoglMatrixStack *stack,
|
||||
float angle,
|
||||
float x,
|
||||
float y,
|
||||
float z)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top_mutable (stack, TRUE);
|
||||
cogl_matrix_rotate (&state->matrix, angle, x, y, z);
|
||||
/* mark dirty */
|
||||
stack->flushed_state = NULL;
|
||||
state->is_identity = FALSE;
|
||||
stack->age++;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_multiply (CoglMatrixStack *stack,
|
||||
const CoglMatrix *matrix)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top_mutable (stack, TRUE);
|
||||
cogl_matrix_multiply (&state->matrix, &state->matrix, matrix);
|
||||
/* mark dirty */
|
||||
stack->flushed_state = NULL;
|
||||
state->is_identity = FALSE;
|
||||
stack->age++;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_frustum (CoglMatrixStack *stack,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float z_near,
|
||||
float z_far)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top_mutable (stack, TRUE);
|
||||
cogl_matrix_frustum (&state->matrix,
|
||||
left, right, bottom, top,
|
||||
z_near, z_far);
|
||||
/* mark dirty */
|
||||
stack->flushed_state = NULL;
|
||||
state->is_identity = FALSE;
|
||||
stack->age++;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_perspective (CoglMatrixStack *stack,
|
||||
float fov_y,
|
||||
float aspect,
|
||||
float z_near,
|
||||
float z_far)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top_mutable (stack, TRUE);
|
||||
cogl_matrix_perspective (&state->matrix,
|
||||
fov_y, aspect, z_near, z_far);
|
||||
/* mark dirty */
|
||||
stack->flushed_state = NULL;
|
||||
state->is_identity = FALSE;
|
||||
stack->age++;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_ortho (CoglMatrixStack *stack,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float z_near,
|
||||
float z_far)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top_mutable (stack, TRUE);
|
||||
cogl_matrix_ortho (&state->matrix,
|
||||
left, right, bottom, top, z_near, z_far);
|
||||
/* mark dirty */
|
||||
stack->flushed_state = NULL;
|
||||
state->is_identity = FALSE;
|
||||
stack->age++;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_matrix_stack_get_inverse (CoglMatrixStack *stack,
|
||||
CoglMatrix *inverse)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top_mutable (stack, TRUE);
|
||||
|
||||
return cogl_matrix_get_inverse (&state->matrix, inverse);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_get (CoglMatrixStack *stack,
|
||||
CoglMatrix *matrix)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top (stack);
|
||||
|
||||
/* NB: identity matrices are lazily initialized because we can often avoid
|
||||
* initializing them at all if nothing is pushed on top of them since we
|
||||
* load them using glLoadIdentity()
|
||||
*
|
||||
* The Cogl journal typically loads an identiy matrix because it performs
|
||||
* software transformations, which is why we have optimized this case.
|
||||
*/
|
||||
if (state->is_identity)
|
||||
cogl_matrix_init_identity (matrix);
|
||||
else
|
||||
*matrix = state->matrix;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_set (CoglMatrixStack *stack,
|
||||
const CoglMatrix *matrix)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
state = _cogl_matrix_stack_top_mutable (stack, FALSE);
|
||||
state->matrix = *matrix;
|
||||
/* mark dirty */
|
||||
stack->flushed_state = NULL;
|
||||
state->is_identity = FALSE;
|
||||
stack->age++;
|
||||
}
|
||||
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
|
||||
static void
|
||||
flush_to_fixed_api_gl (gboolean is_identity,
|
||||
const CoglMatrix *matrix,
|
||||
void *user_data)
|
||||
{
|
||||
CoglMatrixStack *stack = user_data;
|
||||
|
||||
if (is_identity)
|
||||
{
|
||||
if (!stack->flushed_identity)
|
||||
GE (glLoadIdentity ());
|
||||
stack->flushed_identity = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
GE (glLoadMatrixf (cogl_matrix_get_array (matrix)) );
|
||||
stack->flushed_identity = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_COGL_GLES2 */
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_prepare_for_flush (CoglMatrixStack *stack,
|
||||
CoglMatrixMode mode,
|
||||
CoglMatrixStackFlushFunc callback,
|
||||
void *user_data)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
state = _cogl_matrix_stack_top (stack);
|
||||
|
||||
/* Because Cogl defines texture coordinates to have a top left origin and
|
||||
* because offscreen framebuffers may be used for rendering to textures we
|
||||
* always render upside down to offscreen buffers.
|
||||
*/
|
||||
if (mode == COGL_MATRIX_PROJECTION &&
|
||||
cogl_is_offscreen (cogl_get_draw_framebuffer ()))
|
||||
{
|
||||
CoglMatrix flipped_projection;
|
||||
CoglMatrix *projection =
|
||||
state->is_identity ? &ctx->identity_matrix : &state->matrix;
|
||||
|
||||
cogl_matrix_multiply (&flipped_projection,
|
||||
&ctx->y_flip_matrix, projection);
|
||||
callback (FALSE, &flipped_projection, user_data);
|
||||
}
|
||||
else
|
||||
callback (state->is_identity,
|
||||
state->is_identity ? &ctx->identity_matrix : &state->matrix,
|
||||
user_data);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
|
||||
CoglMatrixMode mode)
|
||||
{
|
||||
CoglMatrixState *state;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
state = _cogl_matrix_stack_top (stack);
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
|
||||
/* Under GLES2 we need to flush the matrices differently because
|
||||
they are stored in uniforms attached to the program instead of
|
||||
the global GL context state. At this point we can't be sure that
|
||||
the right program will be generated so instead we'll just store a
|
||||
reference to the matrix stack that is intended to be flushed and
|
||||
update the uniform once the program is ready. */
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case COGL_MATRIX_MODELVIEW:
|
||||
cogl_object_ref (stack);
|
||||
if (ctx->flushed_modelview_stack)
|
||||
cogl_object_unref (ctx->flushed_modelview_stack);
|
||||
ctx->flushed_modelview_stack = stack;
|
||||
break;
|
||||
|
||||
case COGL_MATRIX_PROJECTION:
|
||||
cogl_object_ref (stack);
|
||||
if (ctx->flushed_projection_stack)
|
||||
cogl_object_unref (ctx->flushed_projection_stack);
|
||||
ctx->flushed_projection_stack = stack;
|
||||
break;
|
||||
|
||||
case COGL_MATRIX_TEXTURE:
|
||||
/* This shouldn't happen because the texture matrices are
|
||||
handled by the GLSL pipeline backend */
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
|
||||
#else /* HAVE_COGL_GLES2 */
|
||||
|
||||
if (stack->flushed_state == state)
|
||||
return;
|
||||
|
||||
if (ctx->flushed_matrix_mode != mode)
|
||||
{
|
||||
GLenum gl_mode = 0;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case COGL_MATRIX_MODELVIEW:
|
||||
gl_mode = GL_MODELVIEW;
|
||||
break;
|
||||
|
||||
case COGL_MATRIX_PROJECTION:
|
||||
gl_mode = GL_PROJECTION;
|
||||
break;
|
||||
|
||||
case COGL_MATRIX_TEXTURE:
|
||||
gl_mode = GL_TEXTURE;
|
||||
break;
|
||||
}
|
||||
|
||||
GE (glMatrixMode (gl_mode));
|
||||
ctx->flushed_matrix_mode = mode;
|
||||
}
|
||||
|
||||
_cogl_matrix_stack_prepare_for_flush (stack,
|
||||
mode,
|
||||
flush_to_fixed_api_gl,
|
||||
stack);
|
||||
|
||||
#endif /* HAVE_COGL_GLES2 */
|
||||
|
||||
stack->flushed_state = state;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_dirty (CoglMatrixStack *stack)
|
||||
{
|
||||
stack->flushed_state = NULL;
|
||||
stack->flushed_identity = FALSE;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
_cogl_matrix_stack_get_age (CoglMatrixStack *stack)
|
||||
{
|
||||
return stack->age;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_matrix_stack_has_identity_flag (CoglMatrixStack *stack)
|
||||
{
|
||||
return _cogl_matrix_stack_top (stack)->is_identity;
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Havoc Pennington <hp@pobox.com> for litl
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_MATRIX_STACK_H
|
||||
#define __COGL_MATRIX_STACK_H
|
||||
|
||||
#include "cogl-matrix.h"
|
||||
|
||||
typedef struct _CoglMatrixStack CoglMatrixStack;
|
||||
|
||||
typedef enum {
|
||||
COGL_MATRIX_MODELVIEW,
|
||||
COGL_MATRIX_PROJECTION,
|
||||
COGL_MATRIX_TEXTURE
|
||||
} CoglMatrixMode;
|
||||
|
||||
typedef void (* CoglMatrixStackFlushFunc) (gboolean is_identity,
|
||||
const CoglMatrix *matrix,
|
||||
void *user_data);
|
||||
|
||||
CoglMatrixStack *
|
||||
_cogl_matrix_stack_new (void);
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_push (CoglMatrixStack *stack);
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_pop (CoglMatrixStack *stack);
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_load_identity (CoglMatrixStack *stack);
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_scale (CoglMatrixStack *stack,
|
||||
float x,
|
||||
float y,
|
||||
float z);
|
||||
void
|
||||
_cogl_matrix_stack_translate (CoglMatrixStack *stack,
|
||||
float x,
|
||||
float y,
|
||||
float z);
|
||||
void
|
||||
_cogl_matrix_stack_rotate (CoglMatrixStack *stack,
|
||||
float angle,
|
||||
float x,
|
||||
float y,
|
||||
float z);
|
||||
void
|
||||
_cogl_matrix_stack_multiply (CoglMatrixStack *stack,
|
||||
const CoglMatrix *matrix);
|
||||
void
|
||||
_cogl_matrix_stack_frustum (CoglMatrixStack *stack,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float z_near,
|
||||
float z_far);
|
||||
void
|
||||
_cogl_matrix_stack_perspective (CoglMatrixStack *stack,
|
||||
float fov_y,
|
||||
float aspect,
|
||||
float z_near,
|
||||
float z_far);
|
||||
void
|
||||
_cogl_matrix_stack_ortho (CoglMatrixStack *stack,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float z_near,
|
||||
float z_far);
|
||||
gboolean
|
||||
_cogl_matrix_stack_get_inverse (CoglMatrixStack *stack,
|
||||
CoglMatrix *inverse);
|
||||
void
|
||||
_cogl_matrix_stack_get (CoglMatrixStack *stack,
|
||||
CoglMatrix *matrix);
|
||||
void
|
||||
_cogl_matrix_stack_set (CoglMatrixStack *stack,
|
||||
const CoglMatrix *matrix);
|
||||
void
|
||||
_cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
|
||||
CoglMatrixMode mode);
|
||||
void
|
||||
_cogl_matrix_stack_dirty (CoglMatrixStack *stack);
|
||||
|
||||
unsigned int
|
||||
_cogl_matrix_stack_get_age (CoglMatrixStack *stack);
|
||||
|
||||
/* If this returns TRUE then the top of the matrix is definitely the
|
||||
identity matrix. If it returns FALSE it may or may not be the
|
||||
identity matrix but no expensive comparison is performed to verify
|
||||
it. */
|
||||
gboolean
|
||||
_cogl_matrix_stack_has_identity_flag (CoglMatrixStack *stack);
|
||||
|
||||
void
|
||||
_cogl_matrix_stack_prepare_for_flush (CoglMatrixStack *stack,
|
||||
CoglMatrixMode mode,
|
||||
CoglMatrixStackFlushFunc callback,
|
||||
void *user_data);
|
||||
|
||||
#endif /* __COGL_MATRIX_STACK_H */
|
@ -1,673 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#define USE_MESA_MATRIX_API
|
||||
|
||||
#include <cogl.h>
|
||||
#include "cogl-debug.h"
|
||||
#include <cogl-matrix.h>
|
||||
#include <cogl-matrix-private.h>
|
||||
#ifdef USE_MESA_MATRIX_API
|
||||
#include <cogl-matrix-mesa.h>
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _COGL_SUPPORTS_GTYPE_INTEGRATION
|
||||
#include <cogl-gtype-private.h>
|
||||
COGL_GTYPE_DEFINE_BOXED ("Matrix", matrix,
|
||||
cogl_matrix_copy,
|
||||
cogl_matrix_free);
|
||||
#endif
|
||||
|
||||
void
|
||||
_cogl_matrix_print (CoglMatrix *matrix)
|
||||
{
|
||||
float *m = (float *)matrix;
|
||||
int y;
|
||||
|
||||
for (y = 0; y < 4; y++)
|
||||
g_print ("\t%6.4f %6.4f %6.4f %6.4f\n", m[y], m[4+y], m[8+y], m[12+y]);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_init_identity (CoglMatrix *matrix)
|
||||
{
|
||||
#ifndef USE_MESA_MATRIX_API
|
||||
matrix->xx = 1; matrix->xy = 0; matrix->xz = 0; matrix->xw = 0;
|
||||
matrix->yx = 0; matrix->yy = 1; matrix->yz = 0; matrix->yw = 0;
|
||||
matrix->zx = 0; matrix->zy = 0; matrix->zz = 1; matrix->zw = 0;
|
||||
matrix->wx = 0; matrix->wy = 0; matrix->wz = 0; matrix->ww = 1;
|
||||
#else
|
||||
_math_matrix_init_identity (matrix);
|
||||
#endif
|
||||
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_multiply (CoglMatrix *result,
|
||||
const CoglMatrix *a,
|
||||
const CoglMatrix *b)
|
||||
{
|
||||
#ifndef USE_MESA_MATRIX_API
|
||||
CoglMatrix r;
|
||||
|
||||
/* row 0 */
|
||||
r.xx = a->xx * b->xx + a->xy * b->yx + a->xz * b->zx + a->xw * b->wx;
|
||||
r.xy = a->xx * b->xy + a->xy * b->yy + a->xz * b->zy + a->xw * b->wy;
|
||||
r.xz = a->xx * b->xz + a->xy * b->yz + a->xz * b->zz + a->xw * b->wz;
|
||||
r.xw = a->xx * b->xw + a->xy * b->yw + a->xz * b->zw + a->xw * b->ww;
|
||||
|
||||
/* row 1 */
|
||||
r.yx = a->yx * b->xx + a->yy * b->yx + a->yz * b->zx + a->yw * b->wx;
|
||||
r.yy = a->yx * b->xy + a->yy * b->yy + a->yz * b->zy + a->yw * b->wy;
|
||||
r.yz = a->yx * b->xz + a->yy * b->yz + a->yz * b->zz + a->yw * b->wz;
|
||||
r.yw = a->yx * b->xw + a->yy * b->yw + a->yz * b->zw + a->yw * b->ww;
|
||||
|
||||
/* row 2 */
|
||||
r.zx = a->zx * b->xx + a->zy * b->yx + a->zz * b->zx + a->zw * b->wx;
|
||||
r.zy = a->zx * b->xy + a->zy * b->yy + a->zz * b->zy + a->zw * b->wy;
|
||||
r.zz = a->zx * b->xz + a->zy * b->yz + a->zz * b->zz + a->zw * b->wz;
|
||||
r.zw = a->zx * b->xw + a->zy * b->yw + a->zz * b->zw + a->zw * b->ww;
|
||||
|
||||
/* row 3 */
|
||||
r.wx = a->wx * b->xx + a->wy * b->yx + a->wz * b->zx + a->ww * b->wx;
|
||||
r.wy = a->wx * b->xy + a->wy * b->yy + a->wz * b->zy + a->ww * b->wy;
|
||||
r.wz = a->wx * b->xz + a->wy * b->yz + a->wz * b->zz + a->ww * b->wz;
|
||||
r.ww = a->wx * b->xw + a->wy * b->yw + a->wz * b->zw + a->ww * b->ww;
|
||||
|
||||
/* The idea was that having this unrolled; it might be easier for the
|
||||
* compiler to vectorize, but that's probably not true. Mesa does it
|
||||
* using a single for (i=0; i<4; i++) approach, maybe that's better...
|
||||
*/
|
||||
|
||||
*result = r;
|
||||
#else
|
||||
_math_matrix_multiply (result, a, b);
|
||||
#endif
|
||||
_COGL_MATRIX_DEBUG_PRINT (result);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_rotate (CoglMatrix *matrix,
|
||||
float angle,
|
||||
float x,
|
||||
float y,
|
||||
float z)
|
||||
{
|
||||
#ifndef USE_MESA_MATRIX_API
|
||||
CoglMatrix rotation;
|
||||
CoglMatrix result;
|
||||
float c, s;
|
||||
|
||||
angle *= G_PI / 180.0f;
|
||||
c = cosf (angle);
|
||||
s = sinf (angle);
|
||||
|
||||
rotation.xx = x * x * (1.0f - c) + c;
|
||||
rotation.yx = y * x * (1.0f - c) + z * s;
|
||||
rotation.zx = x * z * (1.0f - c) - y * s;
|
||||
rotation.wx = 0.0f;
|
||||
|
||||
rotation.xy = x * y * (1.0f - c) - z * s;
|
||||
rotation.yy = y * y * (1.0f - c) + c;
|
||||
rotation.zy = y * z * (1.0f - c) + x * s;
|
||||
rotation.wy = 0.0f;
|
||||
|
||||
rotation.xz = x * z * (1.0f - c) + y * s;
|
||||
rotation.yz = y * z * (1.0f - c) - x * s;
|
||||
rotation.zz = z * z * (1.0f - c) + c;
|
||||
rotation.wz = 0.0f;
|
||||
|
||||
rotation.xw = 0.0f;
|
||||
rotation.yw = 0.0f;
|
||||
rotation.zw = 0.0f;
|
||||
rotation.ww = 1.0f;
|
||||
|
||||
cogl_matrix_multiply (&result, matrix, &rotation);
|
||||
*matrix = result;
|
||||
#else
|
||||
_math_matrix_rotate (matrix, angle, x, y, z);
|
||||
#endif
|
||||
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_translate (CoglMatrix *matrix,
|
||||
float x,
|
||||
float y,
|
||||
float z)
|
||||
{
|
||||
#ifndef USE_MESA_MATRIX_API
|
||||
matrix->xw = matrix->xx * x + matrix->xy * y + matrix->xz * z + matrix->xw;
|
||||
matrix->yw = matrix->yx * x + matrix->yy * y + matrix->yz * z + matrix->yw;
|
||||
matrix->zw = matrix->zx * x + matrix->zy * y + matrix->zz * z + matrix->zw;
|
||||
matrix->ww = matrix->wx * x + matrix->wy * y + matrix->wz * z + matrix->ww;
|
||||
#else
|
||||
_math_matrix_translate (matrix, x, y, z);
|
||||
#endif
|
||||
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_scale (CoglMatrix *matrix,
|
||||
float sx,
|
||||
float sy,
|
||||
float sz)
|
||||
{
|
||||
#ifndef USE_MESA_MATRIX_API
|
||||
matrix->xx *= sx; matrix->xy *= sy; matrix->xz *= sz;
|
||||
matrix->yx *= sx; matrix->yy *= sy; matrix->yz *= sz;
|
||||
matrix->zx *= sx; matrix->zy *= sy; matrix->zz *= sz;
|
||||
matrix->wx *= sx; matrix->wy *= sy; matrix->wz *= sz;
|
||||
#else
|
||||
_math_matrix_scale (matrix, sx, sy, sz);
|
||||
#endif
|
||||
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_frustum (CoglMatrix *matrix,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float z_near,
|
||||
float z_far)
|
||||
{
|
||||
#ifndef USE_MESA_MATRIX_API
|
||||
float x, y, a, b, c, d;
|
||||
CoglMatrix frustum;
|
||||
|
||||
x = (2.0f * z_near) / (right - left);
|
||||
y = (2.0f * z_near) / (top - bottom);
|
||||
a = (right + left) / (right - left);
|
||||
b = (top + bottom) / (top - bottom);
|
||||
c = -(z_far + z_near) / ( z_far - z_near);
|
||||
d = -(2.0f * z_far* z_near) / (z_far - z_near);
|
||||
|
||||
frustum.xx = x;
|
||||
frustum.yx = 0.0f;
|
||||
frustum.zx = 0.0f;
|
||||
frustum.wx = 0.0f;
|
||||
|
||||
frustum.xy = 0.0f;
|
||||
frustum.yy = y;
|
||||
frustum.zy = 0.0f;
|
||||
frustum.wy = 0.0f;
|
||||
|
||||
frustum.xz = a;
|
||||
frustum.yz = b;
|
||||
frustum.zz = c;
|
||||
frustum.wz = -1.0f;
|
||||
|
||||
frustum.xw = 0.0f;
|
||||
frustum.yw = 0.0f;
|
||||
frustum.zw = d;
|
||||
frustum.ww = 0.0f;
|
||||
|
||||
cogl_matrix_multiply (matrix, matrix, &frustum);
|
||||
#else
|
||||
_math_matrix_frustum (matrix, left, right, bottom, top, z_near, z_far);
|
||||
#endif
|
||||
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_perspective (CoglMatrix *matrix,
|
||||
float fov_y,
|
||||
float aspect,
|
||||
float z_near,
|
||||
float z_far)
|
||||
{
|
||||
float ymax = z_near * tan (fov_y * G_PI / 360.0);
|
||||
|
||||
cogl_matrix_frustum (matrix,
|
||||
-ymax * aspect, /* left */
|
||||
ymax * aspect, /* right */
|
||||
-ymax, /* bottom */
|
||||
ymax, /* top */
|
||||
z_near,
|
||||
z_far);
|
||||
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_ortho (CoglMatrix *matrix,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float near_val,
|
||||
float far_val)
|
||||
{
|
||||
#ifndef USE_MESA_MATRIX_API
|
||||
CoglMatrix ortho;
|
||||
|
||||
/* column 0 */
|
||||
ortho.xx = 2.0 / (right - left);
|
||||
ortho.yx = 0.0;
|
||||
ortho.zx = 0.0;
|
||||
ortho.wx = 0.0;
|
||||
|
||||
/* column 1 */
|
||||
ortho.xy = 0.0;
|
||||
ortho.yy = 2.0 / (top - bottom);
|
||||
ortho.zy = 0.0;
|
||||
ortho.wy = 0.0;
|
||||
|
||||
/* column 2 */
|
||||
ortho.xz = 0.0;
|
||||
ortho.yz = 0.0;
|
||||
ortho.zz = -2.0 / (far_val - near_val);
|
||||
ortho.wz = 0.0;
|
||||
|
||||
/* column 3 */
|
||||
ortho.xw = -(right + left) / (right - left);
|
||||
ortho.yw = -(top + bottom) / (top - bottom);
|
||||
ortho.zw = -(far_val + near_val) / (far_val - near_val);
|
||||
ortho.ww = 1.0;
|
||||
|
||||
cogl_matrix_multiply (matrix, matrix, &ortho);
|
||||
#else
|
||||
_math_matrix_ortho (matrix, left, right, bottom, top, near_val, far_val);
|
||||
#endif
|
||||
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_view_2d_in_frustum (CoglMatrix *matrix,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float z_near,
|
||||
float z_2d,
|
||||
float width_2d,
|
||||
float height_2d)
|
||||
{
|
||||
float left_2d_plane = left / z_near * z_2d;
|
||||
float right_2d_plane = right / z_near * z_2d;
|
||||
float bottom_2d_plane = bottom / z_near * z_2d;
|
||||
float top_2d_plane = top / z_near * z_2d;
|
||||
|
||||
float width_2d_start = right_2d_plane - left_2d_plane;
|
||||
float height_2d_start = top_2d_plane - bottom_2d_plane;
|
||||
|
||||
/* Factors to scale from framebuffer geometry to frustum
|
||||
* cross-section geometry. */
|
||||
float width_scale = width_2d_start / width_2d;
|
||||
float height_scale = height_2d_start / height_2d;
|
||||
|
||||
cogl_matrix_translate (matrix,
|
||||
left_2d_plane, top_2d_plane, -z_2d);
|
||||
|
||||
cogl_matrix_scale (matrix, width_scale, -height_scale, width_scale);
|
||||
}
|
||||
|
||||
/* Assuming a symmetric perspective matrix is being used for your
|
||||
* projective transform this convenience function lets you compose a
|
||||
* view transform such that geometry on the z=0 plane will map to
|
||||
* screen coordinates with a top left origin of (0,0) and with the
|
||||
* given width and height.
|
||||
*/
|
||||
void
|
||||
cogl_matrix_view_2d_in_perspective (CoglMatrix *matrix,
|
||||
float fov_y,
|
||||
float aspect,
|
||||
float z_near,
|
||||
float z_2d,
|
||||
float width_2d,
|
||||
float height_2d)
|
||||
{
|
||||
float top = z_near * tan (fov_y * G_PI / 360.0);
|
||||
cogl_matrix_view_2d_in_frustum (matrix,
|
||||
-top * aspect,
|
||||
top * aspect,
|
||||
-top,
|
||||
top,
|
||||
z_near,
|
||||
z_2d,
|
||||
width_2d,
|
||||
height_2d);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_init_from_array (CoglMatrix *matrix, const float *array)
|
||||
{
|
||||
#ifndef USE_MESA_MATRIX_API
|
||||
memcpy (matrix, array, sizeof (float) * 16);
|
||||
#else
|
||||
_math_matrix_init_from_array (matrix, array);
|
||||
#endif
|
||||
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_matrix_equal (gconstpointer v1, gconstpointer v2)
|
||||
{
|
||||
const CoglMatrix *a = v1;
|
||||
const CoglMatrix *b = v2;
|
||||
|
||||
g_return_val_if_fail (v1 != NULL, FALSE);
|
||||
g_return_val_if_fail (v2 != NULL, FALSE);
|
||||
|
||||
/* We want to avoid having a fuzzy _equal() function (e.g. that uses
|
||||
* an arbitrary epsilon value) since this function noteably conforms
|
||||
* to the prototype suitable for use with g_hash_table_new() and a
|
||||
* fuzzy hash function isn't really appropriate for comparing hash
|
||||
* table keys since it's possible that you could end up fetching
|
||||
* different values if you end up with multiple similar keys in use
|
||||
* at the same time. If you consider that fuzzyness allows cases
|
||||
* such as A == B == C but A != C then you could also end up loosing
|
||||
* values in a hash table.
|
||||
*
|
||||
* We do at least use the == operator to compare values though so
|
||||
* that -0 is considered equal to 0.
|
||||
*/
|
||||
|
||||
/* XXX: We don't compare the flags, inverse matrix or padding */
|
||||
if (a->xx == b->xx &&
|
||||
a->xy == b->xy &&
|
||||
a->xz == b->xz &&
|
||||
a->xw == b->xw &&
|
||||
a->yx == b->yx &&
|
||||
a->yy == b->yy &&
|
||||
a->yz == b->yz &&
|
||||
a->yw == b->yw &&
|
||||
a->zx == b->zx &&
|
||||
a->zy == b->zy &&
|
||||
a->zz == b->zz &&
|
||||
a->zw == b->zw &&
|
||||
a->wx == b->wx &&
|
||||
a->wy == b->wy &&
|
||||
a->wz == b->wz &&
|
||||
a->ww == b->ww)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CoglMatrix *
|
||||
cogl_matrix_copy (const CoglMatrix *matrix)
|
||||
{
|
||||
if (G_LIKELY (matrix))
|
||||
return g_slice_dup (CoglMatrix, matrix);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_free (CoglMatrix *matrix)
|
||||
{
|
||||
g_slice_free (CoglMatrix, matrix);
|
||||
}
|
||||
|
||||
const float *
|
||||
cogl_matrix_get_array (const CoglMatrix *matrix)
|
||||
{
|
||||
return (float *)matrix;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_matrix_get_inverse (const CoglMatrix *matrix, CoglMatrix *inverse)
|
||||
{
|
||||
#ifndef USE_MESA_MATRIX_API
|
||||
#warning "cogl_matrix_get_inverse not supported without Mesa matrix API"
|
||||
cogl_matrix_init_identity (inverse);
|
||||
return FALSE;
|
||||
#else
|
||||
if (_math_matrix_update_inverse ((CoglMatrix *)matrix))
|
||||
{
|
||||
cogl_matrix_init_from_array (inverse, matrix->inv);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
cogl_matrix_init_identity (inverse);
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_transform_point (const CoglMatrix *matrix,
|
||||
float *x,
|
||||
float *y,
|
||||
float *z,
|
||||
float *w)
|
||||
{
|
||||
float _x = *x, _y = *y, _z = *z, _w = *w;
|
||||
|
||||
*x = matrix->xx * _x + matrix->xy * _y + matrix->xz * _z + matrix->xw * _w;
|
||||
*y = matrix->yx * _x + matrix->yy * _y + matrix->yz * _z + matrix->yw * _w;
|
||||
*z = matrix->zx * _x + matrix->zy * _y + matrix->zz * _z + matrix->zw * _w;
|
||||
*w = matrix->wx * _x + matrix->wy * _y + matrix->wz * _z + matrix->ww * _w;
|
||||
}
|
||||
|
||||
typedef struct _Point2f
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
} Point2f;
|
||||
|
||||
typedef struct _Point3f
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} Point3f;
|
||||
|
||||
typedef struct _Point4f
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
} Point4f;
|
||||
|
||||
static void
|
||||
_cogl_matrix_transform_points_f2 (const CoglMatrix *matrix,
|
||||
size_t stride_in,
|
||||
const void *points_in,
|
||||
size_t stride_out,
|
||||
void *points_out,
|
||||
int n_points)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n_points; i++)
|
||||
{
|
||||
Point2f p = *(Point2f *)((guint8 *)points_in + i * stride_in);
|
||||
Point3f *o = (Point3f *)((guint8 *)points_out + i * stride_out);
|
||||
|
||||
o->x = matrix->xx * p.x + matrix->xy * p.y + matrix->xw;
|
||||
o->y = matrix->yx * p.x + matrix->yy * p.y + matrix->yw;
|
||||
o->z = matrix->zx * p.x + matrix->zy * p.y + matrix->zw;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_matrix_project_points_f2 (const CoglMatrix *matrix,
|
||||
size_t stride_in,
|
||||
const void *points_in,
|
||||
size_t stride_out,
|
||||
void *points_out,
|
||||
int n_points)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n_points; i++)
|
||||
{
|
||||
Point2f p = *(Point2f *)((guint8 *)points_in + i * stride_in);
|
||||
Point4f *o = (Point4f *)((guint8 *)points_out + i * stride_out);
|
||||
|
||||
o->x = matrix->xx * p.x + matrix->xy * p.y + matrix->xw;
|
||||
o->y = matrix->yx * p.x + matrix->yy * p.y + matrix->yw;
|
||||
o->z = matrix->zx * p.x + matrix->zy * p.y + matrix->zw;
|
||||
o->w = matrix->wx * p.x + matrix->wy * p.y + matrix->ww;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_matrix_transform_points_f3 (const CoglMatrix *matrix,
|
||||
size_t stride_in,
|
||||
const void *points_in,
|
||||
size_t stride_out,
|
||||
void *points_out,
|
||||
int n_points)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n_points; i++)
|
||||
{
|
||||
Point3f p = *(Point3f *)((guint8 *)points_in + i * stride_in);
|
||||
Point3f *o = (Point3f *)((guint8 *)points_out + i * stride_out);
|
||||
|
||||
o->x = matrix->xx * p.x + matrix->xy * p.y +
|
||||
matrix->xz * p.z + matrix->xw;
|
||||
o->y = matrix->yx * p.x + matrix->yy * p.y +
|
||||
matrix->yz * p.z + matrix->yw;
|
||||
o->z = matrix->zx * p.x + matrix->zy * p.y +
|
||||
matrix->zz * p.z + matrix->zw;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_matrix_project_points_f3 (const CoglMatrix *matrix,
|
||||
size_t stride_in,
|
||||
const void *points_in,
|
||||
size_t stride_out,
|
||||
void *points_out,
|
||||
int n_points)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n_points; i++)
|
||||
{
|
||||
Point3f p = *(Point3f *)((guint8 *)points_in + i * stride_in);
|
||||
Point4f *o = (Point4f *)((guint8 *)points_out + i * stride_out);
|
||||
|
||||
o->x = matrix->xx * p.x + matrix->xy * p.y +
|
||||
matrix->xz * p.z + matrix->xw;
|
||||
o->y = matrix->yx * p.x + matrix->yy * p.y +
|
||||
matrix->yz * p.z + matrix->yw;
|
||||
o->z = matrix->zx * p.x + matrix->zy * p.y +
|
||||
matrix->zz * p.z + matrix->zw;
|
||||
o->w = matrix->wx * p.x + matrix->wy * p.y +
|
||||
matrix->wz * p.z + matrix->ww;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_matrix_project_points_f4 (const CoglMatrix *matrix,
|
||||
size_t stride_in,
|
||||
const void *points_in,
|
||||
size_t stride_out,
|
||||
void *points_out,
|
||||
int n_points)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n_points; i++)
|
||||
{
|
||||
Point4f p = *(Point4f *)((guint8 *)points_in + i * stride_in);
|
||||
Point4f *o = (Point4f *)((guint8 *)points_out + i * stride_out);
|
||||
|
||||
o->x = matrix->xx * p.x + matrix->xy * p.y +
|
||||
matrix->xz * p.z + matrix->xw * p.w;
|
||||
o->y = matrix->yx * p.x + matrix->yy * p.y +
|
||||
matrix->yz * p.z + matrix->yw * p.w;
|
||||
o->z = matrix->zx * p.x + matrix->zy * p.y +
|
||||
matrix->zz * p.z + matrix->zw * p.w;
|
||||
o->w = matrix->wx * p.x + matrix->wy * p.y +
|
||||
matrix->wz * p.z + matrix->ww * p.w;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_transform_points (const CoglMatrix *matrix,
|
||||
int n_components,
|
||||
size_t stride_in,
|
||||
const void *points_in,
|
||||
size_t stride_out,
|
||||
void *points_out,
|
||||
int n_points)
|
||||
{
|
||||
/* The results of transforming always have three components... */
|
||||
g_return_if_fail (stride_out >= sizeof (Point3f));
|
||||
|
||||
if (n_components == 2)
|
||||
_cogl_matrix_transform_points_f2 (matrix,
|
||||
stride_in, points_in,
|
||||
stride_out, points_out,
|
||||
n_points);
|
||||
else
|
||||
{
|
||||
g_return_if_fail (n_components == 3);
|
||||
|
||||
_cogl_matrix_transform_points_f3 (matrix,
|
||||
stride_in, points_in,
|
||||
stride_out, points_out,
|
||||
n_points);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_project_points (const CoglMatrix *matrix,
|
||||
int n_components,
|
||||
size_t stride_in,
|
||||
const void *points_in,
|
||||
size_t stride_out,
|
||||
void *points_out,
|
||||
int n_points)
|
||||
{
|
||||
if (n_components == 2)
|
||||
_cogl_matrix_project_points_f2 (matrix,
|
||||
stride_in, points_in,
|
||||
stride_out, points_out,
|
||||
n_points);
|
||||
else if (n_components == 3)
|
||||
_cogl_matrix_project_points_f3 (matrix,
|
||||
stride_in, points_in,
|
||||
stride_out, points_out,
|
||||
n_points);
|
||||
else
|
||||
{
|
||||
g_return_if_fail (n_components == 4);
|
||||
|
||||
_cogl_matrix_project_points_f4 (matrix,
|
||||
stride_in, points_in,
|
||||
stride_out, points_out,
|
||||
n_points);
|
||||
}
|
||||
}
|
@ -1,589 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_MATRIX_H
|
||||
#define __COGL_MATRIX_H
|
||||
|
||||
#include <glib.h>
|
||||
#include "cogl-types.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-matrix
|
||||
* @short_description: Fuctions for initializing and manipulating 4x4 matrices
|
||||
*
|
||||
* Matrices are used in Cogl to describe affine model-view transforms, texture
|
||||
* transforms, and projective transforms. This exposes a utility API that can
|
||||
* be used for direct manipulation of these matrices.
|
||||
*/
|
||||
|
||||
typedef struct _CoglMatrix CoglMatrix;
|
||||
|
||||
/**
|
||||
* CoglMatrix:
|
||||
*
|
||||
* A CoglMatrix holds a 4x4 transform matrix. This is a single precision,
|
||||
* column-major matrix which means it is compatible with what OpenGL expects.
|
||||
*
|
||||
* A CoglMatrix can represent transforms such as, rotations, scaling,
|
||||
* translation, sheering, and linear projections. You can combine these
|
||||
* transforms by multiplying multiple matrices in the order you want them
|
||||
* applied.
|
||||
*
|
||||
* The transformation of a vertex (x, y, z, w) by a CoglMatrix is given by:
|
||||
*
|
||||
* |[
|
||||
* x_new = xx * x + xy * y + xz * z + xw * w
|
||||
* y_new = yx * x + yy * y + yz * z + yw * w
|
||||
* z_new = zx * x + zy * y + zz * z + zw * w
|
||||
* w_new = wx * x + wy * y + wz * z + ww * w
|
||||
* ]|
|
||||
*
|
||||
* Where w is normally 1
|
||||
*
|
||||
* <note>You must consider the members of the CoglMatrix structure read only,
|
||||
* and all matrix modifications must be done via the cogl_matrix API. This
|
||||
* allows Cogl to annotate the matrices internally. Violation of this will give
|
||||
* undefined results. If you need to initialize a matrix with a constant other
|
||||
* than the identity matrix you can use cogl_matrix_init_from_array().</note>
|
||||
*/
|
||||
struct _CoglMatrix
|
||||
{
|
||||
/* column 0 */
|
||||
float xx;
|
||||
float yx;
|
||||
float zx;
|
||||
float wx;
|
||||
|
||||
/* column 1 */
|
||||
float xy;
|
||||
float yy;
|
||||
float zy;
|
||||
float wy;
|
||||
|
||||
/* column 2 */
|
||||
float xz;
|
||||
float yz;
|
||||
float zz;
|
||||
float wz;
|
||||
|
||||
/* column 3 */
|
||||
float xw;
|
||||
float yw;
|
||||
float zw;
|
||||
float ww;
|
||||
|
||||
/*< private >*/
|
||||
|
||||
/* Note: we may want to extend this later with private flags
|
||||
* and a cache of the inverse transform matrix. */
|
||||
float COGL_PRIVATE (inv)[16];
|
||||
unsigned long COGL_PRIVATE (type);
|
||||
unsigned long COGL_PRIVATE (flags);
|
||||
unsigned long COGL_PRIVATE (_padding3);
|
||||
};
|
||||
|
||||
/**
|
||||
* cogl_matrix_init_identity:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
*
|
||||
* Resets matrix to the identity matrix:
|
||||
*
|
||||
* |[
|
||||
* .xx=1; .xy=0; .xz=0; .xw=0;
|
||||
* .yx=0; .yy=1; .yz=0; .yw=0;
|
||||
* .zx=0; .zy=0; .zz=1; .zw=0;
|
||||
* .wx=0; .wy=0; .wz=0; .ww=1;
|
||||
* ]|
|
||||
*/
|
||||
void
|
||||
cogl_matrix_init_identity (CoglMatrix *matrix);
|
||||
|
||||
/**
|
||||
* cogl_matrix_multiply:
|
||||
* @result: The address of a 4x4 matrix to store the result in
|
||||
* @a: A 4x4 transformation matrix
|
||||
* @b: A 4x4 transformation matrix
|
||||
*
|
||||
* Multiplies the two supplied matrices together and stores
|
||||
* the resulting matrix inside @result.
|
||||
*
|
||||
* <note>It is possible to multiply the @a matrix in-place, so
|
||||
* @result can be equal to @a but can't be equal to @b.</note>
|
||||
*/
|
||||
void
|
||||
cogl_matrix_multiply (CoglMatrix *result,
|
||||
const CoglMatrix *a,
|
||||
const CoglMatrix *b);
|
||||
|
||||
/**
|
||||
* cogl_matrix_rotate:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @angle: The angle you want to rotate in degrees
|
||||
* @x: X component of your rotation vector
|
||||
* @y: Y component of your rotation vector
|
||||
* @z: Z component of your rotation vector
|
||||
*
|
||||
* Multiplies @matrix with a rotation matrix that applies a rotation
|
||||
* of @angle degrees around the specified 3D vector.
|
||||
*/
|
||||
void
|
||||
cogl_matrix_rotate (CoglMatrix *matrix,
|
||||
float angle,
|
||||
float x,
|
||||
float y,
|
||||
float z);
|
||||
|
||||
/**
|
||||
* cogl_matrix_translate:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @x: The X translation you want to apply
|
||||
* @y: The Y translation you want to apply
|
||||
* @z: The Z translation you want to apply
|
||||
*
|
||||
* Multiplies @matrix with a transform matrix that translates along
|
||||
* the X, Y and Z axis.
|
||||
*/
|
||||
void
|
||||
cogl_matrix_translate (CoglMatrix *matrix,
|
||||
float x,
|
||||
float y,
|
||||
float z);
|
||||
|
||||
/**
|
||||
* cogl_matrix_scale:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @sx: The X scale factor
|
||||
* @sy: The Y scale factor
|
||||
* @sz: The Z scale factor
|
||||
*
|
||||
* Multiplies @matrix with a transform matrix that scales along the X,
|
||||
* Y and Z axis.
|
||||
*/
|
||||
void
|
||||
cogl_matrix_scale (CoglMatrix *matrix,
|
||||
float sx,
|
||||
float sy,
|
||||
float sz);
|
||||
|
||||
/**
|
||||
* cogl_matrix_frustum:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @left: coord of left vertical clipping plane
|
||||
* @right: coord of right vertical clipping plane
|
||||
* @bottom: coord of bottom horizontal clipping plane
|
||||
* @top: coord of top horizontal clipping plane
|
||||
* @z_near: positive distance to near depth clipping plane
|
||||
* @z_far: positive distance to far depth clipping plane
|
||||
*
|
||||
* Multiplies @matrix by the given frustum perspective matrix.
|
||||
*/
|
||||
void
|
||||
cogl_matrix_frustum (CoglMatrix *matrix,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float z_near,
|
||||
float z_far);
|
||||
|
||||
/**
|
||||
* cogl_matrix_perspective:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @fov_y: A field of view angle for the Y axis
|
||||
* @aspect: The ratio of width to height determining the field of view angle
|
||||
* for the x axis.
|
||||
* @z_near: The distance to the near clip plane. Never pass 0 and always pass
|
||||
* a positive number.
|
||||
* @z_far: The distance to the far clip plane. (Should always be positive)
|
||||
*
|
||||
* Multiplies @matrix by the described perspective matrix
|
||||
*
|
||||
* <note>You should be careful not to have to great a @z_far / @z_near ratio
|
||||
* since that will reduce the effectiveness of depth testing since there wont
|
||||
* be enough precision to identify the depth of objects near to each
|
||||
* other.</note>
|
||||
*/
|
||||
void
|
||||
cogl_matrix_perspective (CoglMatrix *matrix,
|
||||
float fov_y,
|
||||
float aspect,
|
||||
float z_near,
|
||||
float z_far);
|
||||
|
||||
/**
|
||||
* cogl_matrix_ortho:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @left: The coordinate for the left clipping plane
|
||||
* @right: The coordinate for the right clipping plane
|
||||
* @bottom: The coordinate for the bottom clipping plane
|
||||
* @top: The coordinate for the top clipping plane
|
||||
* @z_near: The coordinate for the near clipping plane (may be negative if
|
||||
* the plane is behind the viewer)
|
||||
* @z_far: The coordinate for the far clipping plane (may be negative if
|
||||
* the plane is behind the viewer)
|
||||
*
|
||||
* Multiplies @matrix by a parallel projection matrix.
|
||||
*/
|
||||
void
|
||||
cogl_matrix_ortho (CoglMatrix *matrix,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float z_near,
|
||||
float z_far);
|
||||
|
||||
#ifdef COGL_ENABLE_EXPERIMENTAL_API
|
||||
#define cogl_matrix_view_2d_in_frustum cogl_matrix_view_2d_in_frustum_EXP
|
||||
#define cogl_matrix_view_2d_in_perspective \
|
||||
cogl_matrix_view_2d_in_perspective_EXP
|
||||
|
||||
/**
|
||||
* cogl_matrix_view_2d_in_frustum:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @left: coord of left vertical clipping plane
|
||||
* @right: coord of right vertical clipping plane
|
||||
* @bottom: coord of bottom horizontal clipping plane
|
||||
* @top: coord of top horizontal clipping plane
|
||||
* @z_near: The distance to the near clip plane. Never pass 0 and always pass
|
||||
* a positive number.
|
||||
* @z_2d: The distance to the 2D plane. (Should always be positive and
|
||||
* be between @z_near and the z_far value that was passed to
|
||||
* cogl_matrix_frustum())
|
||||
* @width_2d: The width of the 2D coordinate system
|
||||
* @height_2d: The height of the 2D coordinate system
|
||||
*
|
||||
* Multiplies @matrix by a view transform that maps the 2D coordinates
|
||||
* (0,0) top left and (@width_2d,@height_2d) bottom right the full viewport
|
||||
* size. Geometry at a depth of 0 will now lie on this 2D plane.
|
||||
*
|
||||
* Note: this doesn't multiply the matrix by any projection matrix,
|
||||
* but it assumes you have a perspective projection as defined by
|
||||
* passing the corresponding arguments to cogl_matrix_frustum().
|
||||
|
||||
* Toolkits such as Clutter that mix 2D and 3D drawing can use this to
|
||||
* create a 2D coordinate system within a 3D perspective projected
|
||||
* view frustum.
|
||||
*/
|
||||
void
|
||||
cogl_matrix_view_2d_in_frustum (CoglMatrix *matrix,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float z_near,
|
||||
float z_2d,
|
||||
float width_2d,
|
||||
float height_2d);
|
||||
|
||||
/**
|
||||
* cogl_matrix_view_2d_in_perspective:
|
||||
* @fov_y: A field of view angle for the Y axis
|
||||
* @aspect: The ratio of width to height determining the field of view angle
|
||||
* for the x axis.
|
||||
* @z_near: The distance to the near clip plane. Never pass 0 and always pass
|
||||
* a positive number.
|
||||
* @z_2d: The distance to the 2D plane. (Should always be positive and
|
||||
* be between @z_near and the z_far value that was passed to
|
||||
* cogl_matrix_frustum())
|
||||
* @width_2d: The width of the 2D coordinate system
|
||||
* @height_2d: The height of the 2D coordinate system
|
||||
*
|
||||
* Multiplies @matrix by a view transform that maps the 2D coordinates
|
||||
* (0,0) top left and (@width_2d,@height_2d) bottom right the full viewport
|
||||
* size. Geometry at a depth of 0 will now lie on this 2D plane.
|
||||
*
|
||||
* Note: this doesn't multiply the matrix by any projection matrix,
|
||||
* but it assumes you have a perspective projection as defined by
|
||||
* passing the corresponding arguments to cogl_matrix_perspective().
|
||||
*
|
||||
* Toolkits such as Clutter that mix 2D and 3D drawing can use this to
|
||||
* create a 2D coordinate system within a 3D perspective projected
|
||||
* view frustum.
|
||||
|
||||
*/
|
||||
void
|
||||
cogl_matrix_view_2d_in_perspective (CoglMatrix *matrix,
|
||||
float fov_y,
|
||||
float aspect,
|
||||
float z_near,
|
||||
float z_2d,
|
||||
float width_2d,
|
||||
float height_2d);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* cogl_matrix_init_from_array:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @array: A linear array of 16 floats (column-major order)
|
||||
*
|
||||
* Initializes @matrix with the contents of @array
|
||||
*/
|
||||
void
|
||||
cogl_matrix_init_from_array (CoglMatrix *matrix,
|
||||
const float *array);
|
||||
|
||||
/**
|
||||
* cogl_matrix_get_array:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
*
|
||||
* Casts @matrix to a float array which can be directly passed to OpenGL.
|
||||
*
|
||||
* Return value: a pointer to the float array
|
||||
*/
|
||||
G_CONST_RETURN float *
|
||||
cogl_matrix_get_array (const CoglMatrix *matrix);
|
||||
|
||||
/**
|
||||
* cogl_matrix_equal:
|
||||
* @v1: A 4x4 transformation matrix
|
||||
* @v2: A 4x4 transformation matrix
|
||||
*
|
||||
* Compares two matrices to see if they represent the same
|
||||
* transformation. Although internally the matrices may have different
|
||||
* annotations associated with them and may potentially have a cached
|
||||
* inverse matrix these are not considered in the comparison.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
gboolean
|
||||
cogl_matrix_equal (gconstpointer v1, gconstpointer v2);
|
||||
|
||||
/**
|
||||
* cogl_matrix_copy:
|
||||
* @matrix: A 4x4 transformation matrix you want to copy
|
||||
*
|
||||
* Allocates a new #CoglMatrix on the heap and initializes it with
|
||||
* the same values as @matrix.
|
||||
*
|
||||
* Returns: A newly allocated #CoglMatrix which should be freed using
|
||||
* cogl_matrix_free()
|
||||
*
|
||||
* Since: 1.6
|
||||
*/
|
||||
CoglMatrix *
|
||||
cogl_matrix_copy (const CoglMatrix *matrix);
|
||||
|
||||
/**
|
||||
* cogl_matrix_free:
|
||||
* @matrix: A 4x4 transformation matrix you want to free
|
||||
*
|
||||
* Frees a #CoglMatrix that was previously allocated via a call to
|
||||
* cogl_matrix_copy().
|
||||
*
|
||||
* Since: 1.6
|
||||
*/
|
||||
void
|
||||
cogl_matrix_free (CoglMatrix *matrix);
|
||||
|
||||
/**
|
||||
* cogl_matrix_get_inverse:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @inverse: (out): The destination for a 4x4 inverse transformation matrix
|
||||
*
|
||||
* Gets the inverse transform of a given matrix and uses it to initialize
|
||||
* a new #CoglMatrix.
|
||||
*
|
||||
* <note>Although the first parameter is annotated as const to indicate
|
||||
* that the transform it represents isn't modified this function may
|
||||
* technically save a copy of the inverse transform within the given
|
||||
* #CoglMatrix so that subsequent requests for the inverse transform may
|
||||
* avoid costly inversion calculations.</note>
|
||||
*
|
||||
* Return value: %TRUE if the inverse was successfully calculated or %FALSE
|
||||
* for degenerate transformations that can't be inverted (in this case the
|
||||
* @inverse matrix will simply be initialized with the identity matrix)
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
gboolean
|
||||
cogl_matrix_get_inverse (const CoglMatrix *matrix,
|
||||
CoglMatrix *inverse);
|
||||
|
||||
/* FIXME: to be consistent with cogl_matrix_{transform,project}_points
|
||||
* this could be renamed to cogl_matrix_project_point for Cogl 2.0...
|
||||
*/
|
||||
|
||||
/**
|
||||
* cogl_matrix_transform_point:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @x: (inout): The X component of your points position
|
||||
* @y: (inout): The Y component of your points position
|
||||
* @z: (inout): The Z component of your points position
|
||||
* @w: (inout): The W component of your points position
|
||||
*
|
||||
* Transforms a point whos position is given and returned as four float
|
||||
* components.
|
||||
*/
|
||||
void
|
||||
cogl_matrix_transform_point (const CoglMatrix *matrix,
|
||||
float *x,
|
||||
float *y,
|
||||
float *z,
|
||||
float *w);
|
||||
|
||||
#ifdef COGL_ENABLE_EXPERIMENTAL_API
|
||||
#define cogl_matrix_transform_points cogl_matrix_transform_points_EXP
|
||||
#define cogl_matrix_project_points cogl_matrix_project_points_EXP
|
||||
|
||||
/**
|
||||
* cogl_matrix_transform_points:
|
||||
* @matrix: A transformation matrix
|
||||
* @n_components: The number of position components for each input point.
|
||||
* (either 2 or 3)
|
||||
* @stride_in: The stride in bytes between input points.
|
||||
* @points_in: A pointer to the first component of the first input point.
|
||||
* @stride_out: The stride in bytes between output points.
|
||||
* @points_out: A pointer to the first component of the first output point.
|
||||
* @n_points: The number of points to transform.
|
||||
*
|
||||
* Transforms an array of input points and writes the result to
|
||||
* another array of output points. The input points can either have 2
|
||||
* or 3 components each. The output points always have 3 components.
|
||||
* The output array can simply point to the input array to do the
|
||||
* transform in-place.
|
||||
*
|
||||
* If you need to transform 4 component points see
|
||||
* cogl_matrix_project_points().
|
||||
*
|
||||
* Here's an example with differing input/output strides:
|
||||
* |[
|
||||
* typedef struct {
|
||||
* float x,y;
|
||||
* guint8 r,g,b,a;
|
||||
* float s,t,p;
|
||||
* } MyInVertex;
|
||||
* typedef struct {
|
||||
* guint8 r,g,b,a;
|
||||
* float x,y,z;
|
||||
* } MyOutVertex;
|
||||
* MyInVertex vertices[N_VERTICES];
|
||||
* MyOutVertex results[N_VERTICES];
|
||||
* CoglMatrix matrix;
|
||||
*
|
||||
* my_load_vertices (vertices);
|
||||
* my_get_matrix (&matrix);
|
||||
*
|
||||
* cogl_matrix_transform_points (&matrix,
|
||||
* 2,
|
||||
* sizeof (MyInVertex),
|
||||
* &vertices[0].x,
|
||||
* sizeof (MyOutVertex),
|
||||
* &results[0].x,
|
||||
* N_VERTICES);
|
||||
* ]|
|
||||
*
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_matrix_transform_points (const CoglMatrix *matrix,
|
||||
int n_components,
|
||||
size_t stride_in,
|
||||
const void *points_in,
|
||||
size_t stride_out,
|
||||
void *points_out,
|
||||
int n_points);
|
||||
|
||||
/**
|
||||
* cogl_matrix_project_points:
|
||||
* @matrix: A projection matrix
|
||||
* @n_components: The number of position components for each input point.
|
||||
* (either 2, 3 or 4)
|
||||
* @stride_in: The stride in bytes between input points.
|
||||
* @points_in: A pointer to the first component of the first input point.
|
||||
* @stride_out: The stride in bytes between output points.
|
||||
* @points_out: A pointer to the first component of the first output point.
|
||||
* @n_points: The number of points to transform.
|
||||
*
|
||||
* Projects an array of input points and writes the result to another
|
||||
* array of output points. The input points can either have 2, 3 or 4
|
||||
* components each. The output points always have 4 components (known
|
||||
* as homogenous coordinates). The output array can simply point to
|
||||
* the input array to do the transform in-place.
|
||||
*
|
||||
* Here's an example with differing input/output strides:
|
||||
* |[
|
||||
* typedef struct {
|
||||
* float x,y;
|
||||
* guint8 r,g,b,a;
|
||||
* float s,t,p;
|
||||
* } MyInVertex;
|
||||
* typedef struct {
|
||||
* guint8 r,g,b,a;
|
||||
* float x,y,z;
|
||||
* } MyOutVertex;
|
||||
* MyInVertex vertices[N_VERTICES];
|
||||
* MyOutVertex results[N_VERTICES];
|
||||
* CoglMatrix matrix;
|
||||
*
|
||||
* my_load_vertices (vertices);
|
||||
* my_get_matrix (&matrix);
|
||||
*
|
||||
* cogl_matrix_project_points (&matrix,
|
||||
* 2,
|
||||
* sizeof (MyInVertex),
|
||||
* &vertices[0].x,
|
||||
* sizeof (MyOutVertex),
|
||||
* &results[0].x,
|
||||
* N_VERTICES);
|
||||
* ]|
|
||||
*
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_matrix_project_points (const CoglMatrix *matrix,
|
||||
int n_components,
|
||||
size_t stride_in,
|
||||
const void *points_in,
|
||||
size_t stride_out,
|
||||
void *points_out,
|
||||
int n_points);
|
||||
|
||||
#endif /* COGL_ENABLE_EXPERIMENTAL_API */
|
||||
|
||||
#ifdef _COGL_SUPPORTS_GTYPE_INTEGRATION
|
||||
|
||||
#define COGL_GTYPE_TYPE_MATRIX (cogl_gtype_matrix_get_type ())
|
||||
|
||||
/**
|
||||
* cogl_gtype_matrix_get_type:
|
||||
*
|
||||
* Returns the GType for the registered "CoglMatrix" boxed type. This
|
||||
* can be used for example to define GObject properties that accept a
|
||||
* #CoglMatrix value.
|
||||
*/
|
||||
GType
|
||||
cogl_gtype_matrix_get_type (void);
|
||||
|
||||
#endif /* _COGL_SUPPORTS_GTYPE_INTEGRATION */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_MATRIX_H */
|
||||
|
@ -1,276 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_OBJECT_PRIVATE_H
|
||||
#define __COGL_OBJECT_PRIVATE_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl-types.h"
|
||||
#include "cogl-object.h"
|
||||
#include "cogl-debug.h"
|
||||
|
||||
/* For compatability until all components have been converted */
|
||||
typedef struct _CoglObjectClass CoglHandleClass;
|
||||
typedef struct _CoglObject CoglHandleObject;
|
||||
|
||||
/* XXX: sadly we didn't fully consider when we copied the cairo API
|
||||
* for _set_user_data that the callback doesn't get a pointer to the
|
||||
* instance which is desired in most cases. This means you tend to end
|
||||
* up creating micro allocations for the private data just so you can
|
||||
* pair up the data of interest with the original instance for
|
||||
* identification when it is later destroyed.
|
||||
*
|
||||
* Internally we use a small hack to avoid needing these micro
|
||||
* allocations by actually passing the instance as a second argument
|
||||
* to the callback */
|
||||
typedef void (*CoglUserDataDestroyInternalCallback) (void *user_data,
|
||||
void *instance);
|
||||
|
||||
typedef struct _CoglObjectClass
|
||||
{
|
||||
GQuark type;
|
||||
void *virt_free;
|
||||
} CoglObjectClass;
|
||||
|
||||
#define COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CoglUserDataKey *key;
|
||||
void *user_data;
|
||||
CoglUserDataDestroyInternalCallback destroy;
|
||||
} CoglUserDataEntry;
|
||||
|
||||
/* All Cogl objects inherit from this base object by adding a member:
|
||||
*
|
||||
* CoglObject _parent;
|
||||
*
|
||||
* at the top of its main structure. This structure is initialized
|
||||
* when you call _cogl_#type_name#_object_new (new_object);
|
||||
*/
|
||||
struct _CoglObject
|
||||
{
|
||||
unsigned int ref_count;
|
||||
|
||||
CoglUserDataEntry user_data_entry[
|
||||
COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES];
|
||||
GArray *user_data_array;
|
||||
int n_user_data_entries;
|
||||
|
||||
CoglObjectClass *klass;
|
||||
};
|
||||
|
||||
/* Helper macro to encapsulate the common code for COGL reference
|
||||
counted objects */
|
||||
|
||||
#ifdef COGL_OBJECT_DEBUG
|
||||
|
||||
#define _COGL_OBJECT_DEBUG_NEW(type_name, obj) \
|
||||
COGL_NOTE (HANDLE, "COGL " G_STRINGIFY (type_name) " NEW %p %i", \
|
||||
(obj), (obj)->ref_count)
|
||||
|
||||
#define _COGL_OBJECT_DEBUG_REF(type_name, object) G_STMT_START { \
|
||||
CoglObject *__obj = (CoglObject *)object; \
|
||||
COGL_NOTE (HANDLE, "COGL %s REF %p %i", \
|
||||
g_quark_to_string ((__obj)->klass->type), \
|
||||
(__obj), (__obj)->ref_count); } G_STMT_END
|
||||
|
||||
#define _COGL_OBJECT_DEBUG_UNREF(type_name, object) G_STMT_START { \
|
||||
CoglObject *__obj = (CoglObject *)object; \
|
||||
COGL_NOTE (HANDLE, "COGL %s UNREF %p %i", \
|
||||
g_quark_to_string ((__obj)->klass->type), \
|
||||
(__obj), (__obj)->ref_count - 1); } G_STMT_END
|
||||
|
||||
#define COGL_OBJECT_DEBUG_FREE(obj) \
|
||||
COGL_NOTE (HANDLE, "COGL %s FREE %p", \
|
||||
g_quark_to_string ((obj)->klass->type), (obj))
|
||||
|
||||
#else /* !COGL_OBJECT_DEBUG */
|
||||
|
||||
#define _COGL_OBJECT_DEBUG_NEW(type_name, obj)
|
||||
#define _COGL_OBJECT_DEBUG_REF(type_name, obj)
|
||||
#define _COGL_OBJECT_DEBUG_UNREF(type_name, obj)
|
||||
#define COGL_OBJECT_DEBUG_FREE(obj)
|
||||
|
||||
#endif /* COGL_OBJECT_DEBUG */
|
||||
|
||||
/* For temporary compatability */
|
||||
#define _COGL_HANDLE_DEBUG_NEW _COGL_OBJECT_DEBUG_NEW
|
||||
#define _COGL_HANDLE_DEBUG_REF _COGL_OBJECT_DEBUG_REF
|
||||
#define _COGL_HANDLE_DEBUG_UNREF _COGL_OBJECT_DEBUG_UNREF
|
||||
#define COGL_HANDLE_DEBUG_FREE COGL_OBJECT_DEBUG_FREE
|
||||
|
||||
#define COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
||||
\
|
||||
static CoglObjectClass _cogl_##type_name##_class; \
|
||||
\
|
||||
GQuark \
|
||||
_cogl_object_##type_name##_get_type (void) \
|
||||
{ \
|
||||
static GQuark type = 0; \
|
||||
if (!type) \
|
||||
{ \
|
||||
type = g_quark_from_static_string ("Cogl"#TypeName); \
|
||||
{ code; } \
|
||||
} \
|
||||
return type; \
|
||||
} \
|
||||
\
|
||||
GQuark \
|
||||
_cogl_handle_##type_name##_get_type (void) \
|
||||
{ \
|
||||
return _cogl_object_##type_name##_get_type (); \
|
||||
} \
|
||||
\
|
||||
static Cogl##TypeName * \
|
||||
_cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \
|
||||
{ \
|
||||
CoglObject *obj = (CoglObject *)&new_obj->_parent; \
|
||||
obj->ref_count = 1; \
|
||||
obj->n_user_data_entries = 0; \
|
||||
obj->user_data_array = NULL; \
|
||||
\
|
||||
obj->klass = &_cogl_##type_name##_class; \
|
||||
if (!obj->klass->type) \
|
||||
{ \
|
||||
obj->klass->type = _cogl_object_##type_name##_get_type ();\
|
||||
obj->klass->virt_free = _cogl_##type_name##_free; \
|
||||
} \
|
||||
\
|
||||
_COGL_OBJECT_DEBUG_NEW (TypeName, obj); \
|
||||
return new_obj; \
|
||||
} \
|
||||
\
|
||||
Cogl##TypeName * \
|
||||
_cogl_##type_name##_pointer_from_handle (CoglHandle handle) \
|
||||
{ \
|
||||
return handle; \
|
||||
}
|
||||
|
||||
#define COGL_OBJECT_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
||||
\
|
||||
COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
||||
\
|
||||
gboolean \
|
||||
cogl_is_##type_name (void *object) \
|
||||
{ \
|
||||
CoglObject *obj = object; \
|
||||
\
|
||||
if (object == NULL) \
|
||||
return FALSE; \
|
||||
\
|
||||
return (obj->klass->type == \
|
||||
_cogl_object_##type_name##_get_type ()); \
|
||||
}
|
||||
|
||||
#define COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
||||
\
|
||||
COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
||||
\
|
||||
gboolean \
|
||||
_cogl_is_##type_name (void *object) \
|
||||
{ \
|
||||
CoglObject *obj = object; \
|
||||
\
|
||||
if (object == NULL) \
|
||||
return FALSE; \
|
||||
\
|
||||
return (obj->klass->type == \
|
||||
_cogl_object_##type_name##_get_type ()); \
|
||||
}
|
||||
|
||||
#define COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING(type_name) \
|
||||
\
|
||||
void * G_GNUC_DEPRECATED \
|
||||
cogl_##type_name##_ref (void *object) \
|
||||
{ \
|
||||
if (!cogl_is_##type_name (object)) \
|
||||
return NULL; \
|
||||
\
|
||||
_COGL_OBJECT_DEBUG_REF (TypeName, object); \
|
||||
\
|
||||
cogl_handle_ref (object); \
|
||||
\
|
||||
return object; \
|
||||
} \
|
||||
\
|
||||
void G_GNUC_DEPRECATED \
|
||||
cogl_##type_name##_unref (void *object) \
|
||||
{ \
|
||||
if (!cogl_is_##type_name (object)) \
|
||||
{ \
|
||||
g_warning (G_STRINGIFY (cogl_##type_name##_unref) \
|
||||
": Ignoring unref of Cogl handle " \
|
||||
"due to type mismatch"); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
_COGL_OBJECT_DEBUG_UNREF (TypeName, object); \
|
||||
\
|
||||
cogl_handle_unref (object); \
|
||||
}
|
||||
|
||||
#define COGL_OBJECT_DEFINE(TypeName, type_name) \
|
||||
COGL_OBJECT_DEFINE_WITH_CODE (TypeName, type_name, (void) 0)
|
||||
|
||||
#define COGL_OBJECT_INTERNAL_DEFINE(TypeName, type_name) \
|
||||
COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE (TypeName, type_name, (void) 0)
|
||||
|
||||
/* For temporary compatability */
|
||||
#define COGL_HANDLE_INTERNAL_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
||||
\
|
||||
COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE (TypeName, type_name, code) \
|
||||
\
|
||||
static Cogl##TypeName * \
|
||||
_cogl_##type_name##_handle_new (CoglHandle handle) \
|
||||
{ \
|
||||
return _cogl_##type_name##_object_new (handle); \
|
||||
}
|
||||
|
||||
#define COGL_HANDLE_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
||||
\
|
||||
COGL_OBJECT_DEFINE_WITH_CODE (TypeName, type_name, code) \
|
||||
\
|
||||
static Cogl##TypeName * \
|
||||
_cogl_##type_name##_handle_new (CoglHandle handle) \
|
||||
{ \
|
||||
return _cogl_##type_name##_object_new (handle); \
|
||||
}
|
||||
|
||||
#define COGL_HANDLE_INTERNAL_DEFINE(TypeName, type_name) \
|
||||
COGL_HANDLE_INTERNAL_DEFINE_WITH_CODE (TypeName, type_name, (void) 0)
|
||||
|
||||
#define COGL_HANDLE_DEFINE(TypeName, type_name) \
|
||||
COGL_HANDLE_DEFINE_WITH_CODE (TypeName, type_name, (void) 0)
|
||||
|
||||
void
|
||||
_cogl_object_set_user_data (CoglObject *object,
|
||||
CoglUserDataKey *key,
|
||||
void *user_data,
|
||||
CoglUserDataDestroyInternalCallback destroy);
|
||||
|
||||
#endif /* __COGL_OBJECT_PRIVATE_H */
|
||||
|
@ -1,249 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cogl-types.h"
|
||||
#include "cogl-object-private.h"
|
||||
|
||||
void *
|
||||
cogl_object_ref (void *object)
|
||||
{
|
||||
CoglObject *obj = object;
|
||||
|
||||
g_return_val_if_fail (object != NULL, NULL);
|
||||
|
||||
obj->ref_count++;
|
||||
return object;
|
||||
}
|
||||
|
||||
CoglHandle
|
||||
cogl_handle_ref (CoglHandle handle)
|
||||
{
|
||||
return cogl_object_ref (handle);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_object_unref (void *object)
|
||||
{
|
||||
CoglObject *obj = object;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (obj->ref_count > 0);
|
||||
|
||||
if (--obj->ref_count < 1)
|
||||
{
|
||||
void (*free_func)(void *obj);
|
||||
|
||||
if (obj->n_user_data_entries)
|
||||
{
|
||||
int i;
|
||||
int count = MIN (obj->n_user_data_entries,
|
||||
COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
CoglUserDataEntry *entry = &obj->user_data_entry[i];
|
||||
if (entry->destroy)
|
||||
entry->destroy (entry->user_data, obj);
|
||||
}
|
||||
|
||||
if (obj->user_data_array != NULL)
|
||||
{
|
||||
for (i = 0; i < obj->user_data_array->len; i++)
|
||||
{
|
||||
CoglUserDataEntry *entry =
|
||||
&g_array_index (obj->user_data_array,
|
||||
CoglUserDataEntry, i);
|
||||
|
||||
if (entry->destroy)
|
||||
entry->destroy (entry->user_data, obj);
|
||||
}
|
||||
g_array_free (obj->user_data_array, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
COGL_OBJECT_DEBUG_FREE (obj);
|
||||
free_func = obj->klass->virt_free;
|
||||
free_func (obj);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cogl_handle_unref (CoglHandle handle)
|
||||
{
|
||||
cogl_object_unref (handle);
|
||||
}
|
||||
|
||||
GType
|
||||
cogl_handle_get_type (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
/* XXX: We are keeping the "CoglHandle" name for now incase it would
|
||||
* break bindings to change to "CoglObject" */
|
||||
if (G_UNLIKELY (our_type == 0))
|
||||
our_type = g_boxed_type_register_static (g_intern_static_string ("CoglHandle"),
|
||||
(GBoxedCopyFunc) cogl_object_ref,
|
||||
(GBoxedFreeFunc) cogl_object_unref);
|
||||
|
||||
return our_type;
|
||||
}
|
||||
|
||||
/* XXX: Unlike for cogl_object_get_user_data this code will return
|
||||
* an empty entry if available and no entry for the given key can be
|
||||
* found. */
|
||||
static CoglUserDataEntry *
|
||||
_cogl_object_find_entry (CoglObject *object, CoglUserDataKey *key)
|
||||
{
|
||||
CoglUserDataEntry *entry = NULL;
|
||||
int count;
|
||||
int i;
|
||||
|
||||
count = MIN (object->n_user_data_entries,
|
||||
COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
CoglUserDataEntry *current = &object->user_data_entry[i];
|
||||
if (current->key == key)
|
||||
return current;
|
||||
if (current->user_data == NULL)
|
||||
entry = current;
|
||||
}
|
||||
|
||||
if (G_UNLIKELY (object->user_data_array != NULL))
|
||||
{
|
||||
for (i = 0; i < object->user_data_array->len; i++)
|
||||
{
|
||||
CoglUserDataEntry *current =
|
||||
&g_array_index (object->user_data_array, CoglUserDataEntry, i);
|
||||
|
||||
if (current->key == key)
|
||||
return current;
|
||||
if (current->user_data == NULL)
|
||||
entry = current;
|
||||
}
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_object_set_user_data (CoglObject *object,
|
||||
CoglUserDataKey *key,
|
||||
void *user_data,
|
||||
CoglUserDataDestroyInternalCallback destroy)
|
||||
{
|
||||
CoglUserDataEntry new_entry;
|
||||
CoglUserDataEntry *entry;
|
||||
|
||||
if (user_data)
|
||||
{
|
||||
new_entry.key = key;
|
||||
new_entry.user_data = user_data;
|
||||
new_entry.destroy = destroy;
|
||||
}
|
||||
else
|
||||
memset (&new_entry, 0, sizeof (new_entry));
|
||||
|
||||
entry = _cogl_object_find_entry (object, key);
|
||||
if (entry)
|
||||
{
|
||||
if (G_LIKELY (entry->destroy))
|
||||
entry->destroy (entry->user_data, object);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (G_LIKELY (object->n_user_data_entries <
|
||||
COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES))
|
||||
entry = &object->user_data_entry[object->n_user_data_entries++];
|
||||
else
|
||||
{
|
||||
if (G_UNLIKELY (object->user_data_array == NULL))
|
||||
{
|
||||
object->user_data_array =
|
||||
g_array_new (FALSE, FALSE, sizeof (CoglUserDataEntry));
|
||||
}
|
||||
|
||||
g_array_set_size (object->user_data_array,
|
||||
object->user_data_array->len + 1);
|
||||
entry =
|
||||
&g_array_index (object->user_data_array, CoglUserDataEntry,
|
||||
object->user_data_array->len - 1);
|
||||
|
||||
object->n_user_data_entries++;
|
||||
}
|
||||
}
|
||||
|
||||
*entry = new_entry;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_object_set_user_data (CoglObject *object,
|
||||
CoglUserDataKey *key,
|
||||
void *user_data,
|
||||
CoglUserDataDestroyCallback destroy)
|
||||
{
|
||||
_cogl_object_set_user_data (object, key, user_data,
|
||||
(CoglUserDataDestroyInternalCallback)destroy);
|
||||
}
|
||||
|
||||
void *
|
||||
cogl_object_get_user_data (CoglObject *object, CoglUserDataKey *key)
|
||||
{
|
||||
int count;
|
||||
int i;
|
||||
|
||||
count = MIN (object->n_user_data_entries,
|
||||
COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
CoglUserDataEntry *entry = &object->user_data_entry[i];
|
||||
if (entry->key == key)
|
||||
return entry->user_data;
|
||||
}
|
||||
|
||||
if (object->user_data_array != NULL)
|
||||
{
|
||||
for (i = 0; i < object->user_data_array->len; i++)
|
||||
{
|
||||
CoglUserDataEntry *entry =
|
||||
&g_array_index (object->user_data_array, CoglUserDataEntry, i);
|
||||
|
||||
if (entry->key == key)
|
||||
return entry->user_data;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2009,2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_OBJECT_H
|
||||
#define __COGL_OBJECT_H
|
||||
|
||||
typedef struct _CoglObject CoglObject;
|
||||
|
||||
#define COGL_OBJECT(X) ((CoglObject *)X)
|
||||
|
||||
/**
|
||||
* CoglUserDataKey:
|
||||
* @unused: ignored.
|
||||
*
|
||||
* A #CoglUserDataKey is used to declare a key for attaching data to a
|
||||
* #CoglObject using cogl_object_set_user_data. The typedef only exists as a
|
||||
* formality to make code self documenting since only the unique address of a
|
||||
* #CoglUserDataKey is used.
|
||||
*
|
||||
* Typically you would declare a static #CoglUserDataKey and set private data
|
||||
* on an object something like this:
|
||||
*
|
||||
* |[
|
||||
* static CoglUserDataKey path_private_key;
|
||||
*
|
||||
* static void
|
||||
* destroy_path_private_cb (void *data)
|
||||
* {
|
||||
* g_free (data);
|
||||
* }
|
||||
*
|
||||
* static void
|
||||
* my_path_set_data (CoglPath *path, void *data)
|
||||
* {
|
||||
* cogl_object_set_user_data (COGL_OBJECT (path),
|
||||
* &private_key,
|
||||
* data,
|
||||
* destroy_path_private_cb);
|
||||
* }
|
||||
* ]|
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int unused;
|
||||
} CoglUserDataKey;
|
||||
|
||||
/**
|
||||
* CoglUserDataDestroyCallback:
|
||||
* @user_data: The data whos association with a #CoglObject has been
|
||||
* destoyed.
|
||||
*
|
||||
* When associating private data with a #CoglObject a callback can be
|
||||
* given which will be called either if the object is destroyed or if
|
||||
* cogl_object_set_user_data() is called with NULL user_data for the
|
||||
* same key.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
typedef void (*CoglUserDataDestroyCallback) (void *user_data);
|
||||
|
||||
/**
|
||||
* cogl_object_set_user_data: (skip)
|
||||
* @object: The object to associate private data with
|
||||
* @key: The address of a #CoglUserDataKey which provides a unique value
|
||||
* with which to index the private data.
|
||||
* @user_data: The data to associate with the given object,
|
||||
* or %NULL to remove a previous association.
|
||||
* @destroy: A #CoglUserDataDestroyCallback to call if the object is
|
||||
* destroyed or if the association is removed by later setting
|
||||
* %NULL data for the same key.
|
||||
*
|
||||
* Associates some private @user_data with a given #CoglObject. To
|
||||
* later remove the association call cogl_object_set_user_data() with
|
||||
* the same @key but NULL for the @user_data.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_object_set_user_data (CoglObject *object,
|
||||
CoglUserDataKey *key,
|
||||
void *user_data,
|
||||
CoglUserDataDestroyCallback destroy);
|
||||
|
||||
/**
|
||||
* cogl_object_get_user_data: (skip)
|
||||
* @object: The object with associated private data to query
|
||||
* @key: The address of a #CoglUserDataKey which provides a unique value
|
||||
* with which to index the private data.
|
||||
*
|
||||
* Finds the user data previously associated with @object using
|
||||
* the given @key. If no user data has been associated with @object
|
||||
* for the given @key this function returns NULL.
|
||||
*
|
||||
* Returns: (transfer none): The user data previously associated
|
||||
* with @object using the given @key; or %NULL if no associated
|
||||
* data is found.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void *
|
||||
cogl_object_get_user_data (CoglObject *object,
|
||||
CoglUserDataKey *key);
|
||||
#endif /* __COGL_OBJECT_H */
|
||||
|
@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_OFFSCREEN_H__
|
||||
#define __COGL_OFFSCREEN_H__
|
||||
|
||||
#include <cogl/cogl-types.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-offscreen
|
||||
* @short_description: Fuctions for creating and manipulating offscreen
|
||||
* framebuffers.
|
||||
*
|
||||
* Cogl allows creating and operating on offscreen framebuffers.
|
||||
*/
|
||||
|
||||
/* Offscreen api */
|
||||
|
||||
/**
|
||||
* cogl_offscreen_new_to_texture:
|
||||
* @handle: A CoglHandle for a Cogl texture
|
||||
*
|
||||
* This creates an offscreen buffer object using the given texture as the
|
||||
* primary color buffer. It doesn't just initialize the contents of the
|
||||
* offscreen buffer with the texture; they are tightly bound so that
|
||||
* drawing to the offscreen buffer effectivly updates the contents of the
|
||||
* given texture. You don't need to destroy the offscreen buffer before
|
||||
* you can use the texture again.
|
||||
*
|
||||
* Note: This does not work with sliced Cogl textures.
|
||||
*
|
||||
* Return value: (transfer full): a #CoglHandle for the new offscreen
|
||||
* buffer or %COGL_INVALID_HANDLE if it wasn't possible to create the
|
||||
* buffer.
|
||||
*/
|
||||
CoglHandle cogl_offscreen_new_to_texture (CoglHandle handle);
|
||||
|
||||
/**
|
||||
* cogl_is_offscreen:
|
||||
* @handle: A CoglHandle for an offscreen buffer
|
||||
*
|
||||
* Determines whether the given #CoglHandle references an offscreen buffer
|
||||
* object.
|
||||
*
|
||||
* Returns: %TRUE if the handle references an offscreen buffer,
|
||||
* %FALSE otherwise
|
||||
*/
|
||||
gboolean cogl_is_offscreen (CoglHandle handle);
|
||||
|
||||
#ifndef COGL_DISABLE_DEPRECATED
|
||||
|
||||
/**
|
||||
* cogl_offscreen_ref:
|
||||
* @handle: A CoglHandle for an offscreen buffer
|
||||
*
|
||||
* Increments the reference count on the offscreen buffer.
|
||||
*
|
||||
* Return value: (transfer none): For convenience it returns the given CoglHandle
|
||||
*
|
||||
* Deprecated: 1.2: cogl_handle_ref() should be used in new code.
|
||||
*/
|
||||
CoglHandle cogl_offscreen_ref (CoglHandle handle) G_GNUC_DEPRECATED;
|
||||
|
||||
/**
|
||||
* cogl_offscreen_unref:
|
||||
* @handle: A CoglHandle for an offscreen buffer
|
||||
*
|
||||
* Decreases the reference count for the offscreen buffer and frees it when
|
||||
* the count reaches 0.
|
||||
*
|
||||
* Deprecated: 1.2: cogl_handle_unref() should be used in new code.
|
||||
*/
|
||||
void cogl_offscreen_unref (CoglHandle handle) G_GNUC_DEPRECATED;
|
||||
|
||||
#endif /* COGL_DISABLE_DEPRECATED */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_OFFSCREEN_H__ */
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_ONSCREEN_TEMPLATE_PRIVATE_H
|
||||
#define __COGL_ONSCREEN_TEMPLATE_PRIVATE_H
|
||||
|
||||
#include "cogl-object-private.h"
|
||||
#include "cogl-swap-chain.h"
|
||||
|
||||
struct _CoglOnscreenTemplate
|
||||
{
|
||||
CoglObject _parent;
|
||||
|
||||
CoglSwapChain *swap_chain;
|
||||
};
|
||||
|
||||
#endif /* __COGL_ONSCREEN_TEMPLATE_PRIVATE_H */
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-object.h"
|
||||
|
||||
#include "cogl-onscreen-template-private.h"
|
||||
|
||||
static void _cogl_onscreen_template_free (CoglOnscreenTemplate *onscreen_template);
|
||||
|
||||
COGL_OBJECT_DEFINE (OnscreenTemplate, onscreen_template);
|
||||
|
||||
GQuark
|
||||
cogl_onscreen_template_error_quark (void)
|
||||
{
|
||||
return g_quark_from_static_string ("cogl-onscreen-template-error-quark");
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_onscreen_template_free (CoglOnscreenTemplate *onscreen_template)
|
||||
{
|
||||
g_slice_free (CoglOnscreenTemplate, onscreen_template);
|
||||
}
|
||||
|
||||
CoglOnscreenTemplate *
|
||||
cogl_onscreen_template_new (CoglSwapChain *swap_chain)
|
||||
{
|
||||
CoglOnscreenTemplate *onscreen_template = g_slice_new0 (CoglOnscreenTemplate);
|
||||
|
||||
onscreen_template->swap_chain = swap_chain;
|
||||
if (swap_chain)
|
||||
cogl_object_ref (swap_chain);
|
||||
|
||||
return _cogl_onscreen_template_object_new (onscreen_template);
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_ONSCREEN_TEMPLATE_H__
|
||||
#define __COGL_ONSCREEN_TEMPLATE_H__
|
||||
|
||||
#include <cogl/cogl-swap-chain.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _CoglOnscreenTemplate CoglOnscreenTemplate;
|
||||
|
||||
#define COGL_ONSCREEN_TEMPLATE(OBJECT) ((CoglOnscreenTemplate *)OBJECT)
|
||||
|
||||
#define cogl_onscreen_template_new cogl_onscreen_template_new_EXP
|
||||
CoglOnscreenTemplate *
|
||||
cogl_onscreen_template_new (CoglSwapChain *swap_chain);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_ONSCREEN_TEMPLATE_H__ */
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __COGL_PATH_PRIVATE_H
|
||||
#define __COGL_PATH_PRIVATE_H
|
||||
|
||||
#include "cogl-object.h"
|
||||
|
||||
typedef struct _floatVec2
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
} floatVec2;
|
||||
|
||||
typedef struct _CoglPathNode
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
unsigned int path_size;
|
||||
} CoglPathNode;
|
||||
|
||||
typedef struct _CoglBezQuad
|
||||
{
|
||||
floatVec2 p1;
|
||||
floatVec2 p2;
|
||||
floatVec2 p3;
|
||||
} CoglBezQuad;
|
||||
|
||||
typedef struct _CoglBezCubic
|
||||
{
|
||||
floatVec2 p1;
|
||||
floatVec2 p2;
|
||||
floatVec2 p3;
|
||||
floatVec2 p4;
|
||||
} CoglBezCubic;
|
||||
|
||||
typedef struct _CoglPathData CoglPathData;
|
||||
|
||||
struct _CoglPath
|
||||
{
|
||||
CoglObject _parent;
|
||||
|
||||
CoglPathData *data;
|
||||
};
|
||||
|
||||
#define COGL_PATH_N_ATTRIBUTES 2
|
||||
|
||||
struct _CoglPathData
|
||||
{
|
||||
unsigned int ref_count;
|
||||
|
||||
CoglPathFillRule fill_rule;
|
||||
|
||||
GArray *path_nodes;
|
||||
|
||||
floatVec2 path_start;
|
||||
floatVec2 path_pen;
|
||||
unsigned int last_path;
|
||||
floatVec2 path_nodes_min;
|
||||
floatVec2 path_nodes_max;
|
||||
|
||||
CoglVertexArray *fill_vbo;
|
||||
CoglIndices *fill_vbo_indices;
|
||||
unsigned int fill_vbo_n_indices;
|
||||
CoglAttribute *fill_vbo_attributes[COGL_PATH_N_ATTRIBUTES + 1];
|
||||
|
||||
CoglVertexArray *stroke_vbo;
|
||||
CoglAttribute **stroke_vbo_attributes;
|
||||
unsigned int stroke_vbo_n_attributes;
|
||||
|
||||
/* This is used as an optimisation for when the path contains a
|
||||
single contour specified using cogl2_path_rectangle. Cogl is more
|
||||
optimised to handle rectangles than paths so we can detect this
|
||||
case and divert to the journal or a rectangle clip. If it is TRUE
|
||||
then the entire path can be described by calling
|
||||
_cogl_path_get_bounds */
|
||||
gboolean is_rectangle;
|
||||
};
|
||||
|
||||
void
|
||||
_cogl_add_path_to_stencil_buffer (CoglPath *path,
|
||||
gboolean merge,
|
||||
gboolean need_clear);
|
||||
|
||||
void
|
||||
_cogl_path_get_bounds (CoglPath *path,
|
||||
float *min_x,
|
||||
float *min_y,
|
||||
float *max_x,
|
||||
float *max_y);
|
||||
|
||||
gboolean
|
||||
_cogl_path_is_rectangle (CoglPath *path);
|
||||
|
||||
#endif /* __COGL_PATH_PRIVATE_H */
|
@ -1,303 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "cogl2-path.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#undef cogl_path_set_fill_rule
|
||||
void
|
||||
cogl_path_set_fill_rule (CoglPathFillRule fill_rule)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_set_fill_rule (ctx->current_path, fill_rule);
|
||||
}
|
||||
|
||||
#undef cogl_path_get_fill_rule
|
||||
CoglPathFillRule
|
||||
cogl_path_get_fill_rule (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, COGL_PATH_FILL_RULE_EVEN_ODD);
|
||||
|
||||
return cogl2_path_get_fill_rule (ctx->current_path);
|
||||
}
|
||||
|
||||
#undef cogl_path_fill
|
||||
void
|
||||
cogl_path_fill (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_fill (ctx->current_path);
|
||||
|
||||
cogl_object_unref (ctx->current_path);
|
||||
ctx->current_path = cogl2_path_new ();
|
||||
}
|
||||
|
||||
#undef cogl_path_fill_preserve
|
||||
void
|
||||
cogl_path_fill_preserve (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_fill (ctx->current_path);
|
||||
}
|
||||
|
||||
#undef cogl_path_stroke
|
||||
void
|
||||
cogl_path_stroke (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_stroke (ctx->current_path);
|
||||
|
||||
cogl_object_unref (ctx->current_path);
|
||||
ctx->current_path = cogl2_path_new ();
|
||||
}
|
||||
|
||||
#undef cogl_path_stroke_preserve
|
||||
void
|
||||
cogl_path_stroke_preserve (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_stroke (ctx->current_path);
|
||||
}
|
||||
|
||||
#undef cogl_path_move_to
|
||||
void
|
||||
cogl_path_move_to (float x,
|
||||
float y)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_move_to (ctx->current_path, x, y);
|
||||
}
|
||||
|
||||
#undef cogl_path_rel_move_to
|
||||
void
|
||||
cogl_path_rel_move_to (float x,
|
||||
float y)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_rel_move_to (ctx->current_path, x, y);
|
||||
}
|
||||
|
||||
#undef cogl_path_line_to
|
||||
void
|
||||
cogl_path_line_to (float x,
|
||||
float y)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_line_to (ctx->current_path, x, y);
|
||||
}
|
||||
|
||||
#undef cogl_path_rel_line_to
|
||||
void
|
||||
cogl_path_rel_line_to (float x,
|
||||
float y)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_rel_line_to (ctx->current_path, x, y);
|
||||
}
|
||||
|
||||
#undef cogl_path_close
|
||||
void
|
||||
cogl_path_close (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_close (ctx->current_path);
|
||||
}
|
||||
|
||||
#undef cogl_path_new
|
||||
void
|
||||
cogl_path_new (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl_object_unref (ctx->current_path);
|
||||
ctx->current_path = cogl2_path_new ();
|
||||
}
|
||||
|
||||
#undef cogl_path_line
|
||||
void
|
||||
cogl_path_line (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_line (ctx->current_path, x_1, y_1, x_2, y_2);
|
||||
}
|
||||
|
||||
#undef cogl_path_polyline
|
||||
void
|
||||
cogl_path_polyline (const float *coords,
|
||||
int num_points)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_polyline (ctx->current_path, coords, num_points);
|
||||
}
|
||||
|
||||
#undef cogl_path_polygon
|
||||
void
|
||||
cogl_path_polygon (const float *coords,
|
||||
int num_points)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_polygon (ctx->current_path, coords, num_points);
|
||||
}
|
||||
|
||||
#undef cogl_path_rectangle
|
||||
void
|
||||
cogl_path_rectangle (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_rectangle (ctx->current_path, x_1, y_1, x_2, y_2);
|
||||
}
|
||||
|
||||
#undef cogl_path_arc
|
||||
void
|
||||
cogl_path_arc (float center_x,
|
||||
float center_y,
|
||||
float radius_x,
|
||||
float radius_y,
|
||||
float angle_1,
|
||||
float angle_2)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_arc (ctx->current_path,
|
||||
center_x,
|
||||
center_y,
|
||||
radius_x,
|
||||
radius_y,
|
||||
angle_1,
|
||||
angle_2);
|
||||
}
|
||||
|
||||
#undef cogl_path_ellipse
|
||||
void
|
||||
cogl_path_ellipse (float center_x,
|
||||
float center_y,
|
||||
float radius_x,
|
||||
float radius_y)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_ellipse (ctx->current_path,
|
||||
center_x,
|
||||
center_y,
|
||||
radius_x,
|
||||
radius_y);
|
||||
}
|
||||
|
||||
#undef cogl_path_round_rectangle
|
||||
void
|
||||
cogl_path_round_rectangle (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2,
|
||||
float radius,
|
||||
float arc_step)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_round_rectangle (ctx->current_path,
|
||||
x_1, y_1, x_2, y_2, radius, arc_step);
|
||||
}
|
||||
|
||||
#undef cogl_path_curve_to
|
||||
void
|
||||
cogl_path_curve_to (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2,
|
||||
float x_3,
|
||||
float y_3)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_curve_to (ctx->current_path,
|
||||
x_1, y_2, x_2, y_2, x_3, y_3);
|
||||
}
|
||||
|
||||
#undef cogl_path_rel_curve_to
|
||||
void
|
||||
cogl_path_rel_curve_to (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2,
|
||||
float x_3,
|
||||
float y_3)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
cogl2_path_rel_curve_to (ctx->current_path,
|
||||
x_1, y_1, x_2, y_2, x_3, y_3);
|
||||
}
|
||||
|
||||
CoglPath *
|
||||
cogl_get_path (void)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
|
||||
return ctx->current_path;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_set_path (CoglPath *path)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
g_return_if_fail (cogl_is_path (path));
|
||||
|
||||
/* Reference the new object first in case it is the same as the old
|
||||
object */
|
||||
cogl_object_ref (path);
|
||||
cogl_object_unref (ctx->current_path);
|
||||
ctx->current_path = path;
|
||||
}
|
||||
|
@ -1,491 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_PATH_H__
|
||||
#define __COGL_PATH_H__
|
||||
|
||||
#include <cogl/cogl-types.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-paths
|
||||
* @short_description: Functions for constructing and drawing 2D paths.
|
||||
*
|
||||
* There are two levels on which drawing with cogl-paths can be used.
|
||||
* The highest level functions construct various simple primitive
|
||||
* shapes to be either filled or stroked. Using a lower-level set of
|
||||
* functions more complex and arbitrary paths can be constructed by
|
||||
* concatenating straight line, bezier curve and arc segments.
|
||||
*
|
||||
* When constructing arbitrary paths, the current pen location is
|
||||
* initialized using the move_to command. The subsequent path segments
|
||||
* implicitly use the last pen location as their first vertex and move
|
||||
* the pen location to the last vertex they produce at the end. Also
|
||||
* there are special versions of functions that allow specifying the
|
||||
* vertices of the path segments relative to the last pen location
|
||||
* rather then in the absolute coordinates.
|
||||
*/
|
||||
|
||||
typedef struct _CoglPath CoglPath;
|
||||
|
||||
#define COGL_PATH(obj) ((CoglPath *)(obj))
|
||||
|
||||
/**
|
||||
* CoglPathFillRule:
|
||||
* @COGL_PATH_FILL_RULE_NON_ZERO: Each time the line crosses an edge of
|
||||
* the path from left to right one is added to a counter and each time
|
||||
* it crosses from right to left the counter is decremented. If the
|
||||
* counter is non-zero then the point will be filled. See <xref
|
||||
* linkend="fill-rule-non-zero"/>.
|
||||
* @COGL_PATH_FILL_RULE_EVEN_ODD: If the line crosses an edge of the
|
||||
* path an odd number of times then the point will filled, otherwise
|
||||
* it won't. See <xref linkend="fill-rule-even-odd"/>.
|
||||
*
|
||||
* #CoglPathFillRule is used to determine how a path is filled. There
|
||||
* are two options - 'non-zero' and 'even-odd'. To work out whether any
|
||||
* point will be filled imagine drawing an infinetely long line in any
|
||||
* direction from that point. The number of times and the direction
|
||||
* that the edges of the path crosses this line determines whether the
|
||||
* line is filled as described below. Any open sub paths are treated
|
||||
* as if there was an extra line joining the first point and the last
|
||||
* point.
|
||||
*
|
||||
* The default fill rule is %COGL_PATH_FILL_RULE_EVEN_ODD. The fill
|
||||
* rule is attached to the current path so preserving a path with
|
||||
* cogl_get_path() also preserves the fill rule. Calling
|
||||
* cogl_path_new() resets the current fill rule to the default.
|
||||
*
|
||||
* <figure id="fill-rule-non-zero">
|
||||
* <title>Example of filling various paths using the non-zero rule</title>
|
||||
* <graphic fileref="fill-rule-non-zero.png" format="PNG"/>
|
||||
* </figure>
|
||||
*
|
||||
* <figure id="fill-rule-even-odd">
|
||||
* <title>Example of filling various paths using the even-odd rule</title>
|
||||
* <graphic fileref="fill-rule-even-odd.png" format="PNG"/>
|
||||
* </figure>
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
typedef enum {
|
||||
COGL_PATH_FILL_RULE_NON_ZERO,
|
||||
COGL_PATH_FILL_RULE_EVEN_ODD
|
||||
} CoglPathFillRule;
|
||||
|
||||
/**
|
||||
* cogl_is_path:
|
||||
* @handle: A CoglHandle
|
||||
*
|
||||
* Gets whether the given handle references an existing path object.
|
||||
*
|
||||
* Return value: %TRUE if the handle references a #CoglPath,
|
||||
* %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
cogl_is_path (CoglHandle handle);
|
||||
|
||||
/**
|
||||
* cogl_path_set_fill_rule:
|
||||
* @fill_rule: The new fill rule.
|
||||
*
|
||||
* Sets the fill rule of the current path to @fill_rule. This will
|
||||
* affect how the path is filled when cogl_path_fill() is later
|
||||
* called. Note that the fill rule state is attached to the path so
|
||||
* calling cogl_get_path() will preserve the fill rule and calling
|
||||
* cogl_path_new() will reset the fill rule back to the default.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_path_set_fill_rule (CoglPathFillRule fill_rule);
|
||||
|
||||
/**
|
||||
* cogl_path_get_fill_rule:
|
||||
*
|
||||
* Retrieves the fill rule set using cogl_path_set_fill_rule().
|
||||
*
|
||||
* Return value: the fill rule that is used for the current path.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
CoglPathFillRule
|
||||
cogl_path_get_fill_rule (void);
|
||||
|
||||
/**
|
||||
* cogl_path_fill:
|
||||
*
|
||||
* Fills the interior of the constructed shape using the current
|
||||
* drawing color. The current path is then cleared. To use the path
|
||||
* again, call cogl_path_fill_preserve() instead.
|
||||
*
|
||||
* The interior of the shape is determined using the fill rule of the
|
||||
* path. See %CoglPathFillRule for details.
|
||||
**/
|
||||
void
|
||||
cogl_path_fill (void);
|
||||
|
||||
/**
|
||||
* cogl_path_fill_preserve:
|
||||
*
|
||||
* Fills the interior of the constructed shape using the current
|
||||
* drawing color and preserves the path to be used again. See
|
||||
* cogl_path_fill() for a description what is considered the interior
|
||||
* of the shape.
|
||||
*
|
||||
* Since: 1.0
|
||||
**/
|
||||
void
|
||||
cogl_path_fill_preserve (void);
|
||||
|
||||
/**
|
||||
* cogl_path_stroke:
|
||||
*
|
||||
* Strokes the constructed shape using the current drawing color and a
|
||||
* width of 1 pixel (regardless of the current transformation
|
||||
* matrix). To current path is then cleared. To use the path again,
|
||||
* call cogl_path_stroke_preserve() instead.
|
||||
**/
|
||||
void
|
||||
cogl_path_stroke (void);
|
||||
|
||||
/**
|
||||
* cogl_path_stroke_preserve:
|
||||
*
|
||||
* Strokes the constructed shape using the current drawing color and
|
||||
* preserves the path to be used again.
|
||||
*
|
||||
* Since: 1.0
|
||||
**/
|
||||
void
|
||||
cogl_path_stroke_preserve (void);
|
||||
|
||||
/**
|
||||
* cogl_path_new:
|
||||
*
|
||||
* Clears the current path and starts a new one. Creating a new path
|
||||
* also resets the fill rule to the default which is
|
||||
* %COGL_PATH_FILL_RULE_EVEN_ODD.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
void
|
||||
cogl_path_new (void);
|
||||
|
||||
/**
|
||||
* cogl_path_move_to:
|
||||
* @x: X coordinate of the pen location to move to.
|
||||
* @y: Y coordinate of the pen location to move to.
|
||||
*
|
||||
* Moves the pen to the given location. If there is an existing path
|
||||
* this will start a new disjoint subpath.
|
||||
**/
|
||||
void
|
||||
cogl_path_move_to (float x,
|
||||
float y);
|
||||
|
||||
|
||||
/**
|
||||
* cogl_path_rel_move_to:
|
||||
* @x: X offset from the current pen location to move the pen to.
|
||||
* @y: Y offset from the current pen location to move the pen to.
|
||||
*
|
||||
* Moves the pen to the given offset relative to the current pen
|
||||
* location. If there is an existing path this will start a new
|
||||
* disjoint subpath.
|
||||
**/
|
||||
void
|
||||
cogl_path_rel_move_to (float x,
|
||||
float y);
|
||||
|
||||
/**
|
||||
* cogl_path_line_to:
|
||||
* @x: X coordinate of the end line vertex
|
||||
* @y: Y coordinate of the end line vertex
|
||||
*
|
||||
* Adds a straight line segment to the current path that ends at the
|
||||
* given coordinates.
|
||||
**/
|
||||
void
|
||||
cogl_path_line_to (float x,
|
||||
float y);
|
||||
|
||||
/**
|
||||
* cogl_path_rel_line_to:
|
||||
* @x: X offset from the current pen location of the end line vertex
|
||||
* @y: Y offset from the current pen location of the end line vertex
|
||||
*
|
||||
* Adds a straight line segment to the current path that ends at the
|
||||
* given coordinates relative to the current pen location.
|
||||
**/
|
||||
void
|
||||
cogl_path_rel_line_to (float x,
|
||||
float y);
|
||||
|
||||
|
||||
/**
|
||||
* cogl_path_arc:
|
||||
* @center_x: X coordinate of the elliptical arc center
|
||||
* @center_y: Y coordinate of the elliptical arc center
|
||||
* @radius_x: X radius of the elliptical arc
|
||||
* @radius_y: Y radius of the elliptical arc
|
||||
* @angle_1: Angle in degrees at which the arc begin
|
||||
* @angle_2: Angle in degrees at which the arc ends
|
||||
*
|
||||
* Adds an elliptical arc segment to the current path. A straight line
|
||||
* segment will link the current pen location with the first vertex
|
||||
* of the arc. If you perform a move_to to the arcs start just before
|
||||
* drawing it you create a free standing arc.
|
||||
*
|
||||
* The angles are measured in degrees where 0° is in the direction of
|
||||
* the positive X axis and 90° is in the direction of the positive Y
|
||||
* axis. The angle of the arc begins at @angle_1 and heads towards
|
||||
* @angle_2 (so if @angle_2 is less than @angle_1 it will decrease,
|
||||
* otherwise it will increase).
|
||||
**/
|
||||
void
|
||||
cogl_path_arc (float center_x,
|
||||
float center_y,
|
||||
float radius_x,
|
||||
float radius_y,
|
||||
float angle_1,
|
||||
float angle_2);
|
||||
|
||||
/**
|
||||
* cogl_path_curve_to:
|
||||
* @x_1: X coordinate of the second bezier control point
|
||||
* @y_1: Y coordinate of the second bezier control point
|
||||
* @x_2: X coordinate of the third bezier control point
|
||||
* @y_2: Y coordinate of the third bezier control point
|
||||
* @x_3: X coordinate of the fourth bezier control point
|
||||
* @y_3: Y coordinate of the fourth bezier control point
|
||||
*
|
||||
* Adds a cubic bezier curve segment to the current path with the given
|
||||
* second, third and fourth control points and using current pen location
|
||||
* as the first control point.
|
||||
**/
|
||||
void
|
||||
cogl_path_curve_to (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2,
|
||||
float x_3,
|
||||
float y_3);
|
||||
|
||||
/**
|
||||
* cogl_path_rel_curve_to:
|
||||
* @x_1: X coordinate of the second bezier control point
|
||||
* @y_1: Y coordinate of the second bezier control point
|
||||
* @x_2: X coordinate of the third bezier control point
|
||||
* @y_2: Y coordinate of the third bezier control point
|
||||
* @x_3: X coordinate of the fourth bezier control point
|
||||
* @y_3: Y coordinate of the fourth bezier control point
|
||||
*
|
||||
* Adds a cubic bezier curve segment to the current path with the given
|
||||
* second, third and fourth control points and using current pen location
|
||||
* as the first control point. The given coordinates are relative to the
|
||||
* current pen location.
|
||||
*/
|
||||
void
|
||||
cogl_path_rel_curve_to (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2,
|
||||
float x_3,
|
||||
float y_3);
|
||||
|
||||
/**
|
||||
* cogl_path_close:
|
||||
*
|
||||
* Closes the path being constructed by adding a straight line segment
|
||||
* to it that ends at the first vertex of the path.
|
||||
**/
|
||||
void
|
||||
cogl_path_close (void);
|
||||
|
||||
/**
|
||||
* cogl_path_line:
|
||||
* @x_1: X coordinate of the start line vertex
|
||||
* @y_1: Y coordinate of the start line vertex
|
||||
* @x_2: X coordinate of the end line vertex
|
||||
* @y_2: Y coordinate of the end line vertex
|
||||
*
|
||||
* Constructs a straight line shape starting and ending at the given
|
||||
* coordinates. If there is an existing path this will start a new
|
||||
* disjoint sub-path.
|
||||
**/
|
||||
void
|
||||
cogl_path_line (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2);
|
||||
|
||||
/**
|
||||
* cogl_path_polyline:
|
||||
* @coords: (in) (array) (transfer none): A pointer to the first element of an
|
||||
* array of fixed-point values that specify the vertex coordinates.
|
||||
* @num_points: The total number of vertices.
|
||||
*
|
||||
* Constructs a series of straight line segments, starting from the
|
||||
* first given vertex coordinate. If there is an existing path this
|
||||
* will start a new disjoint sub-path. Each subsequent segment starts
|
||||
* where the previous one ended and ends at the next given vertex
|
||||
* coordinate.
|
||||
*
|
||||
* The coords array must contain 2 * num_points values. The first value
|
||||
* represents the X coordinate of the first vertex, the second value
|
||||
* represents the Y coordinate of the first vertex, continuing in the same
|
||||
* fashion for the rest of the vertices. (num_points - 1) segments will
|
||||
* be constructed.
|
||||
**/
|
||||
void
|
||||
cogl_path_polyline (const float *coords,
|
||||
int num_points);
|
||||
|
||||
|
||||
/**
|
||||
* cogl_path_polygon:
|
||||
* @coords: (in) (array) (transfer none): A pointer to the first element of
|
||||
* an array of fixed-point values that specify the vertex coordinates.
|
||||
* @num_points: The total number of vertices.
|
||||
*
|
||||
* Constructs a polygonal shape of the given number of vertices. If
|
||||
* there is an existing path this will start a new disjoint sub-path.
|
||||
*
|
||||
* The coords array must contain 2 * num_points values. The first value
|
||||
* represents the X coordinate of the first vertex, the second value
|
||||
* represents the Y coordinate of the first vertex, continuing in the same
|
||||
* fashion for the rest of the vertices.
|
||||
**/
|
||||
void
|
||||
cogl_path_polygon (const float *coords,
|
||||
int num_points);
|
||||
|
||||
|
||||
/**
|
||||
* cogl_path_rectangle:
|
||||
* @x_1: X coordinate of the top-left corner.
|
||||
* @y_1: Y coordinate of the top-left corner.
|
||||
* @x_2: X coordinate of the bottom-right corner.
|
||||
* @y_2: Y coordinate of the bottom-right corner.
|
||||
*
|
||||
* Constructs a rectangular shape at the given coordinates. If there
|
||||
* is an existing path this will start a new disjoint sub-path.
|
||||
**/
|
||||
void
|
||||
cogl_path_rectangle (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2);
|
||||
|
||||
/**
|
||||
* cogl_path_ellipse:
|
||||
* @center_x: X coordinate of the ellipse center
|
||||
* @center_y: Y coordinate of the ellipse center
|
||||
* @radius_x: X radius of the ellipse
|
||||
* @radius_y: Y radius of the ellipse
|
||||
*
|
||||
* Constructs an ellipse shape. If there is an existing path this will
|
||||
* start a new disjoint sub-path.
|
||||
**/
|
||||
void
|
||||
cogl_path_ellipse (float center_x,
|
||||
float center_y,
|
||||
float radius_x,
|
||||
float radius_y);
|
||||
|
||||
/**
|
||||
* cogl_path_round_rectangle:
|
||||
* @x_1: X coordinate of the top-left corner.
|
||||
* @y_1: Y coordinate of the top-left corner.
|
||||
* @x_2: X coordinate of the bottom-right corner.
|
||||
* @y_2: Y coordinate of the bottom-right corner.
|
||||
* @radius: Radius of the corner arcs.
|
||||
* @arc_step: Angle increment resolution for subdivision of
|
||||
* the corner arcs.
|
||||
*
|
||||
* Constructs a rectangular shape with rounded corners. If there is an
|
||||
* existing path this will start a new disjoint sub-path.
|
||||
**/
|
||||
void
|
||||
cogl_path_round_rectangle (float x_1,
|
||||
float y_1,
|
||||
float x_2,
|
||||
float y_2,
|
||||
float radius,
|
||||
float arc_step);
|
||||
|
||||
/**
|
||||
* cogl_get_path: (skip)
|
||||
*
|
||||
* Gets a pointer to the current path. The path can later be used
|
||||
* again by calling cogl_path_set(). Note that the path isn't copied
|
||||
* so if you later call any functions to add to the path it will
|
||||
* affect the returned object too. No reference is taken on the path
|
||||
* so if you want to retain it you should take your own reference with
|
||||
* cogl_object_ref().
|
||||
*
|
||||
* Return value: a pointer to the current path.
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
CoglPath *
|
||||
cogl_get_path (void);
|
||||
|
||||
/**
|
||||
* cogl_set_path: (skip)
|
||||
* @path: A #CoglPath object
|
||||
*
|
||||
* Replaces the current path with @path. A reference is taken on the
|
||||
* object so if you no longer need the path you should unref with
|
||||
* cogl_object_unref().
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
void
|
||||
cogl_set_path (CoglPath *path);
|
||||
|
||||
/**
|
||||
* cogl_path_copy: (skip)
|
||||
* @path: A #CoglPath object
|
||||
*
|
||||
* Returns a new copy of the path in @path. The new path has a
|
||||
* reference count of 1 so you should unref it with
|
||||
* cogl_object_unref() if you no longer need it.
|
||||
*
|
||||
* Internally the path will share the data until one of the paths is
|
||||
* modified so copying paths should be relatively cheap.
|
||||
*
|
||||
* Return value: (transfer full): a copy of the path in @path.
|
||||
*/
|
||||
CoglPath *
|
||||
cogl_path_copy (CoglPath *path);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_PATH_H__ */
|
||||
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors:
|
||||
* Robert Bragg <robert@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_PIPELINE_FRAGEND_ARBFP_PRIVATE_H
|
||||
#define __COGL_PIPELINE_FRAGEND_ARBFP_PRIVATE_H
|
||||
|
||||
#include "cogl-pipeline-private.h"
|
||||
|
||||
extern const CoglPipelineFragend _cogl_pipeline_arbfp_fragend;
|
||||
|
||||
unsigned int
|
||||
_cogl_pipeline_fragend_arbfp_hash (const void *pipeline);
|
||||
|
||||
gboolean
|
||||
_cogl_pipeline_fragend_arbfp_equal (const void *pipeline0,
|
||||
const void *pipeline1);
|
||||
|
||||
#endif /* __COGL_PIPELINE_ARBFP_PRIVATE_H */
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user