Commit Graph

605 Commits

Author SHA1 Message Date
Neil Roberts
830f2402d4 Merge branch 'more-texture-backends'
This adds three new texture backends.

- CoglTexture2D: This is a trimmed down version of CoglTexture2DSliced
  which only supports a single texture and only works with the
  GL_TEXTURE_2D target. The code is a lot simpler so it has a less
  overheads than dealing with slices. Cogl will use this wherever
  possible.

- CoglSubTexture: This is used to get a CoglHandle to represent a
  subregion of another texture. The texture can be used as if it was a
  standalone texture but it does not need to copy the resources.

- CoglAtlasTexture: This collects RGB and RGBA textures into a single
  GL texture with the aim of reducing texture state changes and
  increasing batching. The backend will try to manage the atlas and
  may move the textures around to close gaps in the texture. By
  default all textures will be placed in the atlas.
2010-02-06 00:20:32 +00:00
Neil Roberts
6b1b27d4f8 cogl-bitmap: Update the format after (un)premultiplying
The pixel format of the bitmap needs to have its premult flag cleared
or set after the premult conversion otherwise it may get converted
again.
2010-02-06 00:13:25 +00:00
Neil Roberts
191d20eb56 cogl-atlas-texture: Fix a cut and paste error when getting the height
There was a typo in getting the height of the full texture to check
whether the sub region fits so that it was using the width
instead. This was causing crashes when debugging is enabled for some
apps.
2010-02-05 17:03:04 +00:00
Damien Lespiau
1bdc3db9ab docs: Use % for defines not #
Some links to defines in the gtk-doc annotations were using '#' instead
of '%'.
2010-02-04 21:10:02 +00:00
Neil Roberts
e6a3b6ebe7 cogl-texture: Avoid copying the bitmap when premultiplying from a file
In cogl_texture_new_from_file we create and own a temporary
bitmap. There's no need to copy this data if we need to do a premult
conversion so instead it just does conversion before passing it on to
cogl_texture_new_from_bitmap.
2010-02-03 23:27:45 +00:00
Neil Roberts
59198b8ab8 cogl-texture: Split out _cogl_texture_prepare_for_upload
The Cogl atlas code was using _cogl_texture_prepare_for_upload with a
NULL pointer for the dst_bmp to determine the internal format of the
texture without converting the bitmap. It needs to do this to decide
whether the texture will go in the atlas before wasting time on the
conversion. This use of the function is a little confusing so that
part of it has been split out into a new function called
_cogl_texture_determine_internal_format. The code to decide whether a
premult conversion is needed has also been split out.
2010-02-03 23:10:52 +00:00
Neil Roberts
5063f4669c cogl-atlas: Make the cogl_atlas_* API internal
This just adds an underscore to every entry point for the CoglAtlas
API so that it's not exported.
2010-02-03 23:09:26 +00:00
Emmanuele Bassi
6fbed66add Delay default stage creation
The default stage creation should be delayed as much as possible,
ideally at the end of the init() process.
2010-02-03 16:34:27 +00:00
Emmanuele Bassi
3191ea1195 cogl-debug: Remove redundant newlines
The debugging notes wrapping g_debug() already have an implicit newline
at the end of the passed message.
2010-02-03 16:34:27 +00:00
Neil Roberts
74c0170ccc cogl-vertex-buffer: Refix disabling texture coord arrays
Commit 92a375ab4 changed the initial value of max_texcoord_attrib_unit
to -1 so that it could disable the texture coord array for the first
texture unit when there are no texture coords used in the vbo. However
max_texcoord_attrib_unit was an unsigned value so this actually became
G_MAXUINT. The disabling loop at the bottom still worked because
G_MAXUINT+1==0 but the check for whether any texture unit is greater
than max_texcoord_attrib_unit was failing so it would always end up
disabling all texture units. This is now fixed by changing
max_texcoord_attrib_unit to be signed.
2010-02-03 14:31:12 +00:00
Neil Roberts
145cc9d3df Merge remote branch 'master' into texture-debugging
Conflicts:
	clutter/cogl/cogl/cogl-context.h
2010-02-01 13:37:19 +00:00
Neil Roberts
aa6731e338 cogl-material: Compare GL texture numbers for material layer textures
When deciding if a material layer is equal it now compares the GL
target and texture number if the textures are not sliced. This is
needed to get batching across atlased textures.
2010-02-01 13:27:42 +00:00
Neil Roberts
abe91784c4 cogl: Let GL do the format conversion when uploading texture data
Cogl accepts a pixel format for both the data in memory and the
internal format to be used for the texture. If they do not match then
it would convert them using the CoglBitmap functions before uploading
the data. However, GL also lets you specify both formats so it makes
more sense to let GL do the conversion. The driver may need the
texture in a specific format so it may end up being converted anyway.

The cogl_texture_upload_data functions have been removed and replaced
with a single function to prepare the bitmap. This will only do the
premultiplication conversion because that is the only part that GL
can't do directly.
2010-02-01 13:27:34 +00:00
Neil Roberts
e83ffb1fa3 cogl: Do the premult conversion in-place rather than copying to a new buffer
The premult part of _cogl_convert_premult has now been split out as
_cogl_convert_premult_status. _cogl_convert_premult has been renamed
to _cogl_convert_format to make it less confusing. The premult
conversion is now done in-place instead of copying the
buffer. Previously it was copying the buffer once for the format
conversion and then copying it again for the premult conversion. The
premult conversion never changes the size of the buffer so it's quite
easy to do in place. We can also use the separated out function
independently.
2010-02-01 13:27:34 +00:00
Neil Roberts
72fba19eac cogl-atlas-texture: Use a single atlas for both RGB and RGBA textures
The internal format of the atlas texture is still set to the
appropriate format so Cogl will disable blending for textures that are
intended to be RGB. This should end up ignoring the alpha channel from
the texture in the atlas. This makes the code slightly easier to
maintain and should also improve the chances of batching.
2010-02-01 13:27:29 +00:00
Emmanuele Bassi
7a1ebcbced Whitespace fixes in cogl-util 2010-02-01 10:40:34 +00:00
Neil Roberts
046a4b8047 cogl: Use the colours of COGL_DEBUG=rectangles to debug batching
Instead of assigning a new colour to each quad of a batch, the
rectangle debugging code now assigns a new colour to each batch so
that it can be used to visually see what is being batched. The colour
is stored in a global variable that is reset during cogl_clear. This
improves the chances that the same colour will be used for a batch in
the next frames to avoid flickering.
2010-01-28 16:52:42 +00:00
Neil Roberts
92a375ab47 cogl-vertex-buffer: Fix disabling the texture arrays from previous prim
When setting up the state for the vertex buffer,
enable_state_for_drawing_buffer tries to keep track of the highest
numbered texture unit in use. It then disables any texture arrays for
units that were previously enabled if they are greater than that
number. However if there is no texturing in the VBO then the max used
unit would be left at 0 which it would later think meant unit 0 is
still in use so it wouldn't disable it. To fix this it now initialises
the max used unit to -1 which it should interpret as ‘no units are in
use’ so it will later disable the arrays for all units.

Thanks to Jon Mayo for reporting the bug.

http://bugzilla.openedhand.com/show_bug.cgi?id=1957
2010-01-27 14:31:59 +00:00
Neil Roberts
f288eae0fc docs: Add some notes about the CoglPixelFormat enums
The pixel format enums didn't explain what order in memory the
components should be so it was difficult to use them.
2010-01-27 12:07:38 +00:00
Damien Lespiau
52cb54f5fa cogl: Fix checks of the number of available texture units
We were checking the number of texture units against the GL enum that is
used in glGetInteger() to query that number. Let's abstract this in a
little function.

Took the opportunity to dig a bit on the usage of GL limits for the
number of texture (image) units and document our use of them. We'll need
something finer grained if we want to fully exploit texture image units
with a programmable pipeline.
2010-01-26 18:47:25 +00:00
Damien Lespiau
06d8ebb0ba cogl: Create CoglTextureUnit with its associated unit number
The index field of CoglTextureUnit was never set, leading to the
creation of units with index set to 0. When trying to retrieve a texture
unit by its index (!= 0) with _cogl_get_texture_unit(), a new one was
created as it could not find it back in the list of textures units:
ctx->texture_units.

http://bugzilla.openedhand.com/show_bug.cgi?id=1958
2010-01-26 12:12:20 +00:00
Neil Roberts
996614cfaf cogl-atlas-texture: Add a debug option to disable the atlas
If the user specifies the 'disable-atlas' debug option then no texture
will be put in the atlas.
2010-01-22 15:54:15 +00:00
Neil Roberts
08b8b2791f cogl-atlas-texture: Don't create atlas textures with the premult bit
Previously the atlas textures were being created with whatever format
the first sub texture is in. Only three formats are supported so this
only matters if the first texture is a premultiplied alpha
texture. Instead it now masks out the premultiplied bit so that the
textures are always either RGB_888 or RGBA_8888.
2010-01-19 17:15:51 +00:00
Neil Roberts
c4adefffd3 cogl-atlas-texture: Fix premultiplied texture formats
When uploading texture data it was just calling cogl_texture_set_data
on the large texture. This would attempt to convert the data to the
format of the large texture. All of the textures with alpha channels
are stored together regardless of whether they are premultiplied so
this was causing premultiplied textures to be unpremultiplied
again. It now just uploads the data ignoring the premult bit of the
format so that it only gets converted once.
2010-01-18 10:53:00 +00:00
Neil Roberts
b78024bd2d cogl-primitives: Ensure the mipmaps for a layer before logging quads
With the atlas texture backend ensuring the mipmaps can make it become
a completely different texture which will have different texture
coordinates or may even be sliced. Therefore we need to ensure the
mipmaps before deciding which quads to log in the journal. This adds a
new private function to cogl-material which ensures the mipmaps if
needed.
2010-01-18 09:22:11 +00:00
Neil Roberts
36f18e5ac5 cogl: Make CoglSubTexture only work for quad rendering
The sub texture backend doesn't work well as a completely general
texture backend because for example when rendering with cogl_polygon
it needs to be able to tranform arbitrary texture coordinates without
reference to the other coordintes. This can't be done when the texture
coordinates are a multiple of one because sometimes the coordinate
should represent the left or top edge and sometimes it should
represent the bottom or top edge. For example if the s coordinates are
0 and 1 then 1 represents the right edge but if they are 1 and 2 then
1 represents the left edge.

Instead the sub-textures are now documented not to support coordinates
outside the range [0,1]. The coordinates for the sub-region are now
represented as integers as this helps avoid rounding issues. The
region can no longer be a super-region of the texture as this
simplifies the code quite a lot.

There are two new texture virtual functions:

transform_quad_coords_to_gl - This transforms two pairs of coordinates
     representing a quad. It will return FALSE if the coordinates can
     not be transformed. The sub texture backend uses this to detect
     coordinates that require repeating which causes cogl-primitives
     to use manual repeating.

ensure_non_quad_rendering - This is used in cogl_polygon and
     cogl_vertex_buffer to inform the texture backend that
     transform_quad_to_gl is going to be used. The atlas backend
     migrates the texture out of the atlas when it hits this.
2010-01-18 09:22:04 +00:00
Neil Roberts
b844653c64 cogl-texture: Fix manual repeating for negative coordinates
When calculating the next integer position for negative coordinates it
would not increment if the position is already a multiple of one so we
need to manually add one.
2010-01-15 12:16:06 +00:00
Neil Roberts
a01b4eefce cogl-texture-2d: Fix the coordinate wrapping for negative coordinates
The formula to wrap the coordinates to the [0,1] range was broken when
the coordinates were negative.
2010-01-15 12:16:06 +00:00
Neil Roberts
ead4399536 Merge branch 'master' into more-texture-backends 2010-01-15 12:15:46 +00:00
Neil Roberts
8247bdf4f9 cogl-framebuffer: Return gboolean from try_creating_fbo
When try_creating_fbo fails it returns 0 to report the error and if it
succeeds it returns ‘flags’. However cogl_offscreen_new_to_texture
also passes in 0 for the flags as the last fallback to create the fbo
with nothing but the color buffer. In that case it will return 0
regardless of whether it succeeded so the last fallback will always be
considered a failure.

To fix this it now just returns a gboolean to indicate whether it
succeeded and the flags used for each attempt is assigned when passing
the argument rather than from the return value of the function.

Also if the only configuration that succeeded was with flags==0 then
it would always try all combinations because last_working_flags would
also be zero. To avoid this it now uses a separate gboolean to mark
whether we found a successful set of flags.

http://bugzilla.openedhand.com/show_bug.cgi?id=1873
2010-01-14 14:10:05 +00:00
Emmanuele Bassi
5322546a4e build: Clean up COGL build flags 2010-01-13 17:15:06 +00:00
Neil Roberts
778e08e4e2 cogl-framebuffer: Add some missing GL defines
Since 755cce33a7 the framebuffer code is using the GL enums
GL_DEPTH_ATTACHMENT and GL_DEPTH_COMPONENT16. These aren't available
directly under GLES except with the OES suffix so we need to define
them manually as we do with the other framebuffer constants.
2010-01-12 17:10:15 +00:00
Neil Roberts
bb8352ca95 cogl: Remove the CGL_* defines
These macros used to define Cogl wrappers for the GLenum values. There are
now Cogl enums everywhere in the API where these were required so we
shouldn't need them anymore. They were in the public headers but as
they are not neccessary and were not in the API docs for Clutter 1.0
it should be safe to remove them.
2010-01-12 17:10:15 +00:00
Robert Bragg
8b950bdc87 journal: Fixes logging of multiple sets of texture coordinates
If a user supplied multiple groups of texture coordinates with
cogl_rectangle_with_multitexture_coords() then we would repeatedly log only
the first group in the journal.  This fixes that bug and adds a conformance
test to verify the fix.

Thanks to Gord Allott for reporting this bug.
2010-01-12 11:22:08 +00:00
Robert Bragg
755cce33a7 cogl: Support multiple fallbacks in cogl_offscreen_new_to_texture()
The Intel drivers in Mesa 7.6 (and possibly earlier versions) don't
support creating FBOs with a stencil buffer but without a depth
buffer. This reworks framebuffer allocation so that we try a number
of fallback options before failing.

The options we try in order are:
- the same options that were sucessful last time if available
- combined depth and stencil
- separate depth and stencil
- just stencil, no depth
- just depth, no stencil
- neither depth or stencil
2010-01-11 15:32:52 +00:00
Robert Bragg
d9b91d61f5 framebuffers: cogl_offscreen_new_to_texture should take a ref on the texture
We weren't taking a reference on the texture to be used as the color buffer
for offscreen rendering, so it was possible to free the texture leaving the
framebuffer in an inconsistent state.
2010-01-08 20:42:35 +00:00
Robert Bragg
30b557c465 profiling: Adds initial UProf accounting to Cogl
This adds gives Cogl a dedicated UProf context which will be linked together
with Clutter's context during clutter_init_real().

Initial timers cover _cogl_journal_flush and _cogl_journal_log_quad

You can explicitly ask for a report of Cogl statistics by exporting
COGL_PROFILE_OUTPUT_REPORT=1 but since the context is linked with Clutter's
the statisitcs will also be shown in the automatic Clutter reports.
2010-01-08 20:19:50 +00:00
Emmanuele Bassi
8b59573190 Covert stb_image.c to Unix format
The file is still in DOS format (CRLF instead of LF) and this confuses
the hell out of some versions of Git.
2010-01-05 18:02:29 +00:00
Emmanuele Bassi
58b5a46e0e Include cogl-defines.h before using GL types
If we are using GL* types we should also be including cogl-defines.h, as
that will include the right GL header.
2010-01-05 17:55:47 +00:00
Emmanuele Bassi
793fec8138 cogl: Fix array annotations
The arrays in the cogl_program_set_uniform_* API should be marked as
such, and have their length arguments specified.
2010-01-05 17:55:47 +00:00
Emmanuele Bassi
4adc2c2d83 build: Move CoglMatrixMode to cogl-matrix-stack.h
This avoids a redeclaration of _cogl_matrix_stack_flush_to_gl() from
using GLenum to CoglMatrixMode.

http://bugzilla.openedhand.com/show_bug.cgi?id=1928
2010-01-04 11:58:32 +00:00
Halton Huo
eb90295041 cogl-texture: Remove return in void functions
http://bugzilla.o-hand.com/show_bug.cgi?id=1929

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2010-01-04 11:51:06 +00:00
Emmanuele Bassi
b98d486fc9 build: Maintainer cflags go in the _CFLAGS target
The maintainer compiler flags are not pre-processor flags.
2010-01-04 11:49:13 +00:00
Emmanuele Bassi
0fb51658fd cogl: Const-ify vertices in cogl_polygon()
The CoglTextureVertex array passed to cogl_polygon() is a pure
in-argument and should be const-ified.

http://bugzilla.openedhand.com/show_bug.cgi?id=1917
2010-01-04 11:43:00 +00:00
Emmanuele Bassi
a09ac0b27c Merge branch 'stage-use-alpha' into ebassi-next
* stage-use-alpha:
  tests: Use accessor methods for :use-alpha
  stage: Add accessors for :use-alpha
  tests: Allow setting the stage opacity in test-paint-wrapper
  stage: Premultiply the stage color
  stage: Composite the opacity with the alpha channel
  glx: Always request an ARGB visual
  stage: Add :use-alpha property
  materials: Get the right blend function for alpha
2009-12-20 17:39:12 +00:00
Neil Roberts
34b50934be cogl-material: Ensure mipmaps before doing anything else on a texture
When the texture is in the atlas, ensuring the mipmaps can effectively
make it become a completely different texture so we should do this
before getting the GL handle.
2009-12-05 14:20:00 +00:00
Neil Roberts
231cfffa18 cogl-atlas-texture: Remove textures from the atlas when mipmapping is required
Mipmaps don't work very well in the current atlas because there is not
enough padding between the textures. If ensure_mipmaps is called it
will now create a new texture and migrate the atlased texture to
it. It will use the same blit mechanism as when migrating so it will
try to use an FBO for a fast blit. However if this is not possible it
will end up downloading the data for the entire atlas which is not
ideal.
2009-12-05 14:11:57 +00:00
Neil Roberts
6cf5ee2cbd cogl-atlas-texture: Try to do texture blits using an FBO
When reorganizing the textures, we can avoid downloading the entire
texture data if we bind the source texture in a framebuffer object and
copy the destination using glCopyTexSubImage2D. This is also
implemented using a much faster path in Mesa.

Currently it is calling the GL framebuffer API directly but ideally it
would use the Cogl offscreen API. However there is no way to tell Cogl
not to create a stencil renderbuffer which seems like a waste in this
situation.

If FBOs are not available it will fallback to reading back the entire
texture data as before.
2009-12-05 14:11:31 +00:00
Neil Roberts
c51a31a2fc cogl-atlas: Add a debug option to visualize the atlas
This adds a 'dump-atlas-image' debug category. When enabled, CoglAtlas
will use Cairo to create a png which visualizes the leaf rectangles of
the atlas.
2009-12-04 20:29:12 +00:00
Neil Roberts
032d6e8aa0 cogl-texture-atlas: Add some debugging notes
This adds an 'atlas' category to the COGL_DEBUG environment
variable. When enabled Cogl will display messages when textures are
added to the atlas and when the atlas is reorganized.
2009-12-04 20:29:12 +00:00