Commit Graph

33 Commits

Author SHA1 Message Date
Damien Lespiau
81bb87e037 Use the internal format to check if the texture size is supported
Until now, we hardcoded the internal format to GL_RGBA and used the
internal format returned by pixel_format_to_gl() as the format for
checking the texture size and format we're asked to create.

Let's use the proper internal format/format from now on.

This is needed as a later patch introduces DEPTH and DEPTH_STENCIL
textures.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit ec45f60ee2545f88302da314bcdbe1439c4ba9c9)
2012-08-06 14:27:44 +01:00
Robert Bragg
54735dec84 Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.

Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.

Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.

So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.

Instead of gsize we now use size_t

For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-08-06 14:27:39 +01:00
Robert Bragg
09642a83b5 Removes all remaining use of CoglHandle
Removing CoglHandle has been an on going goal for quite a long time now
and finally this patch removes the last remaining uses of the CoglHandle
type and the cogl_handle_ apis.

Since the big remaining users of CoglHandle were the cogl_program_ and
cogl_shader_ apis which have replaced with the CoglSnippets api this
patch removes both of these apis.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6ed3aaf4be21d605a1ed3176b3ea825933f85cf0)

  Since the original patch was done after removing deprecated API
  this back ported patch doesn't affect deprecated API and so
  actually this cherry-pick doesn't remove all remaining use of
  CoglHandle as it did for the master branch of Cogl.
2012-08-06 14:27:39 +01:00
Neil Roberts
ec5009fa23 Use GL_PACK_ALIGNMENT of 1 whenever possible
The Intel driver currently has an optimisation when calling
glReadPixels into a PBO so that it will use a blit instead of the Mesa
fallback path. However this only works if the GL_PACK_ALIGNMENT is
exactly 1, even if this would be equivalent to a higher alignment
value because the bpp*width is already aligned. To make it more likely
to hit this fast path, we now detect this situation and explicitly use
an alignment of 1. To make this work the texture driver needs to be
passed down the bpp*width as well as the rowstride when configuring
the alignment.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:51:56 +01:00
Neil Roberts
6197e3abf3 Add constructors which take a CoglBitmap to all primitive textures
This adds public constructors which take a CoglBitmap to all primitive
texture types. This constructor should be considered the canonical
constructor for initializing the texture with data because it should
be possible to wrap any type of data in a CoglBitmap. Having at least
this single constructor avoids the need to have an explosion of
constructors such as new_from_data, new_from_pixel_buffer and
new_from_file etc.

The already available internal bitmap constructor for CoglTexture2D
has had its flags parameter removed under the assumption that flags do
not make sense for primitive textures. The meta constructor
cogl_texture_new_from_bitmap now just explicitly calls set_auto_mipmap
after constructing the texture depending on the value of the
COGL_TEXTURE_NO_AUTO_MIPMAP flag.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:47:32 +01:00
Neil Roberts
e7f1582630 Add a CoglPrimitiveTexture interface
This interface represents any textures that are backed by a single
texture in GL and that can be used directly with the
cogl_framebuffer_draw_attributes family of functions. This currently
equates to CoglTexture2D, CoglTexture3D and CoglTextureRectangle.

The interface currently has only one method called
cogl_primitive_set_auto_mipmap. This replaces the
COGL_TEXTURE_NO_AUTO_MIPMAP flag from the CoglTextureFlags parameter
in the constructors. None of the other flags in CoglTextureFlags make
sense for primitive textures so it doesn't seem like a good idea to
need them for primitive constructors.

There is a boolean in the vtable to mark whether a texture type is
primitive which the new cogl_is_primitive function uses. There is also
a new texture virtual called set_auto_mipmap which is only required to
be implemented for primitive textures.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-04 17:02:23 +01:00
Neil Roberts
e7df2dbf79 bitmap: Store a pointer to the context
This adds a context member to CoglBitmap which stores the context it
was created with. That way it can be used in texture constructors
which use a bitmap. There is also an internal private function to get
the context out of the bitmap which all of the texture constructors
now use. _cogl_texture_3d_new_from_bitmap has had its context
parameter removed so that it more closely matches the other bitmap
constructors.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-04 14:24:01 +01:00
Neil Roberts
d6ca75fbec Add a context parameter to all of the texture driver virtuals
All of the texture driver virtual functions now take an explicit
CoglContext parameter as a step towards removing the global context.
2012-03-23 13:51:08 +00:00
Neil Roberts
60812e6a0e Add a vtable for the driver
Cogl already had a vtable for the texture driver. This ended up being
used for some things that are not strictly related to texturing such
as converting between pixel formats and GL enums. Some other functions
that are driver dependent such as updating the features were not
indirected through a vtable but instead switched directly by looking
at the ctx->driver enum value. This patch normalises to the two uses
by adding a separate vtable for driver functions not related to
texturing and moves the pixel format conversion functions to it from
the texture driver vtable. It also adds a context parameter to all of
the functions in the new driver vtable so that they won't have to rely
on the global context.
2012-03-23 13:51:08 +00:00
Neil Roberts
1397a2da19 Make _cogl_bitmap_get_{width,height,format,rowstride} public
This are now marked as public experimental

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-03-05 18:47:52 +00:00
Robert Bragg
680f63a48c Remove all internal includes of cogl.h
The cogl.h header is meant to be the public header for including the 1.x
api used by Clutter so we should stop using that as a convenient way to
include all likely prototypes and typedefs. Actually we already do a
good job of listing the specific headers we depend on in each of the .c
files we have so mostly this patch just strip out the redundant
includes for cogl.h with a few fixups where that broke the build.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-20 23:12:45 +00:00
Robert Bragg
fbec2a5ad7 moves and renames _cogl_get_format_bpp
This moves _cogl_get_format_bpp from cogl-bitmap.c to cogl.c and renames
it to _cogl_pixel_format_get_bytes_per_pixel. This makes it clearer that
it doesn't return bits per pixel and makes the naming consistent with
other cogl api. The prototype has been moved to cogl-private.h since it
seems we should be aiming to get rid of cogl-internal.h at some point.

The patch also adds a simple gtk-doc comment since we might want to make
this api public.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-20 23:12:44 +00:00
Neil Roberts
8012eee31f Add _cogl_texture_get_type()
This adds an internal function to get the type of the underlying
hardware texture for any CoglTexture. It can return one of three
values to represent 2D textures, 3D textures or rectangle textures.
The idea is that this can be used as a replacement for
cogl_texture_get_gl_texture when only the target is required to make
it a bit less GL-centric. The implementation adds a new virtual
function which all of the texture backends now implement.

The enum is in a public header because a later patch will want to use
it from the CoglPipeline API. We may want to consider making the
function public too later.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-02-13 17:02:46 +00:00
Robert Bragg
90f106117f texture: Make CoglTextureRectangle experimentally public
This exposes CoglTextureRectangle in the experimental cogl 2.0 api. For
now we just expose a single constructor;
cogl_texture_rectangle_new_with_size() but we can add more later.

This is part of going work to improve our texture apis with more
emphasis on providing low-level access to the varying semantics of
different texture types understood by the gpu instead of only trying to
present a lowest common denominator api.

CoglTextureRectangle is notably useful for never being restricted to
power of two sizes and for being sampled with non-normalized texture
coordinates which can be convenient for use a lookup tables in glsl due
to not needing separate uniforms for mapping normalized coordinates to
texels. Unlike CoglTexture2D though rectangle textures can't have a
mipmap and they only support the _CLAMP_TO_EDGE wrap mode.

Applications wanting to use CoglTextureRectangle should first check
cogl_has_feature (COGL_FEATURE_ID_TEXTURE_RECTANGLE).

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:02 +00:00
Robert Bragg
b72f255c0a Start to reduce dependence on glib
Since we've had several developers from admirable projects say they
would like to use Cogl but would really prefer not to pull in
gobject,gmodule and glib as extra dependencies we are investigating if
we can get to the point where glib is only an optional dependency.
Actually we feel like we only make minimal use of glib anyway, so it may
well be quite straightforward to achieve this.

This adds a --disable-glib configure option that can be used to disable
features that depend on glib.

Actually --disable-glib doesn't strictly disable glib at this point
because it's more helpful if cogl continues to build as we make
incremental progress towards this.

The first use of glib that this patch tackles is the use of
g_return_val_if_fail and g_return_if_fail which have been replaced with
equivalent _COGL_RETURN_VAL_IF_FAIL and _COGL_RETURN_IF_FAIL macros.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:02 +00:00
Robert Bragg
1d8fd64e1c meta-texture: This publicly exposes CoglMetaTexture
CoglMetaTexture is an interface for dealing with high level textures
that may be comprised of one or more low-level textures internally. The
interface allows the development of primitive drawing APIs that can draw
with high-level textures (such as atlas textures) even though the
GPU doesn't natively understand these texture types.

There is currently just one function that's part of this interface:
cogl_meta_texture_foreach_in_region() which allows an application to
resolve the internal, low-level textures of a high-level texture.
cogl_rectangle() uses this API for example so that it can easily emulate
the _REPEAT wrap mode for textures that the hardware can't natively
handle repeating of.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:01 +00:00
Robert Bragg
426c8b8f41 features: Support more than 32 features!
Currently features are represented as bits in a 32bit mask so we
obviously can't have more than 32 features with that approach. The new
approach is to use the COGL_FLAGS_ macros which lets us handle bitmasks
without a size limit and we change the public api to accept individual
feature enums instead of a mask. This way there is no limit on the
number of features we can add to Cogl.

Instead of using cogl_features_available() there is a new
cogl_has_feature() function and for checking multiple features there is
cogl_has_features() which takes a zero terminated vararg list of
features.

In addition to being able to check for individual features this also
adds a way to query all the features currently available via
cogl_foreach_feature() which will call a callback for each feature.

Since the new functions take an explicit context pointer there is also
no longer any ambiguity over when users can first start to query
features.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:01 +00:00
Neil Roberts
503f138fb6 texture: Call _cogl_texture_prepare_for_upload in set_region impl
Instead of calling _cogl_texutre_prepare_for_upload in
cogl_texture_set_region_from_bitmap the call is now deferred to the
implementation of the virtual for set_region. This is needed if the
texture backend is using a different format for the actual GL texture
than what is reported by cogl_texture_get_format. This happens for
example with atlas textures which report the original internal format
specified when the texture was created but actually always store the
data in an RGBA texture.

Also when creating an atlas texture from a bitmap it was preparing the
bitmap to be uploaded to the original format instead of the format of
the actual texture used for the atlas. Then it was using
cogl_texture_set_region_from_bitmap to upload the 5 pieces to make the
copies of the edge pixels. This would end up converting the image to
the actual format 5 times. The atlas textures have now been changed to
prepare the bitmap for the right format.

https://bugzilla.gnome.org/show_bug.cgi?id=657840

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-05 19:02:04 +01:00
Neil Roberts
b2e735ff7f Dynamically load the GL or GLES library
The GL or GLES library is now dynamically loaded by the CoglRenderer
so that it can choose between GL, GLES1 and GLES2 at runtime. The
library is loaded by the renderer because it needs to be done before
calling eglInitialize. There is a new environment variable called
COGL_DRIVER to choose between gl, gles1 or gles2.

The #ifdefs for HAVE_COGL_GL, HAVE_COGL_GLES and HAVE_COGL_GLES2 have
been changed so that they don't assume the ifdefs are mutually
exclusive. They haven't been removed entirely so that it's possible to
compile the GLES backends without the the enums from the GL headers.

When using GLX the winsys additionally dynamically loads libGL because
that also contains the GLX API. It can't be linked in directly because
that would probably conflict with the GLES API if the EGL is
selected. When compiling with EGL support the library links directly
to libEGL because it doesn't contain any GL API so it shouldn't have
any conflicts.

When building for WGL or OSX Cogl still directly links against the GL
API so there is a #define in config.h so that Cogl won't try to dlopen
the library.

Cogl-pango previously had a #ifdef to detect when the GL backend is
used so that it can sneakily pass GL_QUADS to
cogl_vertex_buffer_draw. This is now changed so that it queries the
CoglContext for the backend. However to get this to work Cogl now
needs to export the _cogl_context_get_default symbol and cogl-pango
needs some extra -I flags to so that it can include
cogl-context-private.h
2011-07-11 12:57:38 +01:00
Neil Roberts
5f181973a6 Move the cogl texture driver functions to a vtable
The texture driver functions are now accessed through a vtable pointed
to by a struct in the CoglContext so that eventually it will be
possible to compile both the GL and GLES texture drivers into a single
binary and then select between them at runtime.
2011-07-08 15:35:51 +01:00
Neil Roberts
2b119b07da Use all core GL functions through indirect pointers
cogl-ext-functions.h now contains definitions for all of the core GL
and GLES functions that we would normally link to directly. All of the
code has changed to access them through the cogl context pointer. The
GE macro now takes an extra parameter to specify the context because
the macro itself needs to make GL calls but various points in the Cogl
source use different names for the context variable.
2011-07-08 15:35:46 +01:00
Robert Bragg
fdbc741770 cogl: rename cogl-context.h cogl-context-private.h
Since we plan to add public cogl_context_* API we need to rename the
current cogl-context.h which contains private member details.
2011-04-11 15:18:12 +01:00
Robert Bragg
1a5a4df326 journal: Support per-framebuffer journals
Instead of having a single journal per context, we now have a
CoglJournal object for each CoglFramebuffer. This means we now don't
have to flush the journal when switching/pushing/popping between
different framebuffers so for example a Clutter scene that involves some
ClutterEffect actors that transiently redirect to an FBO can still be
batched.

This also allows us to track state in the journal that relates to the
current frame of its associated framebuffer which we'll need for our
optimization for using the CPU to handle reading a single pixel back
from a framebuffer when we know the whole scene is currently comprised
of simple rectangles in a journal.
2011-01-21 16:18:10 +00:00
Neil Roberts
081eb2d75d cogl-texture: Remove the gl_handle from CoglTextureSliceCallback
There's no longer any need to use the GL handle in the callback for
_cogl_texture_foreach_sub_texture_in_region because it can now work in
terms of primitive cogl textures so it has now been removed. This
would be helpful if we ever want to make the foreach function public
so that apps could implement their own primitives using sliced
textures.
2010-11-11 16:25:13 +00:00
Robert Bragg
f80cb197a9 cogl: rename CoglMaterial -> CoglPipeline
This applies an API naming change that's been deliberated over for a
while now which is to rename CoglMaterial to CoglPipeline.

For now the new pipeline API is marked as experimental and public
headers continue to talk about materials not pipelines. The CoglMaterial
API is now maintained in terms of the cogl_pipeline API internally.
Currently this API is targeting Cogl 2.0 so we will have time to
integrate it properly with other upcoming Cogl 2.0 work.

The basic reasons for the rename are:
- That the term "material" implies to many people that they are
  constrained to fragment processing; perhaps as some kind of high-level
  texture abstraction.
    - In Clutter they get exposed by ClutterTexture actors which may be
      re-inforcing this misconception.
- When comparing how other frameworks use the term material, a material
  sometimes describes a multi-pass fragment processing technique which
  isn't the case in Cogl.
- In code, "CoglPipeline" will hopefully be a much more self documenting
  summary of what these objects represent; a full GPU pipeline
  configuration including, for example, vertex processing, fragment
  processing and blending.
- When considering the API documentation story, at some point we need a
  document introducing developers to how the "GPU pipeline" works so it
  should become intuitive that CoglPipeline maps back to that
  description of the GPU pipeline.
- This is consistent in terminology and concept to OpenGL 4's new
  pipeline object which is a container for program objects.

Note: The cogl-material.[ch] files have been renamed to
cogl-material-compat.[ch] because otherwise git doesn't seem to treat
the change as a moving the old cogl-material.c->cogl-pipeline.c and so
we loose all our git-blame history.
2010-11-03 18:09:23 +00:00
Neil Roberts
b540dcb75a Support foreign textures in the texture-2d and rectangle backends
This adds two new internal functions to create a foreign texture for
the texture 2d and rectangle backends. cogl_texture_new_from_foreign
will now use one of these backends directly if there is no waste
instead of always using the sliced texture backend.
2010-10-22 12:19:02 +01:00
Neil Roberts
ccc3068ffd cogl-bitmap: Encapsulate the CoglBitmap even internally
The CoglBitmap struct is now only defined within cogl-bitmap.c so that
all of its members can now only be accessed with accessor
functions. To get to the data pointer for the bitmap image you must
first call _cogl_bitmap_map and later call _cogl_bitmap_unmap. The map
function takes the same arguments as cogl_pixel_array_map so that
eventually we can make a bitmap optionally internally divert to a
pixel array.

There is a _cogl_bitmap_new_from_data function which constructs a new
bitmap object and takes ownership of the data pointer. The function
gets passed a destroy callback which gets called when the bitmap is
freed. This is similar to how gdk_pixbuf_new_from_data
works. Alternatively NULL can be passed for the destroy function which
means that the caller will manage the life of the pointer (but must
guarantee that it stays alive at least until the bitmap is
freed). This mechanism is used instead of the old approach of creating
a CoglBitmap struct on the stack and manually filling in the
members. It could also later be used to create a CoglBitmap that owns
a GdkPixbuf ref so that we don't necessarily have to copy the
GdkPixbuf data when converting to a bitmap.

There is also _cogl_bitmap_new_shared. This creates a bitmap using a
reference to another CoglBitmap for the data. This is a bit of a hack
but it is needed by the atlas texture backend which wants to divert
the set_region virtual to another texture but it needs to override the
format of the bitmap to ignore the premult flag.
2010-07-15 17:24:01 +01:00
Robert Bragg
5442e429ba material: split the texture unit management out
In general cogl-material.c has become far to large to manage in one
source file. As one of the ways to try and break it down this patch
starts to move some of lower level texture unit state management out
into cogl-material-opengl.c. The naming is such because the plan is to
follow up and migrate the very GL specific state flushing code into the
same file.
2010-07-13 19:26:58 +01:00
Neil Roberts
ec718d4ca4 Rename the third texure coordinate from 'r' to 'p'
Using 'r' to name the third component is problematic because that is
commonly used to represent the red component of a vector representing
a color. Under GLSL this is awkward because the texture swizzling for
a vector uses a single letter for each component and the names for
colors, textures and positions are synonymous. GLSL works around this
by naming the components of the texture s, t, p and q. Cogl already
effectively already exposes this naming because it exposes GLSL so it
makes sense to use that naming consistently. Another alternative could
be u, v and w. This is what Blender and Direct3D use. However the w
component conflicts with the w component of a position vertex.
2010-07-13 14:29:07 +01:00
Neil Roberts
2c8bf00995 Don't define public cogl_is_* functions for internal types
This adds a COGL_OBJECT_INTERNAL_DEFINE macro and friends that are the
same as COGL_OBJECT_DEFINE except that they prefix the cogl_is_*
function with an underscore so that it doesn't get exported in the
shared library.
2010-07-09 18:57:54 +01:00
Neil Roberts
61cbeeacfa cogl-texture: Share the common code in the set_region virtual
There was a lot of common code that was copied to all of the backends
to convert the data to a suitable format and wrap it into a CoglBitmap
so that it can be passed to _cogl_texture_driver_upload_subregion_to_gl.
This patch moves the common code to cogl-texture.c so that the virtual
just takes a CoglBitmap that is already in the right format.
2010-07-09 11:14:14 +01:00
Neil Roberts
223317c500 cogl-texture: Share the common code in the get_data virtual
Previously cogl_texture_get_data would pretty much directly pass on to
the get_data texture virtual function. This ended up with a lot of
common code that was copied to all of the backends. For example, the
method is expected to return the required data size if the data
pointer is NULL and to calculate its own rowstride if the rowstride is
0. Also it needs to convert the downloaded data if GL can't support
that format directly.

This patch moves the common code to cogl-texture.c so the virtual is
always called with a format that can be downloaded directly by GL and
with a valid rowstride. If the download fails then the virtual can
return FALSE in which case cogl-texture will use the draw and read
fallback.
2010-07-09 11:00:48 +01:00
Neil Roberts
9a1aa08fda cogl: Add an internal CoglTextureRectangle backend
This adds an internal rectangle texture backend which is mostly based
on the CoglTexture2D backend. It will throw assert failures if any
operations are attempted that rectangle textures don't support, such
as mipmapping or hardware repeating.
2010-06-22 11:47:33 +01:00