diff options
author | David Reveman <davidr@novell.com> | 2004-09-03 14:27:57 +0000 |
---|---|---|
committer | David Reveman <davidr@novell.com> | 2004-09-03 14:27:57 +0000 |
commit | ed87d4348a8c8d433966cbecacd7a5bcfd49a961 (patch) | |
tree | 8b79d722df84618cd52ce4b96b9811025e16b045 | |
parent | f4130c9875ccc100a5ee954ab1155c3c7f4d3696 (diff) |
Switched to new geometry interface
35 files changed, 2026 insertions, 3634 deletions
@@ -1,3 +1,67 @@ +2004-09-03 David Reveman <c99drn@cs.umu.se> + + * src/glitzint.h: Switched to geometry buffers. + + * src/glitz_texture.c: Added texcoord_width_unit and + texcoord_height_unit. + Always use glTexGen for texture coordinates. + + * src/glitz_surface.c: Cleaned up public API. + Switched to geometry buffers. + glitz_buffer_t -> glitz_color_buffer_t. + + * src/glitz_status.c: Removed unused status values. Added + CONTENT_DESTROYED. + + * src/glitz_rect.c: fill -> set and set always use SRC operator. + glitz_set_rectangles works for all surfaces, drawable or not. + + * src/glitz_program.c: Transformations are no longer done in + fragment programs. Vertex programs are no longer needed. + + * src/glitz_pixel.c: Use fixed point pixel conversion. + pixel_buffer -> buffer and moved to glitz_buffer.c. + glitz_put_pixels -> glitz_set_pixels. + + * src/glitz_operator.c: Stencil operators no longer needed. + + * src/glitz_gl.h: VertexArray, TexGen tokens and prototypes. + More buffer object prototypes. + + * src/glitz_filter.c: Use float instead of double everywhere. + Do all calculations at "filter set" time and nothing at + "filter use" time. + Vertex programs are no longer needed. + + * src/glitz_compose.c: Use float instead of double everywhere. + Vertex programs are no longer needed. + + * src/glitz_glx_surface.c: New context specific backend objects. + Removed update_size backend function. + + * src/glitz_agl_surface.c: New context specific backend objects. + Removed update_size backend function. + + * src/glitz_glx_context.c: New context specific backend objects. + + * src/glitz_agl_context.c: New context specific backend objects. + + * src/glitz.h: Added new geometry system. Cleaned up public API. + + * src/glitz.c: Switched using vertex arrays and vertex buffer + objects for everything. + + * src/Makefile.am (libglitz_la_SOURCES): Removed glitz_trap.c, + glitz_tri.c and glitz_stencil.c. Added glitz_buffer.c and + glitz_geometry.c. + + * src/glitz.h (GLITZ_REVISION): Bump version to 0.2.0. + + * configure.in: Bump version to 0.2.0. + + * TODO: Switched to geometry buffers. + Transformations are no longer done in fragment programs. + 2004-08-18 David Reveman <c99drn@cs.umu.se> * src/glitzint.h: New filter system should now be working. @@ -1,26 +1,20 @@ -* Use different fragment programs for transformed surfaces and - non-transformed surfaces. - * Allow the fragment filters to be applied to mask surfaces and not only source surfaces. The filter system and the fragment programs are design to work both with source and mask surfaces, - so this should be really easy. Most work will be to validate that - it works correct for all cases. + so this should be really easy. Most of the work will be to validate + that it works correct in all cases. * Add low-pass sub-pixel filters for HW accelerated color balancing of per-component alpha masks. * Gamma correction. Software multi-sampling using stencil bits can easily be gamma corrected without any performance penelty. - Gammma correction for the add_trapezoids and add_triangles might - be harder. The above mentioned sub-pixel filters should include - gamma correction and I should probably also add a gamma correction filter for - alpha-masks and per-component alpha-masks without color + The above mentioned sub-pixel filters should include gamma + correction and I should probably also add a gamma correction + filter for alpha-masks and per-component alpha-masks without color balancing. -* GL_MESA_pack_invert support. - -* Retained-mode rendering. +* Improve AGL backend (proc address lookups). * WGL (Windows GL) backend. diff --git a/configure.in b/configure.in index 935dd00..346fb90 100644 --- a/configure.in +++ b/configure.in @@ -6,7 +6,7 @@ dnl =========================================================================== # Package version number, (as distinct from shared library version) # This must be manually synchronized with the version in src/glitz.h -GLITZ_VERSION=0.1.5 +GLITZ_VERSION=0.2.0 # libtool shared library version # Increment if the interface has additions, changes, removals. diff --git a/src/Makefile.am b/src/Makefile.am index 087de42..8dd3ee9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,16 +31,15 @@ libglitz_la_SOURCES = \ glitz_surface.c \ glitz_texture.c \ glitz_rect.c \ - glitz_trap.c \ - glitz_tri.c \ glitz_status.c \ glitz_util.c \ glitz_format.c \ glitz_program.c \ glitz_compose.c \ - glitz_stencil.c \ - glitz_pixel.c \ glitz_filter.c \ + glitz_buffer.c \ + glitz_geometry.c \ + glitz_pixel.c \ glitz_gl.h \ glitzint.h diff --git a/src/glitz.c b/src/glitz.c index 0e146ea..df21f6f 100644 --- a/src/glitz.c +++ b/src/glitz.c @@ -44,6 +44,7 @@ glitz_gl_uint_t _texture_units[] = { typedef struct _glitz_texture_unit_t { glitz_texture_t *texture; glitz_gl_uint_t unit; + glitz_bool_t transform; } glitz_texture_unit_t; void @@ -60,17 +61,17 @@ glitz_composite (glitz_operator_t op, int width, int height) { - glitz_gl_proc_address_list_t *gl = dst->gl; + glitz_gl_proc_address_list_t *gl = &dst->backend->gl; glitz_surface_t *intermediate = NULL; glitz_bounding_box_t rect; glitz_composite_op_t comp_op; int i, passes, texture_nr = -1; glitz_texture_t *stexture, *mtexture; glitz_texture_unit_t textures[3]; - glitz_point_t t0_tl, t0_br, t1_tl, t1_br; - glitz_gl_enum_t t0 = 0x0, t1 = 0x0; - glitz_point_t *tl, *br; glitz_color_t alpha_mask; + glitz_gl_enum_t primitive; + glitz_gl_int_t first; + glitz_gl_sizei_t count; if (width <= 0 || height <= 0) return; @@ -83,44 +84,6 @@ glitz_composite (glitz_operator_t op, src = comp_op.src; mask = comp_op.mask; - - if (src && SURFACE_CLIP (src)) { - if (x_src < 0) { - x_dst -= x_src; - x_mask -= x_src; - width += x_src; - x_src = 0; - } - - if (y_src < 0) { - y_dst -= y_src; - y_mask -= y_src; - height += y_src; - y_src = 0; - } - - width = MIN (src->width - x_src, width); - height = MIN (src->height - y_src, height); - } - - if (mask && SURFACE_CLIP (mask)) { - if (x_mask < 0) { - x_dst -= x_mask; - x_src -= x_mask; - width += x_mask; - x_mask = 0; - } - - if (y_mask < 0) { - y_dst -= y_mask; - y_src -= y_mask; - height += y_mask; - y_mask = 0; - } - - width = MIN (mask->width - x_mask, width); - height = MIN (mask->height - y_mask, height); - } if (comp_op.type == GLITZ_COMBINE_TYPE_INTERMEDIATE) { glitz_format_t templ; @@ -204,53 +167,35 @@ glitz_composite (glitz_operator_t op, rect.y1 = y_dst; rect.x2 = rect.x1 + width; rect.y2 = rect.y1 + height; - + if (mtexture) { textures[0].texture = mtexture; textures[0].unit = _texture_units[0]; + textures[0].transform = 0; texture_nr = 0; glitz_texture_bind (gl, mtexture); - - tl = &t0_tl; - br = &t0_br; - t0 = textures[0].unit; - - if (SURFACE_WINDOW_SPACE_TEXCOORDS (mask)) { - tl->x = x_mask; - tl->y = y_mask; - br->x = x_mask + width; - br->y = y_mask + height; - } else { - glitz_texture_tex_coord (mtexture, x_mask, y_mask, &tl->x, &tl->y); - glitz_texture_tex_coord (mtexture, x_mask + width, y_mask + height, - &br->x, &br->y); - } - - gl->matrix_mode (GLITZ_GL_TEXTURE); - gl->load_identity (); + + glitz_texture_set_tex_gen (gl, + mtexture, + rect.x1 - x_mask, + rect.y1 - y_mask, + mask->height, + mask->flags); if (mask->transform) { - if (SURFACE_WINDOW_SPACE_TEXCOORDS (mask)) { - gl->mult_matrix_d (mask->transform->m); - } else { - gl->scale_d (1.0, -1.0, 1.0); - gl->translate_d (0.0, -mtexture->texcoord_height, 0.0); - gl->mult_matrix_d (mask->transform->m_norm); - } + textures[0].transform = 1; + gl->matrix_mode (GLITZ_GL_TEXTURE); + gl->load_matrix_f (SURFACE_TEXTURE_COORDS (mask)? + mask->transform->t: mask->transform->m); + gl->matrix_mode (GLITZ_GL_MODELVIEW); if (SURFACE_LINEAR_TRANSFORM_FILTER (mask)) glitz_texture_ensure_filter (gl, mtexture, GLITZ_GL_LINEAR); else glitz_texture_ensure_filter (gl, mtexture, GLITZ_GL_NEAREST); - } else { - if (!SURFACE_WINDOW_SPACE_TEXCOORDS (mask)) { - tl->y = mtexture->texcoord_height - tl->y; - br->y = mtexture->texcoord_height - br->y; - } - + } else glitz_texture_ensure_filter (gl, mtexture, GLITZ_GL_NEAREST); - } if (SURFACE_REPEAT (mask)) { if (SURFACE_MIRRORED (mask)) @@ -258,7 +203,7 @@ glitz_composite (glitz_operator_t op, else glitz_texture_ensure_wrap (gl, mtexture, GLITZ_GL_REPEAT); } else { - if (SURFACE_PAD (mask) || SURFACE_CLIP (mask)) + if (SURFACE_PAD (mask)) glitz_texture_ensure_wrap (gl, mtexture, GLITZ_GL_CLAMP_TO_EDGE); else glitz_texture_ensure_wrap (gl, mtexture, GLITZ_GL_CLAMP_TO_BORDER); @@ -271,56 +216,32 @@ glitz_composite (glitz_operator_t op, while (texture_nr < last_texture_nr) { textures[++texture_nr].texture = stexture; textures[texture_nr].unit = _texture_units[texture_nr]; + textures[texture_nr].transform = 0; if (texture_nr > 0) gl->active_texture (textures[texture_nr].unit); glitz_texture_bind (gl, stexture); } - - if (t0) { - tl = &t1_tl; - br = &t1_br; - t1 = textures[texture_nr].unit; - } else { - tl = &t0_tl; - br = &t0_br; - t0 = textures[texture_nr].unit; - } - - if (SURFACE_WINDOW_SPACE_TEXCOORDS (src)) { - tl->x = x_src; - tl->y = y_src; - br->x = x_src + width; - br->y = y_src + height; - } else { - glitz_texture_tex_coord (stexture, x_src, y_src, &tl->x, &tl->y); - glitz_texture_tex_coord (stexture, x_src + width, y_src + height, - &br->x, &br->y); - } - gl->matrix_mode (GLITZ_GL_TEXTURE); - gl->load_identity (); + glitz_texture_set_tex_gen (gl, + stexture, + rect.x1 - y_src, + rect.y1 - x_src, + src->height, + src->flags); if (src->transform) { - if (SURFACE_WINDOW_SPACE_TEXCOORDS (src)) { - gl->mult_matrix_d (src->transform->m); - } else { - gl->scale_d (1.0, -1.0, 1.0); - gl->translate_d (0.0, -stexture->texcoord_height, 0.0); - gl->mult_matrix_d (src->transform->m_norm); - } - + textures[texture_nr].transform = 1; + gl->matrix_mode (GLITZ_GL_TEXTURE); + gl->load_matrix_f (SURFACE_TEXTURE_COORDS (src)? + src->transform->t: src->transform->m); + gl->matrix_mode (GLITZ_GL_MODELVIEW); + if (SURFACE_LINEAR_TRANSFORM_FILTER (src)) glitz_texture_ensure_filter (gl, stexture, GLITZ_GL_LINEAR); else glitz_texture_ensure_filter (gl, stexture, GLITZ_GL_NEAREST); - } else { - if (!SURFACE_WINDOW_SPACE_TEXCOORDS (src)) { - tl->y = stexture->texcoord_height - tl->y; - br->y = stexture->texcoord_height - br->y; - } - + } else glitz_texture_ensure_filter (gl, stexture, GLITZ_GL_NEAREST); - } if (SURFACE_REPEAT (src)) { if (SURFACE_MIRRORED (src)) @@ -328,7 +249,7 @@ glitz_composite (glitz_operator_t op, else glitz_texture_ensure_wrap (gl, stexture, GLITZ_GL_REPEAT); } else { - if (SURFACE_PAD (src) || SURFACE_CLIP (src)) + if (SURFACE_PAD (src)) glitz_texture_ensure_wrap (gl, stexture, GLITZ_GL_CLAMP_TO_EDGE); else glitz_texture_ensure_wrap (gl, stexture, GLITZ_GL_CLAMP_TO_BORDER); @@ -337,86 +258,135 @@ glitz_composite (glitz_operator_t op, glitz_set_operator (gl, op); - if (dst->multi_sample) - passes = dst->multi_sample->n_samples; - else if (comp_op.component_alpha) - passes = comp_op.component_alpha; - else + gl->scissor (rect.x1, + dst->height - rect.y2, + rect.x2 - rect.x1, + rect.y2 - rect.y1); + + gl->push_matrix (); + + glitz_geometry_enable (gl, dst, &primitive, &first, &count); + + if (dst->indirect) { + glitz_sample_offset_t *offsets; + + passes = dst->indirect->n_samples; + offsets = dst->indirect->offsets; + + gl->enable (GLITZ_GL_STENCIL_TEST); + gl->color_mask (GLITZ_GL_FALSE, GLITZ_GL_FALSE, GLITZ_GL_FALSE, + GLITZ_GL_FALSE); + gl->clear_stencil (0); + gl->clear (GLITZ_GL_STENCIL_BUFFER_BIT); + gl->stencil_func (GLITZ_GL_ALWAYS, ~0, ~0); + gl->stencil_op (GLITZ_GL_KEEP, GLITZ_GL_INCR, GLITZ_GL_INCR); + + for (i = 0; i < passes; i++) { + gl->push_matrix (); + gl->translate_f (offsets[i].x, offsets[i].y, 0.0f); + gl->draw_arrays (primitive, first, count); + gl->pop_matrix (); + } + + gl->pop_matrix (); + gl->push_matrix (); + + gl->color_mask (GLITZ_GL_TRUE, GLITZ_GL_TRUE, GLITZ_GL_TRUE, + GLITZ_GL_TRUE); + + glitz_geometry_enable_default (gl, dst); + primitive = GLITZ_GL_QUADS; + first = 0; + count = 4; + } else passes = 1; + if (comp_op.component_alpha) + passes *= comp_op.component_alpha; + alpha_mask = comp_op.alpha_mask; for (i = 0; i < passes; i++) { - if (dst->multi_sample) { - if ((i + 1) == passes) - glitz_set_stencil_operator (gl, GLITZ_STENCIL_OPERATOR_CLIP, - (*dst->stencil_mask & ~0x1) | (i + 1)); + unsigned short weight, sample; + + if (dst->indirect) { + if (comp_op.component_alpha) + sample = i / comp_op.component_alpha; else - glitz_set_stencil_operator (gl, GLITZ_STENCIL_OPERATOR_CLIP_EQUAL, - (*dst->stencil_mask & ~0x1) | (i + 1)); - - SET_COLOR (comp_op.alpha_mask, 0x0, 0x0, 0x0, - SHORT_MULT (dst->multi_sample->weights[i], alpha_mask.alpha)); + sample = i; + + weight = dst->indirect->weights[sample]; - } else if (comp_op.component_alpha) { - switch (i) { + gl->stencil_func (GLITZ_GL_EQUAL, sample + 1, ~0); + gl->stencil_op (GLITZ_GL_KEEP, GLITZ_GL_KEEP, GLITZ_GL_KEEP); + } else + weight = 0xffff; + + if (comp_op.component_alpha) { + switch (i % comp_op.component_alpha) { case 0: - SET_COLOR (comp_op.alpha_mask, alpha_mask.red, 0x0, 0x0, 0x0); - gl->color_mask (1, 0, 0, 0); + SET_COLOR (comp_op.alpha_mask, + SHORT_MULT (weight, alpha_mask.red), 0, 0, 0); + gl->color_mask (GLITZ_GL_TRUE, GLITZ_GL_FALSE, GLITZ_GL_FALSE, + GLITZ_GL_FALSE); break; case 1: - SET_COLOR (comp_op.alpha_mask, 0x0, 0x0, alpha_mask.blue, 0x0); - gl->color_mask (0, 0, 1, 0); + SET_COLOR (comp_op.alpha_mask, + 0, 0, SHORT_MULT (weight, alpha_mask.blue), 0); + gl->color_mask (GLITZ_GL_FALSE, GLITZ_GL_FALSE, GLITZ_GL_TRUE, + GLITZ_GL_FALSE); break; case 2: - SET_COLOR (comp_op.alpha_mask, 0x0, alpha_mask.green, 0x0, 0x0); - gl->color_mask (0, 1, 0, (passes == 4)? 0: 1); + SET_COLOR (comp_op.alpha_mask, + 0, SHORT_MULT (weight, alpha_mask.green), 0, 0); + gl->color_mask (GLITZ_GL_FALSE, GLITZ_GL_TRUE, GLITZ_GL_FALSE, + (comp_op.component_alpha == 4)? GLITZ_GL_FALSE: + GLITZ_GL_TRUE); break; case 3: - SET_COLOR (comp_op.alpha_mask, 0x0, 0x0, 0x0, alpha_mask.alpha); - gl->color_mask (0, 0, 0, 1); + SET_COLOR (comp_op.alpha_mask, + 0, 0, 0, SHORT_MULT (weight, alpha_mask.alpha)); + gl->color_mask (GLITZ_GL_FALSE, GLITZ_GL_FALSE, GLITZ_GL_FALSE, + GLITZ_GL_TRUE); break; } + } else { + SET_COLOR (comp_op.alpha_mask, 0, 0, 0, + SHORT_MULT (weight, alpha_mask.alpha)); } - - glitz_composite_enable (&comp_op); - - gl->begin (GLITZ_GL_QUADS); - - if (t0) gl->tex_coord_2d (t0_tl.x, t0_tl.y); - if (t1) gl->multi_tex_coord_2d (t1, t1_tl.x, t1_tl.y); - gl->vertex_2d (rect.x1, rect.y1); - if (t0) gl->tex_coord_2d (t0_br.x, t0_tl.y); - if (t1) gl->multi_tex_coord_2d (t1, t1_br.x, t1_tl.y); - gl->vertex_2d (rect.x2, rect.y1); - - if (t0) gl->tex_coord_2d (t0_br.x, t0_br.y); - if (t1) gl->multi_tex_coord_2d (t1, t1_br.x, t1_br.y); - gl->vertex_2d (rect.x2, rect.y2); - - if (t0) gl->tex_coord_2d (t0_tl.x, t0_br.y); - if (t1) gl->multi_tex_coord_2d (t1, t1_tl.x, t1_br.y); - gl->vertex_2d (rect.x1, rect.y2); - - gl->end (); + glitz_composite_enable (&comp_op); + gl->draw_arrays (primitive, first, count); } - if (comp_op.component_alpha) - gl->color_mask (1, 1, 1, 1); + glitz_geometry_disable (gl, dst); - glitz_composite_disable (&comp_op); + gl->pop_matrix (); + if (dst->indirect) + gl->disable (GLITZ_GL_STENCIL_TEST); + + if (comp_op.component_alpha) + gl->color_mask (GLITZ_GL_TRUE, GLITZ_GL_TRUE, GLITZ_GL_TRUE, + GLITZ_GL_TRUE); + + glitz_composite_disable (&comp_op); + for (i = texture_nr; i >= 0; i--) { glitz_texture_unbind (gl, textures[i].texture); + if (textures[i].transform) { + gl->matrix_mode (GLITZ_GL_TEXTURE); + gl->load_identity (); + gl->matrix_mode (GLITZ_GL_MODELVIEW); + } if (i > 0) gl->active_texture (textures[i - 1].unit); } glitz_surface_dirty (dst, &rect); - + glitz_surface_pop_current (dst); if (intermediate) @@ -469,7 +439,7 @@ glitz_copy_area (glitz_surface_t *src, if (width <= 0 || height <= 0) return; - gl = dst->gl; + gl = &dst->backend->gl; status = 0; if (glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { @@ -480,8 +450,10 @@ glitz_copy_area (glitz_surface_t *src, else status = 1; - gl->disable (GLITZ_GL_STENCIL_TEST); - dst->update_mask |= GLITZ_UPDATE_STENCIL_OP_MASK; + box.x1 = x_dst; + box.y1 = y_dst; + box.x2 = box.x1 + width; + box.y2 = box.y1 + height; if (status) { if (src->format->doublebuffer) @@ -495,48 +467,32 @@ glitz_copy_area (glitz_surface_t *src, } else { glitz_texture_t *texture = glitz_surface_get_texture (src, 0); if (texture) { - glitz_point_t tl, br; - glitz_texture_bind (gl, texture); - gl->matrix_mode (GLITZ_GL_TEXTURE); - gl->load_identity (); - + glitz_texture_set_tex_gen (gl, texture, x_dst, y_dst, height, ~0); + gl->tex_env_f (GLITZ_GL_TEXTURE_ENV, GLITZ_GL_TEXTURE_ENV_MODE, GLITZ_GL_REPLACE); gl->color_4us (0x0, 0x0, 0x0, 0xffff); - - glitz_set_operator (gl, GLITZ_OPERATOR_SRC); glitz_texture_ensure_wrap (gl, texture, GLITZ_GL_CLAMP_TO_EDGE); glitz_texture_ensure_filter (gl, texture, GLITZ_GL_NEAREST); + + glitz_set_operator (gl, GLITZ_OPERATOR_SRC); + + gl->scissor (box.x1, + dst->height - box.y2, + width, height); - glitz_texture_tex_coord (&dst->texture, x_dst, y_dst, &tl.x, &tl.y); - glitz_texture_tex_coord (&dst->texture, - x_dst + width, y_dst + height, &br.x, &br.y); - - tl.y = dst->texture.texcoord_height - tl.y; - br.y = dst->texture.texcoord_height - br.y; - - gl->begin (GLITZ_GL_QUADS); - gl->tex_coord_2d (tl.x, tl.y); - gl->vertex_2d (x_dst, y_dst); - gl->tex_coord_2d (br.x, tl.y); - gl->vertex_2d (x_dst + width, y_dst); - gl->tex_coord_2d (br.x, br.y); - gl->vertex_2d (x_dst + width, y_dst + height); - gl->tex_coord_2d (tl.x, br.y); - gl->vertex_2d (x_dst, y_dst + height); - gl->end (); + glitz_geometry_enable_default (gl, dst); + + gl->draw_arrays (GLITZ_GL_QUADS, 0, 4); + + glitz_geometry_disable (gl, dst); glitz_texture_unbind (gl, texture); } } - - box.x1 = x_dst; - box.y1 = y_dst; - box.x2 = box.x1 + width; - box.y2 = box.y1 + height; glitz_surface_dirty (dst, &box); glitz_surface_pop_current (dst); @@ -570,21 +526,19 @@ glitz_copy_area (glitz_surface_t *src, 0, 0, 0, GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP }; - glitz_pixel_buffer_t *buffer = + glitz_buffer_t *buffer = glitz_pixel_buffer_create (src, NULL, width * height * 4, - GLITZ_PIXEL_BUFFER_HINT_STATIC_COPY); + GLITZ_BUFFER_HINT_STATIC_COPY); if (!buffer) { glitz_surface_status_add (dst, GLITZ_STATUS_NO_MEMORY_MASK); return; } - glitz_pixel_buffer_set_format (buffer, &pf); - - glitz_get_pixels (src, x_src, y_src, width, height, buffer); - glitz_put_pixels (dst, x_dst, y_dst, width, height, buffer); + glitz_get_pixels (src, x_src, y_src, width, height, &pf, buffer); + glitz_set_pixels (dst, x_dst, y_dst, width, height, &pf, buffer); - glitz_pixel_buffer_destroy (buffer); + glitz_buffer_destroy (buffer); } } diff --git a/src/glitz.h b/src/glitz.h index 0f1c07b..230b4b6 100644 --- a/src/glitz.h +++ b/src/glitz.h @@ -1,28 +1,26 @@ /* - * Copyright © 2004 David Reveman, Peter Nilsson - * + * Copyright © 2004 David Reveman + * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without * fee, provided that the above copyright notice appear in all copies * and that both that copyright notice and this permission notice * appear in supporting documentation, and that the names of - * David Reveman and Peter Nilsson not be used in advertising or - * publicity pertaining to distribution of the software without - * specific, written prior permission. David Reveman and Peter Nilsson - * makes no representations about the suitability of this software for - * any purpose. It is provided "as is" without express or implied warranty. + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. * - * DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND - * PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA - * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * Authors: David Reveman <c99drn@cs.umu.se> - * Peter Nilsson <c99pnn@cs.umu.se> + * Author: David Reveman <c99drn@cs.umu.se> */ #ifndef GLITZ_H_INCLUDED @@ -40,37 +38,25 @@ /* NOTE: Must be manually synchronized with GLITZ_VERSION in configure.in */ #define GLITZ_MAJOR 0 -#define GLITZ_MINOR 1 -#define GLITZ_REVISION 5 +#define GLITZ_MINOR 2 +#define GLITZ_REVISION 0 #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif typedef int glitz_bool_t; +typedef short glitz_short_t; +typedef int glitz_int_t; +typedef float glitz_float_t; +typedef double glitz_double_t; typedef int glitz_fixed16_16_t; -typedef struct _glitz_point_fixed_t { - glitz_fixed16_16_t x, y; -} glitz_point_fixed_t; - typedef struct _glitz_rectangle_t { short x, y; unsigned short width, height; } glitz_rectangle_t; -typedef struct _glitz_triangle_t { - glitz_point_fixed_t p1, p2, p3; -} glitz_triangle_t; - -typedef struct _glitz_span_fixed_t { - glitz_fixed16_16_t left, right, y; -} glitz_span_fixed_t; - -typedef struct _glitz_trapezoid_t { - glitz_span_fixed_t top, bottom; -} glitz_trapezoid_t; - typedef struct _glitz_transform_t { glitz_fixed16_16_t matrix[3][3]; } glitz_transform_t; @@ -82,25 +68,6 @@ typedef struct { unsigned short alpha; } glitz_color_t; -typedef struct _glitz_colorspan_t { - glitz_fixed16_16_t left, right, y; - glitz_color_t left_color; - glitz_color_t right_color; -} glitz_colorspan_t; - -typedef struct _glitz_colorpoint_t { - glitz_point_fixed_t point; - glitz_color_t color; -} glitz_colorpoint_t; - -typedef struct _glitz_color_trapezoid_t { - glitz_colorspan_t top, bottom; -} glitz_color_trapezoid_t; - -typedef struct _glitz_color_triangle_t { - glitz_colorpoint_t p1, p2, p3; -} glitz_color_triangle_t; - typedef enum { GLITZ_FILTER_NEAREST, GLITZ_FILTER_BILINEAR, @@ -111,11 +78,6 @@ typedef enum { } glitz_filter_t; typedef enum { - GLITZ_POLYEDGE_SHARP, - GLITZ_POLYEDGE_SMOOTH -} glitz_polyedge_t; - -typedef enum { GLITZ_OPERATOR_CLEAR, GLITZ_OPERATOR_SRC, GLITZ_OPERATOR_DST, @@ -132,21 +94,20 @@ typedef enum { GLITZ_OPERATOR_SATURATE } glitz_operator_t; -#define GLITZ_FEATURE_OFFSCREEN_DRAWING_MASK (1L << 0) -#define GLITZ_FEATURE_TEXTURE_RECTANGLE_MASK (1L << 1) -#define GLITZ_FEATURE_TEXTURE_NON_POWER_OF_TWO_MASK (1L << 2) -#define GLITZ_FEATURE_TEXTURE_MIRRORED_REPEAT_MASK (1L << 3) -#define GLITZ_FEATURE_TEXTURE_BORDER_CLAMP_MASK (1L << 4) -#define GLITZ_FEATURE_MULTISAMPLE_MASK (1L << 5) -#define GLITZ_FEATURE_OFFSCREEN_MULTISAMPLE_MASK (1L << 6) -#define GLITZ_FEATURE_MULTISAMPLE_FILTER_HINT_MASK (1L << 7) -#define GLITZ_FEATURE_MULTITEXTURE_MASK (1L << 8) -#define GLITZ_FEATURE_TEXTURE_ENV_COMBINE_MASK (1L << 9) -#define GLITZ_FEATURE_TEXTURE_ENV_DOT3_MASK (1L << 10) -#define GLITZ_FEATURE_VERTEX_PROGRAM_MASK (1L << 11) -#define GLITZ_FEATURE_FRAGMENT_PROGRAM_MASK (1L << 12) -#define GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK (1L << 13) -#define GLITZ_FEATURE_COMPONENT_ALPHA_MASK (1L << 14) +#define GLITZ_FEATURE_TEXTURE_RECTANGLE_MASK (1L << 0) +#define GLITZ_FEATURE_TEXTURE_NON_POWER_OF_TWO_MASK (1L << 1) +#define GLITZ_FEATURE_TEXTURE_MIRRORED_REPEAT_MASK (1L << 2) +#define GLITZ_FEATURE_TEXTURE_BORDER_CLAMP_MASK (1L << 3) +#define GLITZ_FEATURE_MULTISAMPLE_MASK (1L << 4) +#define GLITZ_FEATURE_OFFSCREEN_MULTISAMPLE_MASK (1L << 5) +#define GLITZ_FEATURE_MULTISAMPLE_FILTER_HINT_MASK (1L << 6) +#define GLITZ_FEATURE_MULTITEXTURE_MASK (1L << 7) +#define GLITZ_FEATURE_TEXTURE_ENV_COMBINE_MASK (1L << 8) +#define GLITZ_FEATURE_TEXTURE_ENV_DOT3_MASK (1L << 9) +#define GLITZ_FEATURE_FRAGMENT_PROGRAM_MASK (1L << 10) +#define GLITZ_FEATURE_VERTEX_BUFFER_OBJECT_MASK (1L << 11) +#define GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK (1L << 12) +#define GLITZ_FEATURE_COMPONENT_ALPHA_MASK (1L << 13) typedef enum { GLITZ_STANDARD_ARGB32, @@ -198,16 +159,18 @@ typedef struct _glitz_format_t { glitz_multisample_format_t multisample; } glitz_format_t; +typedef struct _glitz_surface glitz_surface_t; +typedef struct _glitz_buffer glitz_buffer_t; + /* glitz_status.c */ typedef enum { GLITZ_STATUS_SUCCESS = 0, GLITZ_STATUS_NO_MEMORY, - GLITZ_STATUS_NULL_POINTER, GLITZ_STATUS_BAD_COORDINATE, GLITZ_STATUS_NOT_SUPPORTED, - GLITZ_STATUS_INVALID_MATRIX + GLITZ_STATUS_CONTENT_DESTROYED } glitz_status_t; const char * @@ -216,17 +179,17 @@ glitz_status_string (glitz_status_t status); /* glitz_surface.c */ -typedef struct _glitz_surface glitz_surface_t; - void glitz_surface_destroy (glitz_surface_t *surface); void +glitz_surface_reference (glitz_surface_t *surface); + +void glitz_surface_set_transform (glitz_surface_t *surface, glitz_transform_t *transform); typedef enum { - GLITZ_FILL_CLIP, GLITZ_FILL_TRANSPARENT, GLITZ_FILL_NEAREST, GLITZ_FILL_REPEAT, @@ -245,95 +208,35 @@ void glitz_surface_set_filter (glitz_surface_t *surface, glitz_filter_t filter, glitz_fixed16_16_t *params, - int n_params); - -void -glitz_surface_set_polyedge (glitz_surface_t *surface, - glitz_polyedge_t polyedge); + int n_params); typedef enum { - GLITZ_POLYEDGE_SMOOTH_HINT_FAST, - GLITZ_POLYEDGE_SMOOTH_HINT_GOOD, - GLITZ_POLYEDGE_SMOOTH_HINT_BEST -} glitz_polyedge_smooth_hint_t; - -void -glitz_surface_set_polyedge_smooth_hint (glitz_surface_t *surface, - glitz_polyedge_smooth_hint_t hint); + GLITZ_COLOR_BUFFER_FRONT, + GLITZ_COLOR_BUFFER_BACK +} glitz_color_buffer_t; -typedef enum { - GLITZ_CLIP_OPERATOR_SET, - GLITZ_CLIP_OPERATOR_UNION, - GLITZ_CLIP_OPERATOR_INTERSECT -} glitz_clip_operator_t; - -void -glitz_surface_clip_rectangles (glitz_surface_t *surface, - glitz_clip_operator_t op, - int x_offset, - int y_offset, - const glitz_rectangle_t *rects, - int n_rects); - void -glitz_surface_clip_trapezoids (glitz_surface_t *surface, - glitz_clip_operator_t op, - int x_offset, - int y_offset, - const glitz_trapezoid_t *traps, - int n_traps); +glitz_surface_set_read_color_buffer (glitz_surface_t *surface, + glitz_color_buffer_t buffer); void -glitz_surface_clip_triangles (glitz_surface_t *surface, - glitz_clip_operator_t op, - int x_offset, - int y_offset, - const glitz_triangle_t *tris, - int n_tris); +glitz_surface_set_draw_color_buffer (glitz_surface_t *surface, + glitz_color_buffer_t buffer); -int -glitz_surface_get_width (glitz_surface_t *surface); - -int -glitz_surface_get_height (glitz_surface_t *surface); - void -glitz_surface_update_size (glitz_surface_t *surface); - -typedef enum { - GLITZ_BUFFER_FRONT, - GLITZ_BUFFER_BACK -} glitz_buffer_t; - -void -glitz_surface_set_read_buffer (glitz_surface_t *surface, - glitz_buffer_t buffer); - -void -glitz_surface_set_draw_buffer (glitz_surface_t *surface, - glitz_buffer_t buffer); +glitz_surface_swap_buffers (glitz_surface_t *surface); void glitz_surface_flush (glitz_surface_t *surface); - -void -glitz_surface_swap_buffers (glitz_surface_t *surface); void glitz_surface_finish (glitz_surface_t *surface); -void -glitz_surface_get_gl_texture (glitz_surface_t *surface, - unsigned int *name, - unsigned int *target, - double *texcoord_width, - double *texcoord_height); - -void -glitz_surface_gl_begin (glitz_surface_t *surface); +int +glitz_surface_get_width (glitz_surface_t *surface); -void -glitz_surface_gl_end (glitz_surface_t *surface); +int +glitz_surface_get_height (glitz_surface_t *surface); glitz_status_t glitz_surface_get_status (glitz_surface_t *surface); @@ -360,13 +263,81 @@ glitz_surface_create_similar (glitz_surface_t *templ, int width, int height); -#define GLITZ_HINT_CLIPPING_MASK (1L << 0) -#define GLITZ_HINT_OFFSCREEN_MASK (1L << 1) -#define GLITZ_HINT_MULTISAMPLE_MASK (1L << 2) + +/* glitz_rect.c */ -unsigned long -glitz_surface_get_hints (glitz_surface_t *surface); +void +glitz_set_rectangle (glitz_surface_t *dst, + const glitz_color_t *color, + int x, + int y, + unsigned int width, + unsigned int height); + +void +glitz_set_rectangles (glitz_surface_t *dst, + const glitz_color_t *color, + const glitz_rectangle_t *rects, + int n_rects); + + +/* glitz_buffer.c */ + +typedef enum { + GLITZ_BUFFER_HINT_STREAM_DRAW, + GLITZ_BUFFER_HINT_STREAM_READ, + GLITZ_BUFFER_HINT_STREAM_COPY, + GLITZ_BUFFER_HINT_STATIC_DRAW, + GLITZ_BUFFER_HINT_STATIC_READ, + GLITZ_BUFFER_HINT_STATIC_COPY, + GLITZ_BUFFER_HINT_DYNAMIC_DRAW, + GLITZ_BUFFER_HINT_DYNAMIC_READ, + GLITZ_BUFFER_HINT_DYNAMIC_COPY +} glitz_buffer_hint_t; + +typedef enum { + GLITZ_BUFFER_ACCESS_READ_ONLY, + GLITZ_BUFFER_ACCESS_WRITE_ONLY, + GLITZ_BUFFER_ACCESS_READ_WRITE +} glitz_buffer_access_t; + +glitz_buffer_t * +glitz_geometry_buffer_create (glitz_surface_t *surface, + void *data, + unsigned int size, + glitz_buffer_hint_t hint); + +glitz_buffer_t * +glitz_pixel_buffer_create (glitz_surface_t *surface, + void *data, + unsigned int size, + glitz_buffer_hint_t hint); + +void +glitz_buffer_destroy (glitz_buffer_t *buffer); + +void +glitz_buffer_reference (glitz_buffer_t *buffer); + +void +glitz_buffer_set_data (glitz_buffer_t *buffer, + int offset, + unsigned int size, + const void *data); + +void +glitz_buffer_get_data (glitz_buffer_t *buffer, + int offset, + unsigned int size, + void *data); + +void * +glitz_buffer_map (glitz_buffer_t *buffer, + glitz_buffer_access_t access); +glitz_status_t +glitz_buffer_unmap (glitz_buffer_t *buffer); + /* glitz_pixel.c */ @@ -391,62 +362,14 @@ typedef struct _glitz_pixel_format { glitz_pixel_scanline_order_t scanline_order; } glitz_pixel_format_t; -typedef struct _glitz_pixel_buffer glitz_pixel_buffer_t; - -typedef enum { - GLITZ_PIXEL_BUFFER_HINT_STREAM_DRAW, - GLITZ_PIXEL_BUFFER_HINT_STREAM_READ, - GLITZ_PIXEL_BUFFER_HINT_STREAM_COPY, - GLITZ_PIXEL_BUFFER_HINT_STATIC_DRAW, - GLITZ_PIXEL_BUFFER_HINT_STATIC_READ, - GLITZ_PIXEL_BUFFER_HINT_STATIC_COPY, - GLITZ_PIXEL_BUFFER_HINT_DYNAMIC_DRAW, - GLITZ_PIXEL_BUFFER_HINT_DYNAMIC_READ, - GLITZ_PIXEL_BUFFER_HINT_DYNAMIC_COPY -} glitz_buffer_hint_t; - -glitz_pixel_buffer_t * -glitz_pixel_buffer_create (glitz_surface_t *surface, - char *data, - unsigned int size, - glitz_buffer_hint_t hint); - -glitz_pixel_buffer_t * -glitz_pixel_buffer_create_for_data (char *data, - glitz_pixel_format_t *format); - -void -glitz_pixel_buffer_destroy (glitz_pixel_buffer_t *buffer); - -void -glitz_pixel_buffer_set_format (glitz_pixel_buffer_t *buffer, - glitz_pixel_format_t *format); - -void -glitz_pixel_buffer_get_format (glitz_pixel_buffer_t *buffer, - glitz_pixel_format_t *format); - -typedef enum { - GLITZ_PIXEL_BUFFER_ACCESS_READ_ONLY, - GLITZ_PIXEL_BUFFER_ACCESS_WRITE_ONLY, - GLITZ_PIXEL_BUFFER_ACCESS_READ_WRITE -} glitz_pixel_buffer_access_t; - -char * -glitz_pixel_buffer_get_data (glitz_pixel_buffer_t *buffer, - glitz_pixel_buffer_access_t access); - -void -glitz_pixel_buffer_put_back_data (glitz_pixel_buffer_t *buffer); - void -glitz_put_pixels (glitz_surface_t *dst, +glitz_set_pixels (glitz_surface_t *dst, int x_dst, int y_dst, int width, int height, - glitz_pixel_buffer_t *buffer); - + glitz_pixel_format_t *format, + glitz_buffer_t *buffer); void glitz_get_pixels (glitz_surface_t *src, @@ -454,130 +377,55 @@ glitz_get_pixels (glitz_surface_t *src, int y_src, int width, int height, - glitz_pixel_buffer_t *buffer); + glitz_pixel_format_t *format, + glitz_buffer_t *buffer); -/* glitz_rect.c */ - -void -glitz_fill_rectangle (glitz_operator_t op, - glitz_surface_t *dst, - const glitz_color_t *color, - int x, - int y, - unsigned int width, - unsigned int height); - -void -glitz_fill_rectangles (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_rectangle_t *rects, - int n_rects); - - -/* glitz_trap.c */ - -void -glitz_fill_trapezoids (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_trapezoid_t *traps, - int n_traps); - -void -glitz_add_trapezoids (glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_trapezoid_t *traps, - int n_traps); - -void -glitz_composite_trapezoids (glitz_operator_t op, - glitz_surface_t *src, - glitz_surface_t *dst, - int x_src, - int y_src, - int x_offset, - int y_offset, - unsigned short opacity, - const glitz_trapezoid_t *traps, - int n_traps); - -void -glitz_color_trapezoids (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_trapezoid_t *color_traps, - int n_color_traps); +/* glitz_geometry.c */ +typedef enum { + GLITZ_GEOMETRY_MODE_DIRECT, + GLITZ_GEOMETRY_MODE_INDIRECT +} glitz_geometry_mode_t; -/* glitz_tri.c */ - -void -glitz_fill_triangles (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_triangle_t *tris, - int n_tris); - -void -glitz_add_triangles (glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_triangle_t *tris, - int n_tris); - -void -glitz_composite_triangles (glitz_operator_t op, - glitz_surface_t *src, - glitz_surface_t *dst, - int x_src, - int y_src, - int x_offset, - int y_offset, - unsigned short opacity, - const glitz_triangle_t *tris, - int n_tris); - -void -glitz_composite_tri_strip (glitz_operator_t op, - glitz_surface_t *src, - glitz_surface_t *dst, - int x_src, - int y_src, - int x_offset, - int y_offset, - unsigned short opacity, - const glitz_point_fixed_t *points, - int n_points); +typedef enum { + GLITZ_GEOMETRY_EDGE_HINT_SHARP, + GLITZ_GEOMETRY_EDGE_HINT_FAST_SMOOTH, + GLITZ_GEOMETRY_EDGE_HINT_GOOD_SMOOTH, + GLITZ_GEOMETRY_EDGE_HINT_BEST_SMOOTH +} glitz_geometry_edge_hint_t; -void -glitz_composite_tri_fan (glitz_operator_t op, - glitz_surface_t *src, - glitz_surface_t *dst, - int x_src, - int y_src, - int x_offset, - int y_offset, - unsigned short opacity, - const glitz_point_fixed_t *points, - int n_points); +typedef enum { + GLITZ_GEOMETRY_PRIMITIVE_TRIANGLES, + GLITZ_GEOMETRY_PRIMITIVE_TRIANGLE_STRIP, + GLITZ_GEOMETRY_PRIMITIVE_TRIANGLE_FAN, + GLITZ_GEOMETRY_PRIMITIVE_QUADS, + GLITZ_GEOMETRY_PRIMITIVE_QUAD_STRIP, + GLITZ_GEOMETRY_PRIMITIVE_POLYGON +} glitz_geometry_primitive_t; -void -glitz_color_triangles (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_triangle_t *color_tris, - int n_color_tris); +typedef enum { + GLITZ_DATA_TYPE_SHORT, + GLITZ_DATA_TYPE_INT, + GLITZ_DATA_TYPE_FLOAT, + GLITZ_DATA_TYPE_DOUBLE +} glitz_data_type_t; + +typedef struct _glitz_geometry_format { + glitz_geometry_mode_t mode; + glitz_geometry_edge_hint_t edge_hint; + glitz_geometry_primitive_t primitive; + glitz_data_type_t type; + int first; + unsigned int count; +} glitz_geometry_format_t; + +void +glitz_set_geometry (glitz_surface_t *dst, + int x_dst, + int y_dst, + glitz_geometry_format_t *format, + glitz_buffer_t *buffer); /* glitz.c */ diff --git a/src/glitz_agl_context.c b/src/glitz_agl_context.c index f398edf..3b57a4d 100644 --- a/src/glitz_agl_context.c +++ b/src/glitz_agl_context.c @@ -31,6 +31,8 @@ #include "glitz_aglint.h" +extern glitz_gl_proc_address_list_t _glitz_agl_gl_proc_address; + static void _glitz_agl_context_create (glitz_agl_thread_info_t *thread_info, AGLPixelFormat pixel_format, @@ -71,6 +73,19 @@ glitz_agl_context_get (glitz_agl_thread_info_t *thread_info, thread_info->format_ids[format->id], context); context->offscreen = offscreen; + + glitz_agl_surface_backend_init (&context->backend); + + memcpy (&context->backend.gl, + &_glitz_agl_gl_proc_address, + sizeof (glitz_gl_proc_address_list_t)); + + context->backend.formats = thread_info->formats; + context->backend.n_formats = thread_info->n_formats; + context->backend.program_map = &thread_info->program_map; + context->backend.feature_mask = thread_info->feature_mask; + + context->backend.gl.need_lookup = 0; return context; } diff --git a/src/glitz_agl_extension.c b/src/glitz_agl_extension.c index b93942c..7395f45 100644 --- a/src/glitz_agl_extension.c +++ b/src/glitz_agl_extension.c @@ -50,9 +50,13 @@ static glitz_extension_map gl_extensions[] = { { "GL_NV_multisample_filter_hint", GLITZ_AGL_FEATURE_MULTISAMPLE_FILTER_HINT_MASK }, { "GL_ARB_multitexture", GLITZ_AGL_FEATURE_MULTITEXTURE_MASK }, - { "GL_ARB_vertex_program", GLITZ_AGL_FEATURE_VERTEX_PROGRAM_MASK }, { "GL_ARB_fragment_program", GLITZ_AGL_FEATURE_FRAGMENT_PROGRAM_MASK }, - { "GL_EXT_pixel_buffer_object", GLITZ_AGL_FEATURE_PIXEL_BUFFER_OBJECT_MASK }, + /* TODO: lookup all symbols not part of OpenGL 1.1 + { "GL_ARB_vertex_buffer_object", + GLITZ_AGL_FEATURE_VERTEX_BUFFER_OBJECT_MASK }, + { "GL_EXT_pixel_buffer_object", + GLITZ_AGL_FEATURE_PIXEL_BUFFER_OBJECT_MASK }, + */ { NULL, 0 } }; @@ -76,9 +80,6 @@ glitz_agl_query_extensions (glitz_agl_thread_info_t *thread_info) thread_info->feature_mask = 0; thread_info->texture_mask = GLITZ_TEXTURE_TARGET_2D_MASK; - if (thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_PBUFFER_MASK) - thread_info->feature_mask |= GLITZ_FEATURE_OFFSCREEN_DRAWING_MASK; - if (thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_MULTISAMPLE_MASK) { thread_info->feature_mask |= GLITZ_FEATURE_MULTISAMPLE_MASK; @@ -133,13 +134,14 @@ glitz_agl_query_extensions (glitz_agl_thread_info_t *thread_info) thread_info->feature_mask |= GLITZ_FEATURE_COMPONENT_ALPHA_MASK; } - if (thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_VERTEX_PROGRAM_MASK) - thread_info->feature_mask |= GLITZ_FEATURE_VERTEX_PROGRAM_MASK; - if (thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_FRAGMENT_PROGRAM_MASK) thread_info->feature_mask |= GLITZ_FEATURE_FRAGMENT_PROGRAM_MASK; } + + if (thread_info->agl_feature_mask & + GLITZ_AGL_FEATURE_VERTEX_BUFFER_OBJECT_MASK) + thread_info->feature_mask |= GLITZ_FEATURE_VERTEX_BUFFER_OBJECT_MASK; if (thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_PIXEL_BUFFER_OBJECT_MASK) diff --git a/src/glitz_agl_format.c b/src/glitz_agl_format.c index e8df7e9..1b945b9 100644 --- a/src/glitz_agl_format.c +++ b/src/glitz_agl_format.c @@ -295,7 +295,7 @@ glitz_agl_query_formats (glitz_agl_thread_info_t *thread_info) format.id = (unsigned long int) pixel_format; format.read.onscreen = format.draw.onscreen = 1; - if (thread_info->feature_mask & GLITZ_FEATURE_OFFSCREEN_DRAWING_MASK) + if (thread_info->agl_feature_mask & GLITZ_AGL_FEATURE_PBUFFER_MASK) format.read.offscreen = format.draw.offscreen = 1; else format.read.offscreen = format.draw.offscreen = 0; diff --git a/src/glitz_agl_info.c b/src/glitz_agl_info.c index b5aa1f9..51849df 100644 --- a/src/glitz_agl_info.c +++ b/src/glitz_agl_info.c @@ -36,15 +36,16 @@ glitz_gl_proc_address_list_t _glitz_agl_gl_proc_address = { (glitz_gl_enable_t) glEnable, (glitz_gl_disable_t) glDisable, - (glitz_gl_begin_t) glBegin, - (glitz_gl_end_t) glEnd, - (glitz_gl_vertex_2i_t) glVertex2i, - (glitz_gl_vertex_2d_t) glVertex2d, + (glitz_gl_enable_client_state_t) glEnableClientState, + (glitz_gl_disable_client_state_t) glDisableClientState, + (glitz_gl_vertex_pointer_t) glVertexPointer, + (glitz_gl_draw_arrays_t) glDrawArrays, (glitz_gl_tex_env_f_t) glTexEnvf, (glitz_gl_tex_env_fv_t) glTexEnvfv, - (glitz_gl_tex_coord_2d_t) glTexCoord2d, + (glitz_gl_tex_gen_i_t) glTexGeni, + (glitz_gl_tex_gen_fv_t) glTexGenfv, (glitz_gl_color_4us_t) glColor4us, - (glitz_gl_color_4d_t) glColor4d, + (glitz_gl_color_4f_t) glColor4f, (glitz_gl_scissor_t) glScissor, (glitz_gl_blend_func_t) glBlendFunc, (glitz_gl_clear_t) glClear, @@ -58,11 +59,10 @@ glitz_gl_proc_address_list_t _glitz_agl_gl_proc_address = { (glitz_gl_push_matrix_t) glPushMatrix, (glitz_gl_pop_matrix_t) glPopMatrix, (glitz_gl_load_identity_t) glLoadIdentity, - (glitz_gl_load_matrix_d_t) glLoadMatrixd, - (glitz_gl_mult_matrix_d_t) glMultMatrixd, + (glitz_gl_load_matrix_f_t) glLoadMatrixf, (glitz_gl_depth_range_t) glDepthRange, (glitz_gl_viewport_t) glViewport, - (glitz_gl_raster_pos_2d_t) glRasterPos2d, + (glitz_gl_raster_pos_2f_t) glRasterPos2f, (glitz_gl_bitmap_t) glBitmap, (glitz_gl_read_buffer_t) glReadBuffer, (glitz_gl_draw_buffer_t) glDrawBuffer, @@ -71,8 +71,8 @@ glitz_gl_proc_address_list_t _glitz_agl_gl_proc_address = { (glitz_gl_finish_t) glFinish, (glitz_gl_pixel_store_i_t) glPixelStorei, (glitz_gl_ortho_t) glOrtho, - (glitz_gl_scale_d_t) glScaled, - (glitz_gl_translate_d_t) glTranslated, + (glitz_gl_scale_f_t) glScalef, + (glitz_gl_translate_f_t) glTranslatef, (glitz_gl_hint_t) glHint, (glitz_gl_depth_mask_t) glDepthMask, (glitz_gl_polygon_mode_t) glPolygonMode, @@ -84,7 +84,6 @@ glitz_gl_proc_address_list_t _glitz_agl_gl_proc_address = { (glitz_gl_gen_textures_t) glGenTextures, (glitz_gl_delete_textures_t) glDeleteTextures, (glitz_gl_bind_texture_t) glBindTexture, - (glitz_gl_tex_image_1d_t) glTexImage1D, (glitz_gl_tex_image_2d_t) glTexImage2D, (glitz_gl_tex_parameter_i_t) glTexParameteri, (glitz_gl_get_tex_level_parameter_iv_t) glGetTexLevelParameteriv, @@ -92,19 +91,23 @@ glitz_gl_proc_address_list_t _glitz_agl_gl_proc_address = { (glitz_gl_get_integer_v_t) glGetIntegerv, (glitz_gl_active_texture_t) glActiveTextureARB, - (glitz_gl_multi_tex_coord_2d_t) glMultiTexCoord2dARB, (glitz_gl_gen_programs_t) glGenProgramsARB, (glitz_gl_delete_programs_t) glDeleteProgramsARB, (glitz_gl_program_string_t) glProgramStringARB, (glitz_gl_bind_program_t) glBindProgramARB, - (glitz_gl_program_local_param_4d_t) glProgramLocalParameter4dARB, + (glitz_gl_program_local_param_4fv_t) glProgramLocalParameter4fvARB, (glitz_gl_get_program_iv_t) glGetProgramivARB, + + /* TODO: lookup all symbols not part of OpenGL 1.1 */ (glitz_gl_gen_buffers_t) 0, (glitz_gl_delete_buffers_t) 0, (glitz_gl_bind_buffer_t) 0, (glitz_gl_buffer_data_t) 0, + (glitz_gl_buffer_sub_data_t) 0, + (glitz_gl_get_buffer_sub_data_t) 0, (glitz_gl_map_buffer_t) 0, (glitz_gl_unmap_buffer_t) 0, + 0 }; @@ -235,6 +238,19 @@ glitz_agl_thread_info_init (glitz_agl_thread_info_t *thread_info) } } + glitz_agl_surface_backend_init (&thread_info->root_context.backend); + + memcpy (&thread_info->root_context.backend.gl, + &_glitz_agl_gl_proc_address, + sizeof (glitz_gl_proc_address_list_t)); + + thread_info->root_context.backend.formats = thread_info->formats; + thread_info->root_context.backend.n_formats = thread_info->n_formats; + thread_info->root_context.backend.program_map = &thread_info->program_map; + thread_info->root_context.backend.feature_mask = thread_info->feature_mask; + + thread_info->root_context.backend.gl.need_lookup = 0; + thread_info->context_stack_size = 1; thread_info->context_stack->surface = NULL; thread_info->context_stack->constraint = GLITZ_CN_NONE; diff --git a/src/glitz_agl_surface.c b/src/glitz_agl_surface.c index 0d58202..639db4c 100644 --- a/src/glitz_agl_surface.c +++ b/src/glitz_agl_surface.c @@ -31,27 +31,6 @@ #include "glitz_aglint.h" -extern glitz_gl_proc_address_list_t _glitz_agl_gl_proc_address; - -static glitz_surface_t * -_glitz_agl_surface_create_similar (void *abstract_templ, - glitz_format_t *format, - int width, - int height); - -static void -_glitz_agl_surface_destroy (void *abstract_surface); - -static glitz_texture_t * -_glitz_agl_surface_get_texture (void *abstract_surface, - glitz_bool_t allocate); - -static void -_glitz_agl_surface_update_size (void *abstract_surface); - -static void -_glitz_agl_surface_swap_buffers (void *abstract_surface); - static glitz_bool_t _glitz_agl_surface_push_current (void *abstract_surface, glitz_constraint_t constraint) @@ -96,23 +75,12 @@ _glitz_agl_surface_make_current_read (void *abstract_surface) return 0; } -static const struct glitz_surface_backend glitz_agl_surface_backend = { - _glitz_agl_surface_create_similar, - _glitz_agl_surface_destroy, - _glitz_agl_surface_push_current, - _glitz_agl_surface_pop_current, - _glitz_agl_surface_get_texture, - _glitz_agl_surface_update_size, - _glitz_agl_surface_swap_buffers, - _glitz_agl_surface_make_current_read -}; - static glitz_texture_t * _glitz_agl_surface_get_texture (void *abstract_surface, glitz_bool_t allocate) { glitz_agl_surface_t *surface = (glitz_agl_surface_t *) abstract_surface; - if (surface->base.hint_mask & GLITZ_INT_HINT_DIRTY_MASK) { + if (surface->base.flags & GLITZ_FLAG_DIRTY_MASK) { glitz_bounding_box_t copy_box; copy_box.x1 = copy_box.y1 = 0; @@ -122,7 +90,8 @@ _glitz_agl_surface_get_texture (void *abstract_surface, ©_box, ©_box); if (!surface->base.texture.allocated) - glitz_texture_allocate (surface->base.gl, &surface->base.texture); + glitz_texture_allocate (&surface->base.backend->gl, + &surface->base.texture); glitz_texture_copy_surface (&surface->base.texture, &surface->base, copy_box.x1, @@ -131,12 +100,14 @@ _glitz_agl_surface_get_texture (void *abstract_surface, copy_box.y2 - copy_box.y1, copy_box.x1, copy_box.y1); - surface->base.hint_mask &= ~GLITZ_INT_HINT_DIRTY_MASK; + + surface->base.flags &= ~GLITZ_FLAG_DIRTY_MASK; } if (allocate) { if (!surface->base.texture.allocated) - glitz_texture_allocate (surface->base.gl, &surface->base.texture); + glitz_texture_allocate (&surface->base.backend->gl, + &surface->base.texture); } if (surface->base.texture.allocated) @@ -146,9 +117,9 @@ _glitz_agl_surface_get_texture (void *abstract_surface, } static void -_glitz_agl_surface_update_size_for_window (WindowRef window, - int *width, - int *height) +_glitz_agl_surface_get_window_size (WindowRef window, + int *width, + int *height) { Rect window_bounds; @@ -158,12 +129,6 @@ _glitz_agl_surface_update_size_for_window (WindowRef window, *height = window_bounds.bottom - window_bounds.top; } -static void -_glitz_agl_set_features (glitz_agl_surface_t *surface) -{ - surface->base.feature_mask = surface->thread_info->feature_mask; -} - static glitz_surface_t * _glitz_agl_surface_create (glitz_agl_thread_info_t *thread_info, glitz_format_t *format, @@ -193,25 +158,19 @@ _glitz_agl_surface_create (glitz_agl_thread_info_t *thread_info, } glitz_surface_init (&surface->base, - &glitz_agl_surface_backend, - &_glitz_agl_gl_proc_address, + &context->backend, format, - thread_info->formats, - thread_info->n_formats, width, height, - &thread_info->program_map, texture_mask); surface->thread_info = thread_info; surface->context = context; - surface->base.hint_mask |= GLITZ_HINT_OFFSCREEN_MASK; + surface->base.flags |= GLITZ_FLAG_OFFSCREEN_MASK; if (format->draw.offscreen) - surface->base.hint_mask |= GLITZ_INT_HINT_DRAWABLE_MASK; - - _glitz_agl_set_features (surface); + surface->base.flags |= GLITZ_FLAG_DRAWABLE_MASK; return &surface->base; } @@ -239,21 +198,17 @@ glitz_agl_surface_create_for_window (glitz_format_t *format, if (!context) return NULL; - _glitz_agl_surface_update_size_for_window (window, &width, &height); + _glitz_agl_surface_get_window_size (window, &width, &height); surface = (glitz_agl_surface_t *) calloc (1, sizeof (glitz_agl_surface_t)); if (surface == NULL) return NULL; glitz_surface_init (&surface->base, - &glitz_agl_surface_backend, - &_glitz_agl_gl_proc_address, + &context->backend, format, - thread_info->formats, - thread_info->n_formats, width, height, - &thread_info->program_map, thread_info->texture_mask); surface->thread_info = thread_info; @@ -261,9 +216,7 @@ glitz_agl_surface_create_for_window (glitz_format_t *format, surface->window = window; surface->drawable = GetWindowPort (window); - surface->base.hint_mask |= GLITZ_INT_HINT_DRAWABLE_MASK; - - _glitz_agl_set_features (surface); + surface->base.flags |= GLITZ_FLAG_DRAWABLE_MASK; return &surface->base; } @@ -316,45 +269,6 @@ _glitz_agl_surface_destroy (void *abstract_surface) } static void -_glitz_agl_surface_update_size (void *abstract_surface) -{ - glitz_agl_surface_t *surface = (glitz_agl_surface_t *) abstract_surface; - - if (surface->window) { - int width, height; - - _glitz_agl_surface_update_size_for_window (surface->window, - &width, &height); - - if (width != surface->base.width || height != surface->base.height) { - glitz_texture_t texture; - - glitz_texture_init (&texture, - width, height, - surface->base.texture.format, - surface->thread_info->texture_mask); - - if (texture.width != surface->base.texture.width || - texture.height != surface->base.texture.height || - texture.target != surface->base.texture.target) { - texture.name = surface->base.texture.name; - surface->base.texture = texture; - } - - surface->base.width = width; - surface->base.height = height; - - glitz_agl_context_push_current (surface, - GLITZ_CN_SURFACE_DRAWABLE_CURRENT); - - aglUpdateContext (surface->context->context); - - glitz_agl_context_pop_current (surface); - } - } -} - -static void _glitz_agl_surface_swap_buffers (void *abstract_surface) { glitz_agl_surface_t *surface = (glitz_agl_surface_t *) abstract_surface; @@ -365,3 +279,15 @@ _glitz_agl_surface_swap_buffers (void *abstract_surface) glitz_agl_context_pop_current (surface); } + +void +glitz_agl_surface_backend_init (glitz_surface_backend_t *backend) +{ + backend->create_similar = _glitz_agl_surface_create_similar; + backend->destroy = _glitz_agl_surface_destroy; + backend->push_current = _glitz_agl_surface_push_current; + backend->pop_current = _glitz_agl_surface_pop_current; + backend->get_texture = _glitz_agl_surface_get_texture; + backend->swap_buffers = _glitz_agl_surface_swap_buffers; + backend->make_current_read = _glitz_agl_surface_make_current_read; +} diff --git a/src/glitz_aglint.h b/src/glitz_aglint.h index 984878f..39739de 100644 --- a/src/glitz_aglint.h +++ b/src/glitz_aglint.h @@ -46,8 +46,8 @@ #define GLITZ_AGL_FEATURE_MULTITEXTURE_MASK (1L << 7) #define GLITZ_AGL_FEATURE_TEXTURE_ENV_COMBINE_MASK (1L << 8) #define GLITZ_AGL_FEATURE_TEXTURE_ENV_DOT3_MASK (1L << 9) -#define GLITZ_AGL_FEATURE_VERTEX_PROGRAM_MASK (1L << 10) -#define GLITZ_AGL_FEATURE_FRAGMENT_PROGRAM_MASK (1L << 11) +#define GLITZ_AGL_FEATURE_FRAGMENT_PROGRAM_MASK (1L << 10) +#define GLITZ_AGL_FEATURE_VERTEX_BUFFER_OBJECT_MASK (1L << 11) #define GLITZ_AGL_FEATURE_PIXEL_BUFFER_OBJECT_MASK (1L << 12) typedef struct _glitz_agl_surface_t glitz_agl_surface_t; @@ -61,6 +61,7 @@ typedef struct _glitz_agl_context_t { AGLContext context; AGLPixelFormat pixel_format; glitz_bool_t offscreen; + glitz_surface_backend_t backend; } glitz_agl_context_t; typedef struct _glitz_agl_thread_info_t { @@ -76,9 +77,9 @@ typedef struct _glitz_agl_thread_info_t { glitz_agl_context_t root_context; - long int feature_mask; - long int agl_feature_mask; - long int texture_mask; + unsigned long feature_mask; + unsigned long agl_feature_mask; + unsigned long texture_mask; glitz_program_map_t program_map; } glitz_agl_thread_info_t; @@ -129,6 +130,9 @@ glitz_agl_pbuffer_create (glitz_texture_t *texture); extern void __internal_linkage glitz_agl_pbuffer_destroy (AGLPbuffer pbuffer); +extern void __internal_linkage +glitz_agl_surface_backend_init (glitz_surface_backend_t *backend); + /* Avoid unnecessary PLT entries. */ diff --git a/src/glitz_buffer.c b/src/glitz_buffer.c new file mode 100644 index 0000000..ec008e9 --- /dev/null +++ b/src/glitz_buffer.c @@ -0,0 +1,301 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman <c99drn@cs.umu.se> + */ + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "glitzint.h" + +static glitz_status_t +_glitz_buffer_init (glitz_buffer_t *buffer, + glitz_surface_t *surface, + void *data, + glitz_buffer_hint_t hint) +{ + glitz_gl_enum_t usage; + + buffer->ref_count = 1; + + switch (hint) { + case GLITZ_BUFFER_HINT_STREAM_DRAW: + usage = GLITZ_GL_STREAM_DRAW; + break; + case GLITZ_BUFFER_HINT_STREAM_READ: + usage = GLITZ_GL_STREAM_READ; + break; + case GLITZ_BUFFER_HINT_STREAM_COPY: + usage = GLITZ_GL_STREAM_COPY; + break; + case GLITZ_BUFFER_HINT_STATIC_DRAW: + usage = GLITZ_GL_STATIC_DRAW; + break; + case GLITZ_BUFFER_HINT_STATIC_READ: + usage = GLITZ_GL_STATIC_READ; + break; + case GLITZ_BUFFER_HINT_STATIC_COPY: + usage = GLITZ_GL_STATIC_COPY; + break; + case GLITZ_BUFFER_HINT_DYNAMIC_DRAW: + usage = GLITZ_GL_DYNAMIC_DRAW; + break; + case GLITZ_BUFFER_HINT_DYNAMIC_READ: + usage = GLITZ_GL_DYNAMIC_READ; + break; + default: + usage = GLITZ_GL_DYNAMIC_COPY; + break; + } + + if (surface) { + buffer->surface = surface; + glitz_surface_reference (surface); + + surface->backend->gl.gen_buffers (1, &buffer->name); + if (buffer->name) { + surface->backend->gl.bind_buffer (buffer->target, buffer->name); + surface->backend->gl.buffer_data (buffer->target, buffer->size, + data, usage); + } + } else + buffer->surface = NULL; + + if (buffer->name == 0) { + buffer->data = malloc (buffer->size); + if (buffer->data == NULL) + return GLITZ_STATUS_NO_MEMORY; + + if (data) + memcpy (buffer->data, data, buffer->size); + + buffer->owns_data = 1; + } + + return GLITZ_STATUS_SUCCESS; +} + +glitz_buffer_t * +glitz_geometry_buffer_create (glitz_surface_t *surface, + void *data, + unsigned int size, + glitz_buffer_hint_t hint) +{ + glitz_buffer_t *buffer; + glitz_status_t status; + + buffer = malloc (sizeof (glitz_buffer_t)); + if (buffer == NULL) + return NULL; + + buffer->size = size; + buffer->name = 0; + buffer->target = GLITZ_GL_ARRAY_BUFFER; + + if (surface->backend->feature_mask & GLITZ_FEATURE_VERTEX_BUFFER_OBJECT_MASK) + status = _glitz_buffer_init (buffer, surface, data, hint); + else + status = _glitz_buffer_init (buffer, NULL, data, hint); + + if (status != GLITZ_STATUS_SUCCESS) { + free (buffer); + return NULL; + } + + return buffer; +} + +glitz_buffer_t * +glitz_pixel_buffer_create (glitz_surface_t *surface, + void *data, + unsigned int size, + glitz_buffer_hint_t hint) +{ + glitz_buffer_t *buffer; + glitz_status_t status; + + buffer = malloc (sizeof (glitz_buffer_t)); + if (buffer == NULL) + return NULL; + + buffer->size = size; + buffer->name = 0; + buffer->target = GLITZ_GL_PIXEL_UNPACK_BUFFER; + + if (surface->backend->feature_mask & GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK) + status = _glitz_buffer_init (buffer, surface, data, hint); + else + status = _glitz_buffer_init (buffer, NULL, data, hint); + + if (status != GLITZ_STATUS_SUCCESS) { + free (buffer); + return NULL; + } + + return buffer; +} + +void +glitz_buffer_destroy (glitz_buffer_t *buffer) +{ + if (!buffer) + return; + + buffer->ref_count--; + if (buffer->ref_count) + return; + + if (buffer->surface) { + buffer->surface->backend->gl.delete_buffers (1, &buffer->name); + glitz_surface_destroy (buffer->surface); + } else if (buffer->owns_data) + free (buffer->data); + + free (buffer); +} + +void +glitz_buffer_reference (glitz_buffer_t *buffer) +{ + if (buffer == NULL) + return; + + buffer->ref_count++; +} + +void +glitz_buffer_set_data (glitz_buffer_t *buffer, + int offset, + unsigned int size, + const void *data) +{ + if (buffer->surface) { + glitz_surface_push_current (buffer->surface, GLITZ_CN_ANY_CONTEXT_CURRENT); + + buffer->surface->backend->gl.bind_buffer (buffer->target, buffer->name); + buffer->surface->backend->gl.buffer_sub_data (buffer->target, + offset, size, data); + buffer->surface->backend->gl.bind_buffer (buffer->target, 0); + + glitz_surface_pop_current (buffer->surface); + } else if (buffer->data) + memcpy ((char *) buffer->data + offset, data, size); +} +slim_hidden_def(glitz_buffer_set_data); + +void +glitz_buffer_get_data (glitz_buffer_t *buffer, + int offset, + unsigned int size, + void *data) +{ + if (buffer->surface) { + glitz_surface_push_current (buffer->surface, GLITZ_CN_ANY_CONTEXT_CURRENT); + + buffer->surface->backend->gl.bind_buffer (buffer->target, buffer->name); + buffer->surface->backend->gl.get_buffer_sub_data (buffer->target, + offset, size, data); + buffer->surface->backend->gl.bind_buffer (buffer->target, 0); + + glitz_surface_pop_current (buffer->surface); + } else if (buffer->data) + memcpy (data, (char *) buffer->data + offset, size); +} +slim_hidden_def(glitz_buffer_get_data); + +void * +glitz_buffer_map (glitz_buffer_t *buffer, + glitz_buffer_access_t access) +{ + void *pointer = NULL; + + if (buffer->surface) { + glitz_gl_enum_t buffer_access; + + glitz_surface_push_current (buffer->surface, GLITZ_CN_ANY_CONTEXT_CURRENT); + + switch (access) { + case GLITZ_BUFFER_ACCESS_READ_ONLY: + buffer_access = GLITZ_GL_READ_ONLY; + break; + case GLITZ_BUFFER_ACCESS_WRITE_ONLY: + buffer_access = GLITZ_GL_WRITE_ONLY; + break; + default: + buffer_access = GLITZ_GL_READ_WRITE; + break; + } + + buffer->surface->backend->gl.bind_buffer (buffer->target, buffer->name); + pointer = buffer->surface->backend->gl.map_buffer (buffer->target, + buffer_access); + + glitz_surface_pop_current (buffer->surface); + } + + if (pointer == NULL) + pointer = buffer->data; + + return pointer; +} + +glitz_status_t +glitz_buffer_unmap (glitz_buffer_t *buffer) +{ + glitz_status_t status = GLITZ_STATUS_SUCCESS; + + if (buffer->surface) { + glitz_surface_push_current (buffer->surface, GLITZ_CN_ANY_CONTEXT_CURRENT); + + if (buffer->surface->backend->gl.unmap_buffer (buffer->target)) + status = GLITZ_STATUS_CONTENT_DESTROYED; + + buffer->surface->backend->gl.bind_buffer (buffer->target, 0); + + glitz_surface_pop_current (buffer->surface); + } + + return status; +} + +void * +glitz_buffer_bind (glitz_buffer_t *buffer, + glitz_gl_enum_t target) +{ + if (buffer->surface) { + buffer->surface->backend->gl.bind_buffer (target, buffer->name); + buffer->target = target; + + return NULL; + } + + return buffer->data; +} + +void +glitz_buffer_unbind (glitz_buffer_t *buffer) +{ + if (buffer->surface) + buffer->surface->backend->gl.bind_buffer (buffer->target, 0); +} diff --git a/src/glitz_compose.c b/src/glitz_compose.c index 1b8f656..9c3abf2 100644 --- a/src/glitz_compose.c +++ b/src/glitz_compose.c @@ -125,11 +125,11 @@ _glitz_combine_argb_argbc (glitz_composite_op_t *op) } if (op->alpha_mask.red) { - op->gl->color_4d (1.0, 0.5, 0.5, 0.5); + op->gl->color_4f (1.0f, 0.5f, 0.5f, 0.5f); } else if (op->alpha_mask.green) { - op->gl->color_4d (0.5, 1.0, 0.5, 0.5); + op->gl->color_4f (0.5f, 1.0f, 0.5f, 0.5f); } else if (op->alpha_mask.blue) { - op->gl->color_4d (0.5, 0.5, 1.0, 0.5); + op->gl->color_4f (0.5f, 0.5f, 1.0f, 0.5f); } else { op->gl->active_texture (GLITZ_GL_TEXTURE0); op->gl->tex_env_f (GLITZ_GL_TEXTURE_ENV, GLITZ_GL_TEXTURE_ENV_MODE, @@ -305,23 +305,23 @@ _glitz_combine_solid_argbc (glitz_composite_op_t *op) op->gl->tex_env_f (GLITZ_GL_TEXTURE_ENV, GLITZ_GL_OPERAND1_ALPHA, GLITZ_GL_SRC_ALPHA); - color[0] = (double) op->solid->red / 65536.0; - color[1] = (double) op->solid->green / 65536.0; - color[2] = (double) op->solid->blue / 65536.0; - color[3] = (double) op->solid->alpha / 65536.0; + color[0] = op->solid->red / 65536.0f; + color[1] = op->solid->green / 65536.0f; + color[2] = op->solid->blue / 65536.0f; + color[3] = op->solid->alpha / 65536.0f; op->gl->tex_env_fv (GLITZ_GL_TEXTURE_ENV, GLITZ_GL_TEXTURE_ENV_COLOR, color); } if (op->alpha_mask.red) { - op->gl->color_4d (1.0, 0.5, 0.5, 0.5); + op->gl->color_4f (1.0f, 0.5f, 0.5f, 0.5f); } else if (op->alpha_mask.green) { - op->gl->color_4d (0.5, 1.0, 0.5, 0.5); + op->gl->color_4f (0.5f, 1.0f, 0.5f, 0.5f); } else if (op->alpha_mask.blue) { - op->gl->color_4d (0.5, 0.5, 1.0, 0.5); + op->gl->color_4f (0.5f, 0.5f, 1.0f, 0.5f); } else { - static glitz_gl_float_t color[] = { 0.0, 0.0, 0.0, 0.0 }; + static glitz_gl_float_t color[] = { 0.0f, 0.0f, 0.0f, 0.0f }; op->gl->active_texture (GLITZ_GL_TEXTURE0); op->gl->tex_env_f (GLITZ_GL_TEXTURE_ENV, GLITZ_GL_TEXTURE_ENV_MODE, @@ -417,13 +417,11 @@ _glitz_combine_map[GLITZ_SURFACE_TYPES][GLITZ_SURFACE_TYPES] = { ) \ ) \ : \ - (SURFACE_CLIP (surface) || \ - (SURFACE_PAD (surface)? \ - ((surface)->texture.repeatable || \ - (surface)->texture.target != GLITZ_GL_TEXTURE_2D) \ - : \ - ((feature_mask) & GLITZ_FEATURE_TEXTURE_BORDER_CLAMP_MASK) \ - ) \ + (SURFACE_PAD (surface)? \ + ((surface)->texture.repeatable || \ + (surface)->texture.target != GLITZ_GL_TEXTURE_2D) \ + : \ + ((feature_mask) & GLITZ_FEATURE_TEXTURE_BORDER_CLAMP_MASK) \ ) \ ) @@ -477,27 +475,29 @@ glitz_composite_op_init (glitz_composite_op_t *op, op->type = GLITZ_COMBINE_TYPE_NA; op->combine = NULL; op->alpha_mask = _default_alpha_mask; - op->gl = dst->gl; + op->gl = &dst->backend->gl; op->src = src; op->mask = mask; op->dst = dst; op->count = 0; op->solid = NULL; op->component_alpha = GLITZ_COMPONENT_ALPHA_NONE; - op->vp = op->fp = 0; + op->fp = 0; + + if (dst->indirect && (dst->format->stencil_size < 1)) + return; - src_type = _glitz_get_surface_type (src, dst->feature_mask); + src_type = _glitz_get_surface_type (src, dst->backend->feature_mask); if (src_type < 1) return; - mask_type = _glitz_get_surface_type (mask, dst->feature_mask); + mask_type = _glitz_get_surface_type (mask, dst->backend->feature_mask); if (mask_type < 0) return; combine = &_glitz_combine_map[src_type][mask_type]; if (combine->type == GLITZ_COMBINE_TYPE_NA) { - if (dst->feature_mask & GLITZ_FEATURE_OFFSCREEN_DRAWING_MASK) - op->type = GLITZ_COMBINE_TYPE_INTERMEDIATE; + op->type = GLITZ_COMBINE_TYPE_INTERMEDIATE; return; } @@ -522,7 +522,7 @@ glitz_composite_op_init (glitz_composite_op_t *op, op->component_alpha = GLITZ_COMPONENT_ALPHA_RGB; } } else if (mask_type != GLITZ_SURFACE_TYPE_NULL) { - if (dst->feature_mask & GLITZ_FEATURE_TEXTURE_ENV_COMBINE_MASK) { + if (dst->backend->feature_mask & GLITZ_FEATURE_TEXTURE_ENV_COMBINE_MASK) { if (mask_type == GLITZ_SURFACE_TYPE_ARGBC) { if (mask->format->alpha_size) op->component_alpha = GLITZ_COMPONENT_ALPHA_ARGB; @@ -531,28 +531,21 @@ glitz_composite_op_init (glitz_composite_op_t *op, } if (op->src) { - if (dst->feature_mask & GLITZ_FEATURE_MULTITEXTURE_MASK) { + if (dst->backend->feature_mask & GLITZ_FEATURE_MULTITEXTURE_MASK) { op->combine = combine; - } else if ((dst->feature_mask & - GLITZ_FEATURE_OFFSCREEN_DRAWING_MASK) && - (!op->component_alpha)) + } else if (!op->component_alpha) op->type = GLITZ_COMBINE_TYPE_INTERMEDIATE; } else op->combine = combine; } - } else { - if (SURFACE_POLYGON_OP (dst)) - op->alpha_mask.alpha = dst->polyopacity; - + } else op->combine = combine; - } if (op->combine == combine) { op->type = combine->type; if (combine->fragment_processing) { - op->vp = glitz_filter_get_vertex_program (src, op); op->fp = glitz_filter_get_fragment_program (src, op); - if (op->vp == 0 || op->fp == 0) + if (op->fp == 0) op->type = GLITZ_COMBINE_TYPE_NA; } } @@ -568,12 +561,8 @@ glitz_composite_enable (glitz_composite_op_t *op) void glitz_composite_disable (glitz_composite_op_t *op) { - if (op->vp) { + if (op->fp) { op->gl->bind_program (GLITZ_GL_FRAGMENT_PROGRAM, 0); op->gl->disable (GLITZ_GL_FRAGMENT_PROGRAM); } - if (op->fp) { - op->gl->bind_program (GLITZ_GL_VERTEX_PROGRAM, 0); - op->gl->disable (GLITZ_GL_VERTEX_PROGRAM); - } } diff --git a/src/glitz_filter.c b/src/glitz_filter.c index 906083d..602c493 100644 --- a/src/glitz_filter.c +++ b/src/glitz_filter.c @@ -31,25 +31,9 @@ #include <math.h> -typedef struct _glitz_linear_gradient_filter_t { - glitz_point_t start; - glitz_point_t stop; -} glitz_linear_gradient_filter_t; - -typedef struct _glitz_radial_gradient_filter_t { - glitz_point_t center; - double radius_base, radius_scale; -} glitz_radial_gradient_filter_t; - struct _glitz_filter_params_t { int fp_type; - int id; - - union { - glitz_linear_gradient_filter_t linear; - glitz_radial_gradient_filter_t radial; - } u; - + int id; glitz_vec4_t *vectors; int n_vectors; }; @@ -78,13 +62,13 @@ _glitz_filter_params_ensure (glitz_filter_params_t **params, int vectors) } static void -_glitz_filter_params_set (double *value, - const double default_value, +_glitz_filter_params_set (glitz_float_t *value, + const glitz_float_t default_value, glitz_fixed16_16_t **params, int *n_params) { if (*n_params > 0) { - *value = FIXED_TO_DOUBLE (**params); + *value = FIXED_TO_FLOAT (**params); (*params)++; (*n_params)--; } else @@ -115,11 +99,11 @@ glitz_filter_set_params (glitz_surface_t *surface, switch (filter) { case GLITZ_FILTER_CONVOLUTION: { - double dm, dn, sum, tx, ty; + glitz_float_t dm, dn, sum, tx, ty; int cx, cy, m, n, j; - _glitz_filter_params_set (&dm, 3.0, ¶ms, &n_params); - _glitz_filter_params_set (&dn, 3.0, ¶ms, &n_params); + _glitz_filter_params_set (&dm, 3.0f, ¶ms, &n_params); + _glitz_filter_params_set (&dn, 3.0f, ¶ms, &n_params); m = dm; n = dn; @@ -138,53 +122,54 @@ glitz_filter_set_params (glitz_surface_t *surface, tx = surface->texture.texcoord_width / surface->texture.width; ty = surface->texture.texcoord_height / surface->texture.height; - sum = 0.0; + sum = 0.0f; for (i = 0; i < m; i++) { glitz_vec4_t *vec; - double weight; + glitz_float_t weight; for (j = 0; j < n; j++) { - _glitz_filter_params_set (&weight, 0.0, ¶ms, &n_params); - if (weight != 0.0) { + _glitz_filter_params_set (&weight, 0.0f, ¶ms, &n_params); + if (weight != 0.0f) { vec = &vecs[surface->filter_params->id++]; vec->v[0] = (i - cx) * tx; vec->v[1] = (cy - j) * ty; vec->v[2] = weight; + vec->v[3] = 0.0f; sum += weight; } } } /* normalize */ - if (sum != 0.0) - sum = 1.0 / sum; + if (sum != 0.0f) + sum = 1.0f / sum; for (i = 0; i < surface->filter_params->id; i++) vecs[i].v[2] *= sum; } break; case GLITZ_FILTER_GAUSSIAN: { - double radius, sigma, alpha, scale, xy_scale, sum, tx, ty; + glitz_float_t radius, sigma, alpha, scale, xy_scale, sum, tx, ty; int half_size, x, y; - _glitz_filter_params_set (&radius, 1.0, ¶ms, &n_params); - glitz_clamp_value (&radius, 0.0, 1024.0); + _glitz_filter_params_set (&radius, 1.0f, ¶ms, &n_params); + glitz_clamp_value (&radius, 0.0f, 1024.0f); - _glitz_filter_params_set (&sigma, radius / 2.0, ¶ms, &n_params); - glitz_clamp_value (&sigma, 0.0, 1024.0); + _glitz_filter_params_set (&sigma, radius / 2.0f, ¶ms, &n_params); + glitz_clamp_value (&sigma, 0.0f, 1024.0f); _glitz_filter_params_set (&alpha, radius, ¶ms, &n_params); - glitz_clamp_value (&alpha, 0.0, 1024.0); + glitz_clamp_value (&alpha, 0.0f, 1024.0f); - scale = 1.0 / (2.0 * GLITZ_PI * sigma * sigma); - half_size = (int) (alpha * radius) / 2; + scale = 1.0f / (2.0f * GLITZ_PI * sigma * sigma); + half_size = alpha + 0.5f; if (half_size == 0) half_size = 1; size = half_size * 2 + 1; - xy_scale = 2.0 * radius / size; - + xy_scale = 2.0f * radius / size; + if (_glitz_filter_params_ensure (&surface->filter_params, size * size)) return GLITZ_STATUS_NO_MEMORY; @@ -195,33 +180,33 @@ glitz_filter_set_params (glitz_surface_t *surface, tx = surface->texture.texcoord_width / surface->texture.width; ty = surface->texture.texcoord_height / surface->texture.height; - sum = 0.0; + sum = 0.0f; for (x = 0; x < size; x++) { glitz_vec4_t *vec; - double fx, fy; - double amp; + glitz_float_t fx, fy, amp; fx = xy_scale * (x - half_size); for (y = 0; y < size; y++) { fy = xy_scale * (y - half_size); - amp = scale * exp ((-1.0 * (fx * fx + fy * fy)) / - (2.0 * sigma * sigma)); + amp = scale * exp ((-1.0f * (fx * fx + fy * fy)) / + (2.0f * sigma * sigma)); - if (amp > 0.0) { + if (amp > 0.0f) { vec = &vecs[surface->filter_params->id++]; vec->v[0] = fx * tx; vec->v[1] = fy * ty; vec->v[2] = amp; + vec->v[3] = 0.0f; sum += amp; } } } /* normalize */ - if (sum != 0.0) - sum = 1.0 / sum; + if (sum != 0.0f) + sum = 1.0f / sum; for (i = 0; i < surface->filter_params->id; i++) vecs[i].v[2] *= sum; @@ -239,59 +224,71 @@ glitz_filter_set_params (glitz_surface_t *surface, if (size < 2) size = 2; - if (_glitz_filter_params_ensure (&surface->filter_params, size)) + if (_glitz_filter_params_ensure (&surface->filter_params, size + 1)) return GLITZ_STATUS_NO_MEMORY; + + vecs = surface->filter_params->vectors; if (filter == GLITZ_FILTER_LINEAR_GRADIENT) { - _glitz_filter_params_set (&surface->filter_params->u.linear.start.x, - 0.0, ¶ms, &n_params); - _glitz_filter_params_set (&surface->filter_params->u.linear.start.y, - 0.0, ¶ms, &n_params); - _glitz_filter_params_set (&surface->filter_params->u.linear.stop.x, - 1.0, ¶ms, &n_params); - _glitz_filter_params_set (&surface->filter_params->u.linear.stop.y, - 0.0, ¶ms, &n_params); + glitz_float_t length, angle, dh, dv; + glitz_point_t start, stop; + + _glitz_filter_params_set (&start.x, 0.0f, ¶ms, &n_params); + _glitz_filter_params_set (&start.y, 0.0f, ¶ms, &n_params); + _glitz_filter_params_set (&stop.x, 1.0f, ¶ms, &n_params); + _glitz_filter_params_set (&stop.y, 0.0f, ¶ms, &n_params); + + dh = stop.x - start.x; + dv = stop.y - start.y; + + length = sqrt (dh * dh + dv * dv); + + angle = -atan2 (dv, dh); + + vecs->v[2] = cos (angle); + vecs->v[3] = -sin (angle); + + vecs->v[0] = vecs->v[2] * start.x; + vecs->v[0] += vecs->v[3] * start.y; + + vecs->v[1] = (length)? 1.0f / length: 2147483647.0f; } else { - double r0, r1; + glitz_float_t r0, r1; + + _glitz_filter_params_set (&vecs->v[0], 0.5f, ¶ms, &n_params); + _glitz_filter_params_set (&vecs->v[1], 0.5f, ¶ms, &n_params); + _glitz_filter_params_set (&r0, 0.0f, ¶ms, &n_params); + _glitz_filter_params_set (&r1, 0.5f, ¶ms, &n_params); + + glitz_clamp_value (&r0, 0.0f, r1); - if (_glitz_filter_params_ensure (&surface->filter_params, size)) - return GLITZ_STATUS_NO_MEMORY; - - _glitz_filter_params_set (&surface->filter_params->u.radial.center.x, - 0.5, ¶ms, &n_params); - _glitz_filter_params_set (&surface->filter_params->u.radial.center.y, - 0.5, ¶ms, &n_params); - _glitz_filter_params_set (&r0, 0.0, ¶ms, &n_params); - _glitz_filter_params_set (&r1, 0.5, ¶ms, &n_params); - glitz_clamp_value (&r0, 0.0, r1); - surface->filter_params->u.radial.radius_base = r0; + vecs->v[2] = r0; if (r1 != r0) - surface->filter_params->u.radial.radius_scale = 1.0 / (r1 - r0); + vecs->v[3] = 1.0f / (r1 - r0); else - surface->filter_params->u.radial.radius_scale = 2147483647.0; + vecs->v[3] = 2147483647.0f; } - vecs = surface->filter_params->vectors; + vecs++; surface->filter_params->id = size; for (i = 0; i < size; i++) { - double x_default, y_default, o_default; + glitz_float_t x_default, y_default, o_default; - o_default = i / (double) (size - 1); - x_default = 0.5 + (surface->width * i) / (double) size; - y_default = 0.5 + (surface->height * i) / (double) size; + o_default = i / (glitz_float_t) (size - 1); + x_default = 0.5f + (surface->width * i) / (glitz_float_t) size; + y_default = 0.5f + (surface->height * i) / (glitz_float_t) size; _glitz_filter_params_set (&vecs[i].v[2], o_default, ¶ms, &n_params); _glitz_filter_params_set (&vecs[i].v[0], x_default, ¶ms, &n_params); _glitz_filter_params_set (&vecs[i].v[1], y_default, ¶ms, &n_params); - glitz_clamp_value (&vecs[i].v[2], 0.0, 1.0); - glitz_clamp_value (&vecs[i].v[0], 0.5, surface->width - 0.5); - glitz_clamp_value (&vecs[i].v[1], 0.5, surface->height - 0.5); - - glitz_texture_tex_coord (&surface->texture, - vecs[i].v[0], vecs[i].v[1], - &vecs[i].v[0], &vecs[i].v[1]); + glitz_clamp_value (&vecs[i].v[2], 0.0f, 1.0f); + glitz_clamp_value (&vecs[i].v[0], 0.5f, surface->width - 0.5f); + glitz_clamp_value (&vecs[i].v[1], 0.5f, surface->height - 0.5f); + + vecs[i].v[0] *= surface->texture.texcoord_width_unit; + vecs[i].v[1] *= surface->texture.texcoord_height_unit; vecs[i].v[1] = surface->texture.texcoord_height - vecs[i].v[1]; vecs[i].v[3] = i; @@ -299,20 +296,20 @@ glitz_filter_set_params (glitz_surface_t *surface, /* sort color stops in ascending order */ qsort (vecs, surface->filter_params->id, sizeof (glitz_vec4_t), - _glitz_color_stop_compare); + _glitz_color_stop_compare); for (i = 0; i < size; i++) { - double diff; + glitz_float_t diff; if ((i + 1) == size) - diff = 1.0 - vecs[i].v[2]; + diff = 1.0f - vecs[i].v[2]; else diff = vecs[i + 1].v[2] - vecs[i].v[2]; - if (diff != 0.0) - vecs[i].v[3] = 1.0 / diff; + if (diff != 0.0f) + vecs[i].v[3] = 1.0f / diff; else - vecs[i].v[3] = 2147483647.0; /* should be DBL_MAX, but this will do */ + vecs[i].v[3] = 2147483647.0f; /* should be FLT_MAX, but this will do */ } break; case GLITZ_FILTER_BILINEAR: @@ -335,13 +332,6 @@ glitz_filter_params_destroy (glitz_filter_params_t *params) } glitz_gl_uint_t -glitz_filter_get_vertex_program (glitz_surface_t *surface, - glitz_composite_op_t *op) -{ - return glitz_get_vertex_program (op); -} - -glitz_gl_uint_t glitz_filter_get_fragment_program (glitz_surface_t *surface, glitz_composite_op_t *op) { @@ -360,7 +350,7 @@ glitz_filter_set_type (glitz_surface_t *surface, surface->filter_params->fp_type = GLITZ_FP_CONVOLUTION; break; case GLITZ_FILTER_LINEAR_GRADIENT: - if (surface->hint_mask & GLITZ_INT_HINT_REPEAT_MASK) { + if (surface->flags & GLITZ_FLAG_REPEAT_MASK) { if (SURFACE_MIRRORED (surface)) surface->filter_params->fp_type = GLITZ_FP_LINEAR_GRADIENT_REFLECT; else @@ -371,7 +361,7 @@ glitz_filter_set_type (glitz_surface_t *surface, surface->filter_params->fp_type = GLITZ_FP_LINEAR_GRADIENT_TRANSPARENT; break; case GLITZ_FILTER_RADIAL_GRADIENT: - if (surface->hint_mask & GLITZ_INT_HINT_REPEAT_MASK) { + if (surface->flags & GLITZ_FLAG_REPEAT_MASK) { if (SURFACE_MIRRORED (surface)) surface->filter_params->fp_type = GLITZ_FP_RADIAL_GRADIENT_REFLECT; else @@ -394,100 +384,52 @@ glitz_filter_enable (glitz_surface_t *surface, glitz_gl_proc_address_list_t *gl = op->gl; int i; - gl->enable (GLITZ_GL_VERTEX_PROGRAM); - gl->bind_program (GLITZ_GL_VERTEX_PROGRAM, op->vp); - gl->enable (GLITZ_GL_FRAGMENT_PROGRAM); gl->bind_program (GLITZ_GL_FRAGMENT_PROGRAM, op->fp); switch (surface->filter) { case GLITZ_FILTER_GAUSSIAN: case GLITZ_FILTER_CONVOLUTION: - for (i = 0; i < surface->filter_params->id; i++) { - glitz_vec4_t *vec; - - vec = &surface->filter_params->vectors[i]; - - gl->program_local_param_4d (GLITZ_GL_FRAGMENT_PROGRAM, i, - vec->v[0], vec->v[1], vec->v[2], 0.0); - } + for (i = 0; i < surface->filter_params->id; i++) + gl->program_local_param_4fv (GLITZ_GL_FRAGMENT_PROGRAM, i, + surface->filter_params->vectors[i].v); break; - case GLITZ_FILTER_LINEAR_GRADIENT: { - glitz_linear_gradient_filter_t *linear = &surface->filter_params->u.linear; - double length, angle, start, cos_angle, sin_angle, dw, dh; + case GLITZ_FILTER_LINEAR_GRADIENT: + case GLITZ_FILTER_RADIAL_GRADIENT: { int j, fp_type = surface->filter_params->fp_type; + glitz_vec4_t *vec; + + vec = surface->filter_params->vectors; - dw = linear->stop.x - linear->start.x; - dh = linear->stop.y - linear->start.y; - - length = sqrt (dw * dw + dh * dh); - - angle = -atan2 (dh, dw); + gl->program_local_param_4fv (GLITZ_GL_FRAGMENT_PROGRAM, 0, vec->v); - cos_angle = cos (angle); - sin_angle = sin (angle); - - start = cos_angle * linear->start.x; - start += -sin_angle * linear->start.y; + vec++; - gl->program_local_param_4d (GLITZ_GL_FRAGMENT_PROGRAM, 0, start, - (length)? 1.0 / length: INT_MAX, - cos_angle, -sin_angle); + if (fp_type == GLITZ_FP_LINEAR_GRADIENT_TRANSPARENT || + fp_type == GLITZ_FP_RADIAL_GRADIENT_TRANSPARENT) { + glitz_vec4_t v; - if (fp_type == GLITZ_FP_LINEAR_GRADIENT_TRANSPARENT) { - glitz_vec4_t *vec = surface->filter_params->vectors; + v.v[0] = v.v[1] = -1.0f; + v.v[2] = 0.0f; + v.v[3] = (vec->v[3])? 1.0f / vec->v[3]: 1.0f; - gl->program_local_param_4d (GLITZ_GL_FRAGMENT_PROGRAM, 1, - -1.0, -1.0, 0.0, - (vec->v[3])? 1.0 / vec->v[3]: 1.0); + gl->program_local_param_4fv (GLITZ_GL_FRAGMENT_PROGRAM, 1, v.v); j = 2; } else j = 1; - for (i = 0; i < surface->filter_params->id; i++) { - glitz_vec4_t *vec; - - vec = &surface->filter_params->vectors[i]; - - gl->program_local_param_4d (GLITZ_GL_FRAGMENT_PROGRAM, i + j, - vec->v[0], vec->v[1], vec->v[2], vec->v[3]); - } - - if (fp_type == GLITZ_FP_LINEAR_GRADIENT_TRANSPARENT) - gl->program_local_param_4d (GLITZ_GL_FRAGMENT_PROGRAM, i + j, - -1.0, -1.0, 1.0, 1.0); - - } break; - case GLITZ_FILTER_RADIAL_GRADIENT: { - glitz_radial_gradient_filter_t *radial = &surface->filter_params->u.radial; - int j, fp_type = surface->filter_params->fp_type; + for (i = 0; i < surface->filter_params->id; i++, vec++) + gl->program_local_param_4fv (GLITZ_GL_FRAGMENT_PROGRAM, i + j, vec->v); - gl->program_local_param_4d (GLITZ_GL_FRAGMENT_PROGRAM, 0, - radial->center.x, radial->center.y, - radial->radius_base, radial->radius_scale); + if (fp_type == GLITZ_FP_LINEAR_GRADIENT_TRANSPARENT || + fp_type == GLITZ_FP_RADIAL_GRADIENT_TRANSPARENT) { + glitz_vec4_t v; - if (fp_type == GLITZ_FP_RADIAL_GRADIENT_TRANSPARENT) { - glitz_vec4_t *vec = surface->filter_params->vectors; + v.v[0] = v.v[1] = -1.0f; + v.v[2] = v.v[3] = 1.0f; - gl->program_local_param_4d (GLITZ_GL_FRAGMENT_PROGRAM, 1, - -1.0, -1.0, 0.0, - (vec->v[3]) ? 1.0 / vec->v[3]: 1.0); - j = 2; - } else - j = 1; - - for (i = 0; i < surface->filter_params->id; i++) { - glitz_vec4_t *vec; - - vec = &surface->filter_params->vectors[i]; - - gl->program_local_param_4d (GLITZ_GL_FRAGMENT_PROGRAM, i + j, - vec->v[0], vec->v[1], vec->v[2], vec->v[3]); - } - - if (fp_type == GLITZ_FP_RADIAL_GRADIENT_TRANSPARENT) - gl->program_local_param_4d (GLITZ_GL_FRAGMENT_PROGRAM, i + j, - -1.0, -1.0, 1.0, 1.0); + gl->program_local_param_4fv (GLITZ_GL_FRAGMENT_PROGRAM, i + j, v.v); + } } break; case GLITZ_FILTER_BILINEAR: case GLITZ_FILTER_NEAREST: diff --git a/src/glitz_geometry.c b/src/glitz_geometry.c new file mode 100644 index 0000000..9205ef3 --- /dev/null +++ b/src/glitz_geometry.c @@ -0,0 +1,268 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman <c99drn@cs.umu.se> + */ + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "glitzint.h" + +/* This is supposed to be 8x, 4x and 2x rotated grid multi-sample + patterns. I'm not sure they're actually correct. */ +static glitz_sample_offset_t _8x_multi_sample_offsets[] = { + { -0.375f, -0.375f }, + { -0.125f, -0.125f }, + { 0.375f, -0.375f }, + { 0.125f, -0.125f }, + { 0.375f, 0.375f }, + { 0.125f, 0.125f }, + { -0.375f, 0.375f }, + { -0.125f, 0.125f } +}; + +static unsigned short _8x_multi_sample_weights[] = { + 0x2000, 0x4000, 0x6000, 0x8000, 0xa000, 0xbfff, 0xdfff, 0xffff +}; + +static glitz_sample_info_t _8x_multi_sample = { + _8x_multi_sample_offsets, + _8x_multi_sample_weights, + 8 +}; + +static glitz_sample_offset_t _4x_multi_sample_offsets[] = { + { -0.125f, -0.375f }, + { 0.375f, -0.125f }, + { 0.125f, 0.375f }, + { -0.375f, 0.125f } +}; + +static unsigned short _4x_multi_sample_weights[] = { + 0x4000, 0x8000, 0xbfff, 0xffff +}; + +static glitz_sample_info_t _4x_multi_sample = { + _4x_multi_sample_offsets, + _4x_multi_sample_weights, + 4 +}; + +static glitz_sample_offset_t _2x_multi_sample_offsets[] = { + { -0.24f, -0.24f }, + { 0.24f, 0.24f } +}; + +static unsigned short _2x_multi_sample_weights[] = { + 0x8000, 0xffff +}; + +static glitz_sample_info_t _2x_multi_sample = { + _2x_multi_sample_offsets, + _2x_multi_sample_weights, + 2 +}; + +static glitz_sample_offset_t _1x_sample_offsets[] = { + { 0.0f, 0.0f } +}; + +static unsigned short _1x_sample_weights[] = { + 0xffff +}; + +static glitz_sample_info_t _1x_sample = { + _1x_sample_offsets, + _1x_sample_weights, + 1 +}; + +void +glitz_set_geometry (glitz_surface_t *dst, + int x_dst, + int y_dst, + glitz_geometry_format_t *format, + glitz_buffer_t *buffer) +{ + if (dst->geometry.buffer) { + glitz_buffer_destroy (dst->geometry.buffer); + dst->geometry.buffer = NULL; + } + + if (buffer) { + dst->geometry.buffer = buffer; + glitz_buffer_reference (buffer); + + dst->geometry.x_offset = x_dst; + dst->geometry.y_offset = y_dst; + + switch (format->primitive) { + case GLITZ_GEOMETRY_PRIMITIVE_TRIANGLES: + dst->geometry.primitive = GLITZ_GL_TRIANGLES; + break; + case GLITZ_GEOMETRY_PRIMITIVE_TRIANGLE_STRIP: + dst->geometry.primitive = GLITZ_GL_TRIANGLE_STRIP; + break; + case GLITZ_GEOMETRY_PRIMITIVE_TRIANGLE_FAN: + dst->geometry.primitive = GLITZ_GL_TRIANGLE_FAN; + break; + case GLITZ_GEOMETRY_PRIMITIVE_QUADS: + dst->geometry.primitive = GLITZ_GL_QUADS; + break; + case GLITZ_GEOMETRY_PRIMITIVE_QUAD_STRIP: + dst->geometry.primitive = GLITZ_GL_QUAD_STRIP; + break; + default: + dst->geometry.primitive = GLITZ_GL_POLYGON; + break; + } + + switch (format->type) { + case GLITZ_DATA_TYPE_SHORT: + dst->geometry.type = GLITZ_GL_SHORT; + break; + case GLITZ_DATA_TYPE_INT: + dst->geometry.type = GLITZ_GL_INT; + break; + case GLITZ_DATA_TYPE_DOUBLE: + dst->geometry.type = GLITZ_GL_DOUBLE; + break; + default: + dst->geometry.type = GLITZ_GL_FLOAT; + break; + } + + dst->geometry.first = format->first; + dst->geometry.count = format->count; + + if (dst->format->multisample.samples > 1) { + if (format->edge_hint != GLITZ_GEOMETRY_EDGE_HINT_SHARP) { + dst->flags |= GLITZ_FLAG_MULTISAMPLE_MASK; + + if (format->edge_hint != GLITZ_GEOMETRY_EDGE_HINT_FAST_SMOOTH) + dst->flags |= GLITZ_FLAG_NICEST_MULTISAMPLE_MASK; + else + dst->flags &= ~GLITZ_FLAG_NICEST_MULTISAMPLE_MASK; + + dst->update_mask |= GLITZ_UPDATE_MULTISAMPLE_MASK; + } else { + dst->flags &= ~GLITZ_FLAG_MULTISAMPLE_MASK; + dst->update_mask |= GLITZ_UPDATE_MULTISAMPLE_MASK; + } + } else { + if (format->mode == GLITZ_GEOMETRY_MODE_INDIRECT) { + switch (format->edge_hint) { + case GLITZ_GEOMETRY_EDGE_HINT_BEST_SMOOTH: + if (dst->format->stencil_size >= 4) { + dst->indirect = &_8x_multi_sample; + break; + } + /* fall-through */ + case GLITZ_GEOMETRY_EDGE_HINT_GOOD_SMOOTH: + if (dst->format->stencil_size >= 3) { + dst->indirect = &_4x_multi_sample; + break; + } + /* fall-through */ + case GLITZ_GEOMETRY_EDGE_HINT_FAST_SMOOTH: + if (dst->format->stencil_size >= 2) { + dst->indirect = &_2x_multi_sample; + break; + } + /* fall-through */ + case GLITZ_GEOMETRY_EDGE_HINT_SHARP: + default: + dst->indirect = &_1x_sample; + break; + } + } else + dst->indirect = NULL; + } + } else { + if (dst->format->multisample.samples > 1) { + dst->flags &= ~GLITZ_FLAG_MULTISAMPLE_MASK; + dst->update_mask |= GLITZ_UPDATE_MULTISAMPLE_MASK; + } else + dst->indirect = NULL; + } +} +slim_hidden_def(glitz_set_geometry); + +void +glitz_geometry_enable_default (glitz_gl_proc_address_list_t *gl, + glitz_surface_t *dst) +{ + if (dst->backend->feature_mask & GLITZ_FEATURE_VERTEX_BUFFER_OBJECT_MASK) { + if (!dst->geometry.default_name) { + gl->gen_buffers (1, &dst->geometry.default_name); + if (dst->geometry.default_name) { + gl->bind_buffer (GLITZ_GL_ARRAY_BUFFER, + dst->geometry.default_name); + gl->buffer_data (GLITZ_GL_ARRAY_BUFFER, sizeof (dst->geometry.data), + dst->geometry.data, GLITZ_GL_STATIC_DRAW); + } + } else + gl->bind_buffer (GLITZ_GL_ARRAY_BUFFER, + dst->geometry.default_name); + + gl->vertex_pointer (2, GLITZ_GL_FLOAT, 0, NULL); + } else + gl->vertex_pointer (2, GLITZ_GL_FLOAT, 0, dst->geometry.data); +} + +void +glitz_geometry_enable (glitz_gl_proc_address_list_t *gl, + glitz_surface_t *dst, + glitz_gl_enum_t *primitive, + glitz_gl_int_t *first, + glitz_gl_sizei_t *count) +{ + if (dst->geometry.buffer) { + void *ptr; + + ptr = glitz_buffer_bind (dst->geometry.buffer, GLITZ_GL_ARRAY_BUFFER); + + gl->vertex_pointer (2, dst->geometry.type, 0, ptr); + + if (dst->geometry.x_offset || dst->geometry.y_offset) + gl->translate_f (dst->geometry.x_offset, dst->geometry.y_offset, 0.0f); + + *primitive = dst->geometry.primitive; + *first = dst->geometry.first; + *count = dst->geometry.count; + } else { + glitz_geometry_enable_default (gl, dst); + *primitive = GLITZ_GL_QUADS; + *first = 0; + *count = 4; + } +} + +void +glitz_geometry_disable (glitz_gl_proc_address_list_t *gl, + glitz_surface_t *dst) +{ + if (dst->backend->feature_mask & GLITZ_FEATURE_VERTEX_BUFFER_OBJECT_MASK) + gl->bind_buffer (GLITZ_GL_ARRAY_BUFFER, 0); +} diff --git a/src/glitz_gl.h b/src/glitz_gl.h index bf24d09..965f4d6 100644 --- a/src/glitz_gl.h +++ b/src/glitz_gl.h @@ -43,6 +43,7 @@ typedef unsigned int glitz_gl_bitfield_t; typedef double glitz_gl_clampd_t; typedef float glitz_gl_clampf_t; typedef unsigned char glitz_gl_ubyte_t; +typedef ptrdiff_t glitz_gl_intptr_t; typedef ptrdiff_t glitz_gl_sizeiptr_t; @@ -66,10 +67,19 @@ typedef ptrdiff_t glitz_gl_sizeiptr_t; #define GLITZ_GL_MODELVIEW 0x1700 #define GLITZ_GL_PROJECTION 0x1701 +#define GLITZ_GL_SHORT 0x1402 +#define GLITZ_GL_INT 0x1404 +#define GLITZ_GL_FLOAT 0x1406 +#define GLITZ_GL_DOUBLE 0x140A + #define GLITZ_GL_TRIANGLES 0x0004 #define GLITZ_GL_TRIANGLE_STRIP 0x0005 #define GLITZ_GL_TRIANGLE_FAN 0x0006 #define GLITZ_GL_QUADS 0x0007 +#define GLITZ_GL_QUAD_STRIP 0x0008 +#define GLITZ_GL_POLYGON 0x0009 + +#define GLITZ_GL_VERTEX_ARRAY 0x8074 #define GLITZ_GL_FILL 0x1B02 #define GLITZ_GL_FRONT 0x0404 @@ -89,6 +99,14 @@ typedef ptrdiff_t glitz_gl_sizeiptr_t; #define GLITZ_GL_TEXTURE_MAG_FILTER 0x2800 #define GLITZ_GL_TEXTURE_MIN_FILTER 0x2801 #define GLITZ_GL_TEXTURE_ENV_COLOR 0x2201 +#define GLITZ_GL_TEXTURE_GEN_S 0x0C60 +#define GLITZ_GL_TEXTURE_GEN_T 0x0C61 +#define GLITZ_GL_TEXTURE_GEN_MODE 0x2500 +#define GLITZ_GL_EYE_LINEAR 0x2400 +#define GLITZ_GL_EYE_PLANE 0x2502 +#define GLITZ_GL_S 0x2000 +#define GLITZ_GL_T 0x2001 + #define GLITZ_GL_MODULATE 0x2100 #define GLITZ_GL_NEAREST 0x2600 #define GLITZ_GL_LINEAR 0x2601 @@ -215,7 +233,6 @@ typedef ptrdiff_t glitz_gl_sizeiptr_t; #define GLITZ_GL_MULTISAMPLE_FILTER_HINT 0x8534 -#define GLITZ_GL_VERTEX_PROGRAM 0x8620 #define GLITZ_GL_FRAGMENT_PROGRAM 0x8804 #define GLITZ_GL_PROGRAM_STRING 0x8628 #define GLITZ_GL_PROGRAM_FORMAT_ASCII 0x8875 @@ -223,6 +240,7 @@ typedef ptrdiff_t glitz_gl_sizeiptr_t; #define GLITZ_GL_PROGRAM_UNDER_NATIVE_LIMITS 0x88B6 #define GLITZ_GL_PROGRAM_NATIVE_INSTRUCTIONS 0x88A2 +#define GLITZ_GL_ARRAY_BUFFER 0x8892 #define GLITZ_GL_PIXEL_PACK_BUFFER 0x88EB #define GLITZ_GL_PIXEL_UNPACK_BUFFER 0x88EC @@ -245,30 +263,34 @@ typedef glitz_gl_void_t (* glitz_gl_enable_t) (glitz_gl_enum_t cap); typedef glitz_gl_void_t (* glitz_gl_disable_t) (glitz_gl_enum_t cap); -typedef glitz_gl_void_t (* glitz_gl_begin_t) - (glitz_gl_enum_t mode); -typedef glitz_gl_void_t (* glitz_gl_end_t) - (glitz_gl_void_t); -typedef glitz_gl_void_t (* glitz_gl_vertex_2i_t) - (glitz_gl_int_t x, glitz_gl_int_t y); -typedef glitz_gl_void_t (* glitz_gl_vertex_2d_t) - (glitz_gl_double_t x, glitz_gl_double_t y); +typedef glitz_gl_void_t (* glitz_gl_enable_client_state_t) + (glitz_gl_enum_t cap); +typedef glitz_gl_void_t (* glitz_gl_disable_client_state_t) + (glitz_gl_enum_t cap); +typedef glitz_gl_void_t (* glitz_gl_vertex_pointer_t) + (glitz_gl_int_t size, glitz_gl_enum_t type, glitz_gl_sizei_t stride, + const glitz_gl_void_t *ptr); +typedef glitz_gl_void_t (* glitz_gl_draw_arrays_t) + (glitz_gl_enum_t mode, glitz_gl_int_t first, glitz_gl_sizei_t count); typedef glitz_gl_void_t (* glitz_gl_tex_env_f_t) (glitz_gl_enum_t target, glitz_gl_enum_t pname, glitz_gl_float_t param); typedef glitz_gl_void_t (* glitz_gl_tex_env_fv_t) (glitz_gl_enum_t target, glitz_gl_enum_t pname, const glitz_gl_float_t *params); -typedef glitz_gl_void_t (* glitz_gl_tex_coord_2d_t) - (glitz_gl_double_t s, glitz_gl_double_t t); +typedef glitz_gl_void_t (* glitz_gl_tex_gen_i_t) + (glitz_gl_enum_t coord, glitz_gl_enum_t pname, glitz_gl_int_t param); +typedef glitz_gl_void_t (* glitz_gl_tex_gen_fv_t) + (glitz_gl_enum_t coord, glitz_gl_enum_t pname, + const glitz_gl_float_t *params); typedef glitz_gl_void_t (* glitz_gl_scissor_t) (glitz_gl_int_t x, glitz_gl_int_t y, glitz_gl_sizei_t width, glitz_gl_sizei_t height); typedef glitz_gl_void_t (* glitz_gl_color_4us_t) (glitz_gl_ushort_t red, glitz_gl_ushort_t green, glitz_gl_ushort_t blue, glitz_gl_ushort_t alpha); -typedef glitz_gl_void_t (* glitz_gl_color_4d_t) - (glitz_gl_double_t red, glitz_gl_double_t green, glitz_gl_double_t blue, - glitz_gl_double_t alpha); +typedef glitz_gl_void_t (* glitz_gl_color_4f_t) + (glitz_gl_float_t red, glitz_gl_float_t green, glitz_gl_float_t blue, + glitz_gl_float_t alpha); typedef glitz_gl_void_t (* glitz_gl_blend_func_t) (glitz_gl_enum_t sfactor, glitz_gl_enum_t dfactor); typedef glitz_gl_void_t (* glitz_gl_clear_t) @@ -294,17 +316,15 @@ typedef glitz_gl_void_t (* glitz_gl_pop_matrix_t) (glitz_gl_void_t); typedef glitz_gl_void_t (* glitz_gl_load_identity_t) (glitz_gl_void_t); -typedef glitz_gl_void_t (* glitz_gl_load_matrix_d_t) - (const glitz_gl_double_t *m); -typedef glitz_gl_void_t (* glitz_gl_mult_matrix_d_t) - (const glitz_gl_double_t *m); +typedef glitz_gl_void_t (* glitz_gl_load_matrix_f_t) + (const glitz_gl_float_t *m); typedef glitz_gl_void_t (* glitz_gl_depth_range_t) (glitz_gl_clampd_t near_val, glitz_gl_clampd_t far_val); typedef glitz_gl_void_t (* glitz_gl_viewport_t) (glitz_gl_int_t x, glitz_gl_int_t y, glitz_gl_sizei_t width, glitz_gl_sizei_t height); -typedef glitz_gl_void_t (* glitz_gl_raster_pos_2d_t) - (glitz_gl_double_t x, glitz_gl_double_t y); +typedef glitz_gl_void_t (* glitz_gl_raster_pos_2f_t) + (glitz_gl_float_t x, glitz_gl_float_t y); typedef glitz_gl_void_t (* glitz_gl_bitmap_t) (glitz_gl_sizei_t width, glitz_gl_sizei_t height, glitz_gl_float_t xorig, glitz_gl_float_t yorig, @@ -328,10 +348,10 @@ typedef glitz_gl_void_t (* glitz_gl_ortho_t) (glitz_gl_double_t left, glitz_gl_double_t right, glitz_gl_double_t bottom, glitz_gl_double_t top, glitz_gl_double_t near_val, glitz_gl_double_t far_val); -typedef glitz_gl_void_t (* glitz_gl_scale_d_t) - (glitz_gl_double_t x, glitz_gl_double_t y, glitz_gl_double_t z); -typedef glitz_gl_void_t (* glitz_gl_translate_d_t) - (glitz_gl_double_t x, glitz_gl_double_t y, glitz_gl_double_t z); +typedef glitz_gl_void_t (* glitz_gl_scale_f_t) + (glitz_gl_float_t x, glitz_gl_float_t y, glitz_gl_float_t z); +typedef glitz_gl_void_t (* glitz_gl_translate_f_t) + (glitz_gl_float_t x, glitz_gl_float_t y, glitz_gl_float_t z); typedef glitz_gl_void_t (* glitz_gl_hint_t) (glitz_gl_enum_t target, glitz_gl_enum_t mode); typedef glitz_gl_void_t (* glitz_gl_depth_mask_t) @@ -366,12 +386,6 @@ typedef glitz_gl_void_t (* glitz_gl_delete_textures_t) (glitz_gl_sizei_t n, const glitz_gl_uint_t *textures); typedef glitz_gl_void_t (* glitz_gl_bind_texture_t) (glitz_gl_enum_t target, glitz_gl_uint_t texture); -typedef glitz_gl_void_t (* glitz_gl_tex_image_1d_t) - (glitz_gl_enum_t target, glitz_gl_int_t level, - glitz_gl_int_t internal_format, - glitz_gl_sizei_t width, glitz_gl_int_t border, - glitz_gl_enum_t format, glitz_gl_enum_t type, - const glitz_gl_void_t *pixels); typedef glitz_gl_void_t (* glitz_gl_tex_image_2d_t) (glitz_gl_enum_t target, glitz_gl_int_t level, glitz_gl_int_t internal_format, @@ -394,8 +408,6 @@ typedef glitz_gl_void_t (* glitz_gl_get_pointer_v_t) (glitz_gl_enum_t pname, glitz_gl_void_t **params); typedef glitz_gl_void_t (* glitz_gl_active_texture_t) (glitz_gl_enum_t); -typedef glitz_gl_void_t (* glitz_gl_multi_tex_coord_2d_t) - (glitz_gl_enum_t, glitz_gl_double_t, glitz_gl_double_t); typedef glitz_gl_void_t (* glitz_gl_gen_programs_t) (glitz_gl_sizei_t, glitz_gl_uint_t *); typedef glitz_gl_void_t (* glitz_gl_delete_programs_t) @@ -405,10 +417,8 @@ typedef glitz_gl_void_t (* glitz_gl_program_string_t) const glitz_gl_void_t *); typedef glitz_gl_void_t (* glitz_gl_bind_program_t) (glitz_gl_enum_t, glitz_gl_uint_t); -typedef glitz_gl_void_t (* glitz_gl_program_local_param_4d_t) - (glitz_gl_enum_t, glitz_gl_uint_t, - glitz_gl_double_t, glitz_gl_double_t, - glitz_gl_double_t, glitz_gl_double_t); +typedef glitz_gl_void_t (* glitz_gl_program_local_param_4fv_t) + (glitz_gl_enum_t, glitz_gl_uint_t, const glitz_gl_float_t *); typedef glitz_gl_void_t (* glitz_gl_get_program_iv_t) (glitz_gl_enum_t, glitz_gl_enum_t, glitz_gl_uint_t *); typedef glitz_gl_void_t (* glitz_gl_gen_buffers_t) @@ -420,6 +430,12 @@ typedef glitz_gl_void_t (* glitz_gl_bind_buffer_t) typedef glitz_gl_void_t (* glitz_gl_buffer_data_t) (glitz_gl_enum_t, glitz_gl_sizeiptr_t, const glitz_gl_void_t *, glitz_gl_enum_t); +typedef glitz_gl_void_t *(* glitz_gl_buffer_sub_data_t) + (glitz_gl_enum_t, glitz_gl_intptr_t, glitz_gl_sizeiptr_t, + const glitz_gl_void_t *); +typedef glitz_gl_void_t *(* glitz_gl_get_buffer_sub_data_t) + (glitz_gl_enum_t, glitz_gl_intptr_t, glitz_gl_sizeiptr_t, + glitz_gl_void_t *); typedef glitz_gl_void_t *(* glitz_gl_map_buffer_t) (glitz_gl_enum_t, glitz_gl_enum_t); typedef glitz_gl_boolean_t (* glitz_gl_unmap_buffer_t) diff --git a/src/glitz_glx_context.c b/src/glitz_glx_context.c index c50aac0..cb3c798 100644 --- a/src/glitz_glx_context.c +++ b/src/glitz_glx_context.c @@ -33,6 +33,8 @@ #include <stdlib.h> +extern glitz_gl_proc_address_list_t _glitz_glx_gl_proc_address; + static void _glitz_glx_context_create_glx12 (glitz_glx_screen_info_t *screen_info, XID visualid, @@ -177,11 +179,18 @@ glitz_glx_context_get (glitz_glx_screen_info_t *screen_info, screen_info->root_context.context, context); - memcpy (&context->gl, - &screen_info->root_context.gl, + glitz_glx_surface_backend_init (&context->backend); + + memcpy (&context->backend.gl, + &_glitz_glx_gl_proc_address, sizeof (glitz_gl_proc_address_list_t)); + + context->backend.formats = screen_info->formats; + context->backend.n_formats = screen_info->n_formats; + context->backend.program_map = &screen_info->program_map; + context->backend.feature_mask = 0; - context->gl.need_lookup = 1; + context->backend.gl.need_lookup = 1; return context; } @@ -202,52 +211,94 @@ glitz_glx_context_proc_address_lookup (glitz_glx_screen_info_t *screen_info, glitz_glx_thread_info_t *thread_info = screen_info->display_info->thread_info; - context->gl.active_texture = + context->backend.gl.active_texture = (glitz_gl_active_texture_t) glitz_glx_get_proc_address (thread_info, "glActiveTextureARB"); - context->gl.multi_tex_coord_2d = - (glitz_gl_multi_tex_coord_2d_t) - glitz_glx_get_proc_address (thread_info, "glMultiTexCoord2dARB"); - context->gl.gen_programs = + context->backend.gl.gen_programs = (glitz_gl_gen_programs_t) glitz_glx_get_proc_address (thread_info, "glGenProgramsARB"); - context->gl.delete_programs = + context->backend.gl.delete_programs = (glitz_gl_delete_programs_t) glitz_glx_get_proc_address (thread_info, "glDeleteProgramsARB"); - context->gl.program_string = + context->backend.gl.program_string = (glitz_gl_program_string_t) glitz_glx_get_proc_address (thread_info, "glProgramStringARB"); - context->gl.bind_program = + context->backend.gl.bind_program = (glitz_gl_bind_program_t) glitz_glx_get_proc_address (thread_info, "glBindProgramARB"); - context->gl.program_local_param_4d = - (glitz_gl_program_local_param_4d_t) - glitz_glx_get_proc_address (thread_info, "glProgramLocalParameter4dARB"); - context->gl.get_program_iv = + context->backend.gl.program_local_param_4fv = + (glitz_gl_program_local_param_4fv_t) + glitz_glx_get_proc_address (thread_info, "glProgramLocalParameter4fvARB"); + context->backend.gl.get_program_iv = (glitz_gl_get_program_iv_t) glitz_glx_get_proc_address (thread_info, "glGetProgramivARB"); - context->gl.gen_buffers = + context->backend.gl.gen_buffers = (glitz_gl_gen_buffers_t) - glitz_glx_get_proc_address (thread_info, "glGenBuffers"); - context->gl.delete_buffers = + glitz_glx_get_proc_address (thread_info, "glGenBuffersARB"); + context->backend.gl.delete_buffers = (glitz_gl_delete_buffers_t) - glitz_glx_get_proc_address (thread_info, "glDeleteBuffers"); - context->gl.bind_buffer = + glitz_glx_get_proc_address (thread_info, "glDeleteBuffersARB"); + context->backend.gl.bind_buffer = (glitz_gl_bind_buffer_t) - glitz_glx_get_proc_address (thread_info, "glBindBuffer"); - context->gl.buffer_data = + glitz_glx_get_proc_address (thread_info, "glBindBufferARB"); + context->backend.gl.buffer_data = (glitz_gl_buffer_data_t) - glitz_glx_get_proc_address (thread_info, "glBufferData"); - context->gl.map_buffer = + glitz_glx_get_proc_address (thread_info, "glBufferDataARB"); + context->backend.gl.buffer_sub_data = + (glitz_gl_buffer_sub_data_t) + glitz_glx_get_proc_address (thread_info, "glBufferSubDataARB"); + context->backend.gl.get_buffer_sub_data = + (glitz_gl_get_buffer_sub_data_t) + glitz_glx_get_proc_address (thread_info, "glGetBufferSubDataARB"); + context->backend.gl.map_buffer = (glitz_gl_map_buffer_t) - glitz_glx_get_proc_address (thread_info, "glMapBuffer"); - context->gl.unmap_buffer = + glitz_glx_get_proc_address (thread_info, "glMapBufferARB"); + context->backend.gl.unmap_buffer = (glitz_gl_unmap_buffer_t) - glitz_glx_get_proc_address (thread_info, "glUnmapBuffer"); + glitz_glx_get_proc_address (thread_info, "glUnmapBufferARB"); + + context->backend.feature_mask = screen_info->feature_mask; - context->gl.need_lookup = 0; + context->backend.feature_mask &= ~GLITZ_FEATURE_MULTITEXTURE_MASK; + context->backend.feature_mask &= ~GLITZ_FEATURE_COMPONENT_ALPHA_MASK; + context->backend.feature_mask &= ~GLITZ_FEATURE_FRAGMENT_PROGRAM_MASK; + context->backend.feature_mask &= ~GLITZ_FEATURE_VERTEX_BUFFER_OBJECT_MASK; + context->backend.feature_mask &= ~GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK; + + if (context->backend.gl.active_texture) { + context->backend.feature_mask |= GLITZ_FEATURE_MULTITEXTURE_MASK; + + if (screen_info->feature_mask & GLITZ_FEATURE_COMPONENT_ALPHA_MASK) + context->backend.feature_mask |= GLITZ_FEATURE_COMPONENT_ALPHA_MASK; + + if (context->backend.gl.gen_programs && + context->backend.gl.delete_programs && + context->backend.gl.program_string && + context->backend.gl.bind_program && + context->backend.gl.program_local_param_4fv) { + if (screen_info->feature_mask & GLITZ_FEATURE_FRAGMENT_PROGRAM_MASK) + context->backend.feature_mask |= GLITZ_FEATURE_FRAGMENT_PROGRAM_MASK; + } + } + + if (context->backend.gl.gen_buffers && + context->backend.gl.delete_buffers && + context->backend.gl.bind_buffer && + context->backend.gl.buffer_data && + context->backend.gl.buffer_sub_data && + context->backend.gl.get_buffer_sub_data && + context->backend.gl.map_buffer && + context->backend.gl.unmap_buffer) { + if (screen_info->feature_mask & GLITZ_FEATURE_VERTEX_BUFFER_OBJECT_MASK) + context->backend.feature_mask |= GLITZ_FEATURE_VERTEX_BUFFER_OBJECT_MASK; + + if (screen_info->feature_mask & GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK) + context->backend.feature_mask |= GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK; + } + + context->backend.gl.need_lookup = 0; } void @@ -272,7 +323,7 @@ glitz_glx_context_make_current (glitz_glx_surface_t *surface, glXMakeCurrent (surface->screen_info->display_info->display, drawable, context); - if (surface->context->gl.need_lookup) + if (surface->context->backend.gl.need_lookup) glitz_glx_context_proc_address_lookup (surface->screen_info, surface->context); } diff --git a/src/glitz_glx_extension.c b/src/glitz_glx_extension.c index 7ed0102..7082bd6 100644 --- a/src/glitz_glx_extension.c +++ b/src/glitz_glx_extension.c @@ -50,8 +50,9 @@ static glitz_extension_map client_glx_extensions[] = { { "GL_NV_multisample_filter_hint", GLITZ_GLX_FEATURE_MULTISAMPLE_FILTER_HINT_MASK }, { "GL_ARB_multitexture", GLITZ_GLX_FEATURE_MULTITEXTURE_MASK }, - { "GL_ARB_vertex_program", GLITZ_GLX_FEATURE_VERTEX_PROGRAM_MASK }, { "GL_ARB_fragment_program", GLITZ_GLX_FEATURE_FRAGMENT_PROGRAM_MASK }, + { "GL_ARB_vertex_buffer_object", + GLITZ_GLX_FEATURE_VERTEX_BUFFER_OBJECT_MASK }, { "GL_EXT_pixel_buffer_object", GLITZ_GLX_FEATURE_PIXEL_BUFFER_OBJECT_MASK }, { NULL, 0 } }; @@ -92,15 +93,13 @@ glitz_glx_query_extensions (glitz_glx_screen_info_t *screen_info) glx->get_fbconfig_attrib && glx->get_visual_from_fbconfig && glx->create_pbuffer && - glx->destroy_pbuffer) { - screen_info->feature_mask |= GLITZ_FEATURE_OFFSCREEN_DRAWING_MASK; + glx->destroy_pbuffer) screen_info->glx_feature_mask |= GLITZ_GLX_FEATURE_GLX13_MASK; - } if (screen_info->glx_feature_mask & GLITZ_GLX_FEATURE_MULTISAMPLE_MASK && screen_info->glx_feature_mask & GLITZ_GLX_FEATURE_CLIENT_MULTISAMPLE_MASK) { - const char *renderer = (char *) glGetString (GL_RENDERER); + const glitz_gl_ubyte_t *renderer = glGetString (GL_RENDERER); screen_info->feature_mask |= GLITZ_FEATURE_MULTISAMPLE_MASK; @@ -158,15 +157,16 @@ glitz_glx_query_extensions (glitz_glx_screen_info_t *screen_info) screen_info->feature_mask |= GLITZ_FEATURE_COMPONENT_ALPHA_MASK; } - if (screen_info->glx_feature_mask & GLITZ_GLX_FEATURE_VERTEX_PROGRAM_MASK) - screen_info->feature_mask |= GLITZ_FEATURE_VERTEX_PROGRAM_MASK; - if (screen_info->glx_feature_mask & GLITZ_GLX_FEATURE_FRAGMENT_PROGRAM_MASK) screen_info->feature_mask |= GLITZ_FEATURE_FRAGMENT_PROGRAM_MASK; } if (screen_info->glx_feature_mask & + GLITZ_GLX_FEATURE_VERTEX_BUFFER_OBJECT_MASK) + screen_info->feature_mask |= GLITZ_FEATURE_VERTEX_BUFFER_OBJECT_MASK; + + if (screen_info->glx_feature_mask & GLITZ_GLX_FEATURE_PIXEL_BUFFER_OBJECT_MASK) screen_info->feature_mask |= GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK; } diff --git a/src/glitz_glx_format.c b/src/glitz_glx_format.c index 807e004..de5e6cf 100644 --- a/src/glitz_glx_format.c +++ b/src/glitz_glx_format.c @@ -183,7 +183,6 @@ glitz_glx_query_formats_glx13 (glitz_glx_screen_info_t *screen_info) fbconfigs = glx->get_fbconfigs (display, screen_info->screen, &num_configs); if (!fbconfigs) { /* GLX 1.3 is not support, falling back to GLX 1.2 */ - screen_info->feature_mask &= ~GLITZ_FEATURE_OFFSCREEN_DRAWING_MASK; screen_info->glx_feature_mask &= ~GLITZ_GLX_FEATURE_GLX13_MASK; return 1; } @@ -287,7 +286,7 @@ glitz_glx_query_formats (glitz_glx_screen_info_t *screen_info) sizeof (glitz_format_t), _glitz_glx_format_compare); glitz_format_for_each_texture_format (&_glitz_glx_add_texture_format, - &screen_info->root_context.gl, + &screen_info->root_context.backend.gl, (void *) screen_info); _glitz_move_out_ids (screen_info); diff --git a/src/glitz_glx_info.c b/src/glitz_glx_info.c index 67dd908..ccf77a7 100644 --- a/src/glitz_glx_info.c +++ b/src/glitz_glx_info.c @@ -34,18 +34,19 @@ #include <string.h> #include <dlfcn.h> -glitz_gl_proc_address_list_t _glitz_gl_proc_address = { +glitz_gl_proc_address_list_t _glitz_glx_gl_proc_address = { (glitz_gl_enable_t) glEnable, (glitz_gl_disable_t) glDisable, - (glitz_gl_begin_t) glBegin, - (glitz_gl_end_t) glEnd, - (glitz_gl_vertex_2i_t) glVertex2i, - (glitz_gl_vertex_2d_t) glVertex2d, + (glitz_gl_enable_client_state_t) glEnableClientState, + (glitz_gl_disable_client_state_t) glDisableClientState, + (glitz_gl_vertex_pointer_t) glVertexPointer, + (glitz_gl_draw_arrays_t) glDrawArrays, (glitz_gl_tex_env_f_t) glTexEnvf, (glitz_gl_tex_env_fv_t) glTexEnvfv, - (glitz_gl_tex_coord_2d_t) glTexCoord2d, + (glitz_gl_tex_gen_i_t) glTexGeni, + (glitz_gl_tex_gen_fv_t) glTexGenfv, (glitz_gl_color_4us_t) glColor4us, - (glitz_gl_color_4d_t) glColor4d, + (glitz_gl_color_4f_t) glColor4f, (glitz_gl_scissor_t) glScissor, (glitz_gl_blend_func_t) glBlendFunc, (glitz_gl_clear_t) glClear, @@ -59,11 +60,10 @@ glitz_gl_proc_address_list_t _glitz_gl_proc_address = { (glitz_gl_push_matrix_t) glPushMatrix, (glitz_gl_pop_matrix_t) glPopMatrix, (glitz_gl_load_identity_t) glLoadIdentity, - (glitz_gl_load_matrix_d_t) glLoadMatrixd, - (glitz_gl_mult_matrix_d_t) glMultMatrixd, + (glitz_gl_load_matrix_f_t) glLoadMatrixf, (glitz_gl_depth_range_t) glDepthRange, (glitz_gl_viewport_t) glViewport, - (glitz_gl_raster_pos_2d_t) glRasterPos2d, + (glitz_gl_raster_pos_2f_t) glRasterPos2f, (glitz_gl_bitmap_t) glBitmap, (glitz_gl_read_buffer_t) glReadBuffer, (glitz_gl_draw_buffer_t) glDrawBuffer, @@ -72,8 +72,8 @@ glitz_gl_proc_address_list_t _glitz_gl_proc_address = { (glitz_gl_finish_t) glFinish, (glitz_gl_pixel_store_i_t) glPixelStorei, (glitz_gl_ortho_t) glOrtho, - (glitz_gl_scale_d_t) glScaled, - (glitz_gl_translate_d_t) glTranslated, + (glitz_gl_scale_f_t) glScalef, + (glitz_gl_translate_f_t) glTranslatef, (glitz_gl_hint_t) glHint, (glitz_gl_depth_mask_t) glDepthMask, (glitz_gl_polygon_mode_t) glPolygonMode, @@ -85,7 +85,6 @@ glitz_gl_proc_address_list_t _glitz_gl_proc_address = { (glitz_gl_gen_textures_t) glGenTextures, (glitz_gl_delete_textures_t) glDeleteTextures, (glitz_gl_bind_texture_t) glBindTexture, - (glitz_gl_tex_image_1d_t) glTexImage1D, (glitz_gl_tex_image_2d_t) glTexImage2D, (glitz_gl_tex_parameter_i_t) glTexParameteri, (glitz_gl_get_tex_level_parameter_iv_t) glGetTexLevelParameteriv, @@ -93,19 +92,21 @@ glitz_gl_proc_address_list_t _glitz_gl_proc_address = { (glitz_gl_get_integer_v_t) glGetIntegerv, (glitz_gl_active_texture_t) 0, - (glitz_gl_multi_tex_coord_2d_t) 0, (glitz_gl_gen_programs_t) 0, (glitz_gl_delete_programs_t) 0, (glitz_gl_program_string_t) 0, (glitz_gl_bind_program_t) 0, - (glitz_gl_program_local_param_4d_t) 0, + (glitz_gl_program_local_param_4fv_t) 0, (glitz_gl_get_program_iv_t) 0, (glitz_gl_gen_buffers_t) 0, (glitz_gl_delete_buffers_t) 0, (glitz_gl_bind_buffer_t) 0, (glitz_gl_buffer_data_t) 0, + (glitz_gl_buffer_sub_data_t) 0, + (glitz_gl_get_buffer_sub_data_t) 0, (glitz_gl_map_buffer_t) 0, (glitz_gl_unmap_buffer_t) 0, + 1 }; @@ -400,12 +401,19 @@ glitz_glx_create_root_context (glitz_glx_screen_info_t *screen_info) } screen_info->root_context.fbconfig = (XID) 0; - - memcpy (&screen_info->root_context.gl, - &_glitz_gl_proc_address, + + glitz_glx_surface_backend_init (&screen_info->root_context.backend); + + memcpy (&screen_info->root_context.backend.gl, + &_glitz_glx_gl_proc_address, sizeof (glitz_gl_proc_address_list_t)); + + screen_info->root_context.backend.formats = NULL; + screen_info->root_context.backend.n_formats = 0; + screen_info->root_context.backend.program_map = &screen_info->program_map; + screen_info->root_context.backend.feature_mask = 0; - screen_info->root_context.gl.need_lookup = 1; + screen_info->root_context.backend.gl.need_lookup = 1; } glitz_glx_screen_info_t * @@ -457,6 +465,9 @@ glitz_glx_screen_info_get (Display *display, &screen_info->root_context); glitz_glx_query_formats (screen_info); } + + screen_info->root_context.backend.formats = screen_info->formats; + screen_info->root_context.backend.n_formats = screen_info->n_formats; screen_info->context_stack_size = 1; screen_info->context_stack->surface = NULL; @@ -475,7 +486,7 @@ glitz_glx_screen_destroy (glitz_glx_screen_info_t *screen_info) glXMakeCurrent (screen_info->display_info->display, screen_info->root_drawable, screen_info->root_context.context)) { - glitz_program_map_fini (&screen_info->root_context.gl, + glitz_program_map_fini (&screen_info->root_context.backend.gl, &screen_info->program_map); glXMakeCurrent (display, None, NULL); } diff --git a/src/glitz_glx_surface.c b/src/glitz_glx_surface.c index 2515475..a84593e 100644 --- a/src/glitz_glx_surface.c +++ b/src/glitz_glx_surface.c @@ -31,25 +31,6 @@ #include "glitz_glxint.h" -static glitz_surface_t * -_glitz_glx_surface_create_similar (void *abstract_templ, - glitz_format_t *format, - int width, - int height); - -static void -_glitz_glx_surface_destroy (void *abstract_surface); - -static glitz_texture_t * -_glitz_glx_surface_get_texture (void *abstract_surface, - glitz_bool_t allocate); - -static void -_glitz_glx_surface_update_size (void *abstract_surface); - -static void -_glitz_glx_surface_swap_buffers (void *abstract_surface); - static glitz_bool_t _glitz_glx_surface_push_current (void *abstract_surface, glitz_constraint_t constraint) @@ -114,22 +95,11 @@ _glitz_glx_surface_make_current_read (void *abstract_surface) return 0; } -static const struct glitz_surface_backend glitz_glx_surface_backend = { - _glitz_glx_surface_create_similar, - _glitz_glx_surface_destroy, - _glitz_glx_surface_push_current, - _glitz_glx_surface_pop_current, - _glitz_glx_surface_get_texture, - _glitz_glx_surface_update_size, - _glitz_glx_surface_swap_buffers, - _glitz_glx_surface_make_current_read -}; - static glitz_bool_t -_glitz_glx_surface_update_size_for_window (Display *display, - Window drawable, - int *width, - int *height) +_glitz_glx_surface_get_window_size (Display *display, + Window drawable, + int *width, + int *height) { unsigned int uwidth, uheight, bwidth_ignore, depth_ignore; Window root_ignore; @@ -151,7 +121,7 @@ _glitz_glx_surface_get_texture (void *abstract_surface, { glitz_glx_surface_t *surface = (glitz_glx_surface_t *) abstract_surface; - if (surface->base.hint_mask & GLITZ_INT_HINT_DIRTY_MASK) { + if (surface->base.flags & GLITZ_FLAG_DIRTY_MASK) { glitz_bounding_box_t copy_box; copy_box.x1 = copy_box.y1 = 0; @@ -161,7 +131,8 @@ _glitz_glx_surface_get_texture (void *abstract_surface, ©_box, ©_box); if (!surface->base.texture.allocated) - glitz_texture_allocate (surface->base.gl, &surface->base.texture); + glitz_texture_allocate (&surface->base.backend->gl, + &surface->base.texture); glitz_texture_copy_surface (&surface->base.texture, &surface->base, copy_box.x1, @@ -170,12 +141,14 @@ _glitz_glx_surface_get_texture (void *abstract_surface, copy_box.y2 - copy_box.y1, copy_box.x1, copy_box.y1); - surface->base.hint_mask &= ~GLITZ_INT_HINT_DIRTY_MASK; + + surface->base.flags &= ~GLITZ_FLAG_DIRTY_MASK; } if (allocate) { if (!surface->base.texture.allocated) - glitz_texture_allocate (surface->base.gl, &surface->base.texture); + glitz_texture_allocate (&surface->base.backend->gl, + &surface->base.texture); } if (surface->base.texture.allocated) @@ -184,57 +157,6 @@ _glitz_glx_surface_get_texture (void *abstract_surface, return NULL; } -static void -_glitz_glx_set_features (glitz_glx_surface_t *surface) -{ - surface->base.feature_mask = surface->screen_info->feature_mask; - - surface->base.feature_mask &= ~GLITZ_FEATURE_MULTITEXTURE_MASK; - surface->base.feature_mask &= ~GLITZ_FEATURE_COMPONENT_ALPHA_MASK; - surface->base.feature_mask &= ~GLITZ_FEATURE_VERTEX_PROGRAM_MASK; - surface->base.feature_mask &= ~GLITZ_FEATURE_FRAGMENT_PROGRAM_MASK; - surface->base.feature_mask &= ~GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK; - - if (surface->context->gl.need_lookup) { - glitz_glx_context_push_current (surface, GLITZ_CN_SURFACE_CONTEXT_CURRENT); - glitz_glx_context_pop_current (surface); - } - - if (surface->context->gl.active_texture && - surface->context->gl.multi_tex_coord_2d) { - surface->base.feature_mask |= GLITZ_FEATURE_MULTITEXTURE_MASK; - - if (surface->screen_info->feature_mask & - GLITZ_FEATURE_COMPONENT_ALPHA_MASK) - surface->base.feature_mask |= GLITZ_FEATURE_COMPONENT_ALPHA_MASK; - - if (surface->context->gl.gen_programs && - surface->context->gl.delete_programs && - surface->context->gl.program_string && - surface->context->gl.bind_program && - surface->context->gl.program_local_param_4d) { - if (surface->screen_info->feature_mask & - GLITZ_FEATURE_VERTEX_PROGRAM_MASK) { - surface->base.feature_mask |= GLITZ_FEATURE_VERTEX_PROGRAM_MASK; - - if (surface->screen_info->feature_mask & - GLITZ_FEATURE_FRAGMENT_PROGRAM_MASK) - surface->base.feature_mask |= GLITZ_FEATURE_FRAGMENT_PROGRAM_MASK; - } - } - } - - if (surface->context->gl.gen_buffers && - surface->context->gl.delete_buffers && - surface->context->gl.bind_buffer && - surface->context->gl.buffer_data && - surface->context->gl.map_buffer && - surface->context->gl.unmap_buffer) - if (surface->screen_info->feature_mask & - GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK) - surface->base.feature_mask |= GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK; -} - static glitz_surface_t * _glitz_glx_surface_create (glitz_glx_screen_info_t *screen_info, glitz_format_t *format, @@ -253,25 +175,24 @@ _glitz_glx_surface_create (glitz_glx_screen_info_t *screen_info, return NULL; glitz_surface_init (&surface->base, - &glitz_glx_surface_backend, - &context->gl, + &context->backend, format, - screen_info->formats, - screen_info->n_formats, width, height, - &screen_info->program_map, screen_info->texture_mask); surface->screen_info = screen_info; surface->context = context; - surface->base.hint_mask |= GLITZ_HINT_OFFSCREEN_MASK; + surface->base.flags |= GLITZ_FLAG_OFFSCREEN_MASK; if (format->draw.offscreen) - surface->base.hint_mask |= GLITZ_INT_HINT_DRAWABLE_MASK; + surface->base.flags |= GLITZ_FLAG_DRAWABLE_MASK; - _glitz_glx_set_features (surface); + if (surface->context->backend.gl.need_lookup) { + glitz_glx_context_push_current (surface, GLITZ_CN_SURFACE_CONTEXT_CURRENT); + glitz_glx_context_pop_current (surface); + } return &surface->base; } @@ -307,8 +228,7 @@ glitz_glx_surface_create_for_window (Display *display, if (!context) return NULL; - if (!_glitz_glx_surface_update_size_for_window (display, window, - &width, &height)) + if (!_glitz_glx_surface_get_window_size (display, window, &width, &height)) return NULL; surface = (glitz_glx_surface_t *) calloc (1, sizeof (glitz_glx_surface_t)); @@ -316,23 +236,22 @@ glitz_glx_surface_create_for_window (Display *display, return NULL; glitz_surface_init (&surface->base, - &glitz_glx_surface_backend, - &context->gl, + &context->backend, format, - screen_info->formats, - screen_info->n_formats, width, height, - &screen_info->program_map, screen_info->texture_mask); surface->screen_info = screen_info; surface->context = context; surface->drawable = window; - surface->base.hint_mask |= GLITZ_INT_HINT_DRAWABLE_MASK; + surface->base.flags |= GLITZ_FLAG_DRAWABLE_MASK; - _glitz_glx_set_features (surface); + if (surface->context->backend.gl.need_lookup) { + glitz_glx_context_push_current (surface, GLITZ_CN_SURFACE_CONTEXT_CURRENT); + glitz_glx_context_pop_current (surface); + } return &surface->base; } @@ -373,39 +292,6 @@ _glitz_glx_surface_destroy (void *abstract_surface) } static void -_glitz_glx_surface_update_size (void *abstract_surface) -{ - glitz_glx_surface_t *surface = (glitz_glx_surface_t *) abstract_surface; - - if ((!surface->pbuffer) && surface->drawable) { - int width, height; - - _glitz_glx_surface_update_size_for_window - (surface->screen_info->display_info->display, surface->drawable, - &width, &height); - - if (width != surface->base.width || height != surface->base.height) { - glitz_texture_t texture; - - glitz_texture_init (&texture, - width, height, - surface->base.texture.format, - surface->screen_info->texture_mask); - - if (texture.width != surface->base.texture.width || - texture.height != surface->base.texture.height || - texture.target != surface->base.texture.target) { - texture.name = surface->base.texture.name; - surface->base.texture = texture; - } - - surface->base.width = width; - surface->base.height = height; - } - } -} - -static void _glitz_glx_surface_swap_buffers (void *abstract_surface) { glitz_glx_surface_t *surface = (glitz_glx_surface_t *) abstract_surface; @@ -420,3 +306,15 @@ _glitz_glx_surface_swap_buffers (void *abstract_surface) glitz_glx_context_pop_current (surface); } + +void +glitz_glx_surface_backend_init (glitz_surface_backend_t *backend) +{ + backend->create_similar = _glitz_glx_surface_create_similar; + backend->destroy = _glitz_glx_surface_destroy; + backend->push_current = _glitz_glx_surface_push_current; + backend->pop_current = _glitz_glx_surface_pop_current; + backend->get_texture = _glitz_glx_surface_get_texture; + backend->swap_buffers = _glitz_glx_surface_swap_buffers; + backend->make_current_read = _glitz_glx_surface_make_current_read; +} diff --git a/src/glitz_glxint.h b/src/glitz_glxint.h index 6a77d25..4a59f5a 100644 --- a/src/glitz_glxint.h +++ b/src/glitz_glxint.h @@ -47,9 +47,9 @@ #define GLITZ_GLX_FEATURE_MULTITEXTURE_MASK (1L << 7) #define GLITZ_GLX_FEATURE_TEXTURE_ENV_COMBINE_MASK (1L << 8) #define GLITZ_GLX_FEATURE_TEXTURE_ENV_DOT3_MASK (1L << 9) -#define GLITZ_GLX_FEATURE_VERTEX_PROGRAM_MASK (1L << 10) -#define GLITZ_GLX_FEATURE_FRAGMENT_PROGRAM_MASK (1L << 11) -#define GLITZ_GLX_FEATURE_GLX13_MASK (1L << 12) +#define GLITZ_GLX_FEATURE_FRAGMENT_PROGRAM_MASK (1L << 10) +#define GLITZ_GLX_FEATURE_GLX13_MASK (1L << 11) +#define GLITZ_GLX_FEATURE_VERTEX_BUFFER_OBJECT_MASK (1L << 12) #define GLITZ_GLX_FEATURE_PIXEL_BUFFER_OBJECT_MASK (1L << 13) typedef struct _glitz_glx_surface glitz_glx_surface_t; @@ -90,8 +90,8 @@ typedef struct _glitz_glx_context_info_t { typedef struct _glitz_glx_context_t { GLXContext context; XID id; - glitz_gl_proc_address_list_t gl; GLXFBConfig fbconfig; + glitz_surface_backend_t backend; } glitz_glx_context_t; struct _glitz_glx_screen_info_t { @@ -112,9 +112,9 @@ struct _glitz_glx_screen_info_t { GLXDrawable root_drawable; Colormap root_colormap; - long int feature_mask; - long int glx_feature_mask; - long int texture_mask; + unsigned long feature_mask; + unsigned long glx_feature_mask; + unsigned long texture_mask; glitz_program_map_t program_map; }; @@ -180,6 +180,9 @@ extern void __internal_linkage glitz_glx_pbuffer_destroy (glitz_glx_display_info_t *display_info, GLXPbuffer pbuffer); +extern void __internal_linkage +glitz_glx_surface_backend_init (glitz_surface_backend_t *backend); + /* Avoid unnecessary PLT entries. */ slim_hidden_proto(glitz_glx_init) diff --git a/src/glitz_operator.c b/src/glitz_operator.c index 8c779c7..6d9975b 100644 --- a/src/glitz_operator.c +++ b/src/glitz_operator.c @@ -96,40 +96,3 @@ glitz_set_operator (glitz_gl_proc_address_list_t *gl, glitz_operator_t op) { break; } } - -void -glitz_set_stencil_operator (glitz_gl_proc_address_list_t *gl, - glitz_stencil_operator_t op, - unsigned int mask) -{ - gl->enable (GLITZ_GL_STENCIL_TEST); - - switch (op) { - case GLITZ_STENCIL_OPERATOR_SET: - case GLITZ_STENCIL_OPERATOR_UNION: - case GLITZ_STENCIL_OPERATOR_CLEAR: - gl->stencil_func (GLITZ_GL_ALWAYS, mask, ~0x0); - gl->stencil_op (GLITZ_GL_REPLACE, GLITZ_GL_REPLACE, GLITZ_GL_REPLACE); - break; - case GLITZ_STENCIL_OPERATOR_INTERSECT: - gl->stencil_func (GLITZ_GL_LESS, mask, ~0x0); - gl->stencil_op (GLITZ_GL_ZERO, GLITZ_GL_REPLACE, GLITZ_GL_REPLACE); - break; - case GLITZ_STENCIL_OPERATOR_INCR_EQUAL: - gl->stencil_func (GLITZ_GL_EQUAL, mask, mask); - gl->stencil_op (GLITZ_GL_KEEP, GLITZ_GL_INCR, GLITZ_GL_INCR); - break; - case GLITZ_STENCIL_OPERATOR_DECR_LESS: - gl->stencil_func (GLITZ_GL_LESS, mask, ~0x0); - gl->stencil_op (GLITZ_GL_KEEP, GLITZ_GL_REPLACE, GLITZ_GL_REPLACE); - break; - case GLITZ_STENCIL_OPERATOR_CLIP_EQUAL: - gl->stencil_func (GLITZ_GL_EQUAL, mask, ~0x0); - gl->stencil_op (GLITZ_GL_KEEP, GLITZ_GL_KEEP, GLITZ_GL_KEEP); - break; - case GLITZ_STENCIL_OPERATOR_CLIP: - gl->stencil_func (GLITZ_GL_LEQUAL, mask, ~0x0); - gl->stencil_op (GLITZ_GL_KEEP, GLITZ_GL_KEEP, GLITZ_GL_KEEP); - break; - } -} diff --git a/src/glitz_pixel.c b/src/glitz_pixel.c index f4d326d..25485d9 100644 --- a/src/glitz_pixel.c +++ b/src/glitz_pixel.c @@ -100,10 +100,7 @@ static struct _glitz_gl_pixel_format { #define GLITZ_GL_FORMAT_ARGB 2 typedef struct _glitz_pixel_color { - double a; - double r; - double g; - double b; + uint32_t r, g, b, a; } glitz_pixel_color_t; typedef struct _glitz_pixel_transform_op { @@ -114,9 +111,12 @@ typedef struct _glitz_pixel_transform_op { } glitz_pixel_transform_op_t; #define FETCH(p, mask) ((mask)? \ - (((double) (((uint32_t) (p)) & (mask))) / ((double) mask)): 0.0) + ((uint32_t) ((((uint64_t) (((uint32_t) (p)) & (mask))) * 0xffffffff) / \ + ((uint64_t) (mask)))): 0x0) + #define FETCH_A(p, mask) ((mask)? \ - (((double) (((uint32_t) (p)) & (mask))) / ((double) mask)): 1.0) + ((uint32_t) ((((uint64_t) (((uint32_t) (p)) & (mask))) * 0xffffffff) / \ + ((uint64_t) (mask)))): 0xffffffff) typedef void (*glitz_pixel_fetch_function_t) (glitz_pixel_transform_op_t *op); @@ -191,7 +191,7 @@ _fetch_32 (glitz_pixel_transform_op_t *op) typedef void (*glitz_pixel_store_function_t) (glitz_pixel_transform_op_t *op); #define STORE(v, mask) \ - (((uint32_t) (v * (double) mask)) & mask) + (((uint32_t) (((v) * (uint64_t) (mask)) / 0xffffffff)) & (mask)) static void _store_1 (glitz_pixel_transform_op_t *op) @@ -406,257 +406,20 @@ _glitz_best_gl_pixel_format (glitz_format_t *format) return &_gl_format_map[GLITZ_GL_FORMAT_A]; } -struct _glitz_pixel_buffer { - glitz_gl_sizei_t size; - glitz_gl_uint_t name; - glitz_gl_enum_t target; - char *data; - int owns_data; - glitz_surface_t *surface; - glitz_pixel_format_t format; -}; - -glitz_pixel_buffer_t * -glitz_pixel_buffer_create (glitz_surface_t *surface, - char *data, - unsigned int size, - glitz_buffer_hint_t hint) -{ - glitz_pixel_buffer_t *buffer; - glitz_gl_enum_t usage; - - buffer = malloc (sizeof (glitz_pixel_buffer_t)); - if (buffer == NULL) - return NULL; - - buffer->size = size; - buffer->name = 0; - - switch (hint) { - case GLITZ_PIXEL_BUFFER_HINT_STREAM_DRAW: - usage = GLITZ_GL_STREAM_DRAW; - buffer->target = GLITZ_GL_PIXEL_UNPACK_BUFFER; - break; - case GLITZ_PIXEL_BUFFER_HINT_STREAM_READ: - usage = GLITZ_GL_STREAM_READ; - buffer->target = GLITZ_GL_PIXEL_PACK_BUFFER; - break; - case GLITZ_PIXEL_BUFFER_HINT_STREAM_COPY: - usage = GLITZ_GL_STREAM_COPY; - buffer->target = GLITZ_GL_PIXEL_UNPACK_BUFFER; - break; - case GLITZ_PIXEL_BUFFER_HINT_STATIC_DRAW: - usage = GLITZ_GL_STATIC_DRAW; - buffer->target = GLITZ_GL_PIXEL_UNPACK_BUFFER; - break; - case GLITZ_PIXEL_BUFFER_HINT_STATIC_READ: - usage = GLITZ_GL_STATIC_READ; - buffer->target = GLITZ_GL_PIXEL_PACK_BUFFER; - break; - case GLITZ_PIXEL_BUFFER_HINT_STATIC_COPY: - usage = GLITZ_GL_STATIC_COPY; - buffer->target = GLITZ_GL_PIXEL_UNPACK_BUFFER; - break; - case GLITZ_PIXEL_BUFFER_HINT_DYNAMIC_DRAW: - usage = GLITZ_GL_DYNAMIC_DRAW; - buffer->target = GLITZ_GL_PIXEL_UNPACK_BUFFER; - break; - case GLITZ_PIXEL_BUFFER_HINT_DYNAMIC_READ: - usage = GLITZ_GL_DYNAMIC_READ; - buffer->target = GLITZ_GL_PIXEL_PACK_BUFFER; - break; - default: - usage = GLITZ_GL_DYNAMIC_COPY; - buffer->target = GLITZ_GL_PIXEL_UNPACK_BUFFER; - break; - } - - if (surface->feature_mask & GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK) { - buffer->surface = surface; - glitz_surface_reference (surface); - - glitz_surface_push_current (surface, GLITZ_CN_ANY_CONTEXT_CURRENT); - - surface->gl->gen_buffers (1, &buffer->name); - if (buffer->name) { - surface->gl->bind_buffer (buffer->target, buffer->name); - surface->gl->buffer_data (buffer->target, size, data, usage); - } - - glitz_surface_pop_current (surface); - } else - buffer->surface = NULL; - - if (buffer->name == 0) { - buffer->data = malloc (size); - if (buffer->data == NULL) { - free (buffer); - return NULL; - } - - if (data) - memcpy (buffer->data, data, size); - - buffer->owns_data = 1; - } - - buffer->format = _glitz_best_gl_pixel_format (surface->format)->pixel; - - return buffer; -} - -glitz_pixel_buffer_t * -glitz_pixel_buffer_create_for_data (char *data, - glitz_pixel_format_t *format) -{ - glitz_pixel_buffer_t *buffer; - - buffer = malloc (sizeof (glitz_pixel_buffer_t)); - if (buffer == NULL) - return NULL; - - buffer->name = 0; - buffer->size = 0; - buffer->data = data; - buffer->owns_data = 0; - buffer->surface = NULL; - buffer->target = 0; - buffer->format = *format; - - return buffer; -} - -void -glitz_pixel_buffer_destroy (glitz_pixel_buffer_t *buffer) -{ - glitz_surface_t *surface = buffer->surface; - - if (surface && - surface->feature_mask & GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK) { - glitz_surface_push_current (surface, GLITZ_CN_ANY_CONTEXT_CURRENT); - - surface->gl->delete_buffers (1, &buffer->name); - - glitz_surface_pop_current (surface); - - glitz_surface_destroy (surface); - } else if (buffer->owns_data) - free (buffer->data); - - free (buffer); -} - void -glitz_pixel_buffer_set_format (glitz_pixel_buffer_t *buffer, - glitz_pixel_format_t *format) -{ - buffer->format = *format; -} - -void -glitz_pixel_buffer_get_format (glitz_pixel_buffer_t *buffer, - glitz_pixel_format_t *format) -{ - *format = buffer->format; -} - -char * -glitz_pixel_buffer_get_data (glitz_pixel_buffer_t *buffer, - glitz_pixel_buffer_access_t access) -{ - char *pointer = NULL; - glitz_surface_t *surface = buffer->surface; - - if (surface && - surface->feature_mask & GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK) { - glitz_gl_enum_t buffer_access; - - glitz_surface_push_current (surface, GLITZ_CN_ANY_CONTEXT_CURRENT); - - switch (access) { - case GLITZ_PIXEL_BUFFER_ACCESS_READ_ONLY: - buffer_access = GLITZ_GL_READ_ONLY; - break; - case GLITZ_PIXEL_BUFFER_ACCESS_WRITE_ONLY: - buffer_access = GLITZ_GL_WRITE_ONLY; - break; - default: - buffer_access = GLITZ_GL_READ_WRITE; - break; - } - - surface->gl->bind_buffer (buffer->target, buffer->name); - pointer = (char *) surface->gl->map_buffer (buffer->target, - buffer_access); - - glitz_surface_pop_current (surface); - } - - if (pointer == NULL) - pointer = buffer->data; - - return pointer; -} - -void -glitz_pixel_buffer_put_back_data (glitz_pixel_buffer_t *buffer) -{ - glitz_surface_t *surface = buffer->surface; - - if (surface && - surface->feature_mask & GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK) { - glitz_surface_push_current (surface, GLITZ_CN_ANY_CONTEXT_CURRENT); - - if (surface->gl->unmap_buffer (buffer->target)) { - /* don't know what to do here, maybe glitz_pixel_buffer_put_back_data - should return a status value */ - } - surface->gl->bind_buffer (buffer->target, 0); - - glitz_surface_pop_current (surface); - } -} - -char * -glitz_pixel_buffer_bind (glitz_pixel_buffer_t *buffer, - glitz_gl_enum_t target) -{ - glitz_surface_t *surface = buffer->surface; - - if (surface && - surface->feature_mask & GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK) { - surface->gl->bind_buffer (target, buffer->name); - buffer->target = target; - - return NULL; - } - - return buffer->data; -} - -void -glitz_pixel_buffer_unbind (glitz_pixel_buffer_t *buffer) -{ - glitz_surface_t *surface = buffer->surface; - - if (surface && - surface->feature_mask & GLITZ_FEATURE_PIXEL_BUFFER_OBJECT_MASK) - surface->gl->bind_buffer (buffer->target, 0); -} - -void -glitz_put_pixels (glitz_surface_t *dst, +glitz_set_pixels (glitz_surface_t *dst, int x_dst, int y_dst, int width, int height, - glitz_pixel_buffer_t *buffer) + glitz_pixel_format_t *format, + glitz_buffer_t *buffer) { glitz_gl_proc_address_list_t *gl; glitz_bool_t to_drawable; glitz_texture_t *texture; char *pixels, *data = NULL; - glitz_gl_pixel_format_t *format = NULL; + glitz_gl_pixel_format_t *gl_format = NULL; unsigned long transform = 0; int xoffset, bytes_per_line; @@ -666,16 +429,16 @@ glitz_put_pixels (glitz_surface_t *dst, return; } - gl = dst->gl; + gl = &dst->backend->gl; - if (buffer->format.scanline_order == GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN) + if (format->scanline_order == GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN) transform |= GLITZ_TRANSFORM_SCANLINE_ORDER_MASK; /* find direct format */ - format = _glitz_find_gl_pixel_format (&buffer->format); - if (format == NULL) { + gl_format = _glitz_find_gl_pixel_format (format); + if (gl_format == NULL) { transform |= GLITZ_TRANSFORM_PIXELS_MASK; - format = _glitz_best_gl_pixel_format (dst->format); + gl_format = _glitz_best_gl_pixel_format (dst->format); } if (SURFACE_DRAWABLE (dst)) @@ -693,7 +456,7 @@ glitz_put_pixels (glitz_surface_t *dst, glitz_image_t src_image, dst_image; int stride; - stride = (((width * format->pixel.masks.bpp) / 8) + 3) & -4; + stride = (((width * gl_format->pixel.masks.bpp) / 8) + 3) & -4; data = malloc (stride * height); if (!data) { @@ -703,36 +466,33 @@ glitz_put_pixels (glitz_surface_t *dst, } dst_image.data = data; - dst_image.format = &format->pixel; + dst_image.format = &gl_format->pixel; dst_image.width = width; dst_image.height = height; - src_image.data = - glitz_pixel_buffer_get_data (buffer, - GLITZ_PIXEL_BUFFER_ACCESS_READ_ONLY); - src_image.data += buffer->format.skip_lines * - buffer->format.bytes_per_line; - src_image.format = &buffer->format; + src_image.data = glitz_buffer_map (buffer, GLITZ_BUFFER_ACCESS_READ_ONLY); + src_image.data += format->skip_lines * format->bytes_per_line; + src_image.format = format; src_image.width = width; src_image.height = height; _glitz_pixel_transform (transform, &src_image, &dst_image, - buffer->format.xoffset, + format->xoffset, 0, width, height); - glitz_pixel_buffer_put_back_data (buffer); + glitz_buffer_unmap (buffer); pixels = data; xoffset = 0; bytes_per_line = stride; } else { - xoffset = buffer->format.xoffset; - bytes_per_line = buffer->format.bytes_per_line; - pixels = glitz_pixel_buffer_bind (buffer, GLITZ_GL_PIXEL_UNPACK_BUFFER); - pixels += buffer->format.skip_lines * bytes_per_line; + xoffset = format->xoffset; + bytes_per_line = format->bytes_per_line; + pixels = glitz_buffer_bind (buffer, GLITZ_GL_PIXEL_UNPACK_BUFFER); + pixels += format->skip_lines * bytes_per_line; } texture = glitz_surface_get_texture (dst, 1); @@ -762,53 +522,42 @@ glitz_put_pixels (glitz_surface_t *dst, gl->tex_sub_image_2d (texture->target, 0, x_dst, dst->height - y_dst - height, width, height, - format->format, format->type, + gl_format->format, gl_format->type, pixels); if (to_drawable) { - glitz_point_t tl, br; + glitz_texture_set_tex_gen (gl, texture, x_dst, y_dst, height, ~0); - gl->matrix_mode (GLITZ_GL_TEXTURE); - gl->load_identity (); - gl->tex_env_f (GLITZ_GL_TEXTURE_ENV, GLITZ_GL_TEXTURE_ENV_MODE, GLITZ_GL_REPLACE); gl->color_4us (0x0, 0x0, 0x0, 0xffff); - glitz_set_operator (gl, GLITZ_OPERATOR_SRC); - glitz_texture_ensure_wrap (gl, texture, GLITZ_GL_CLAMP_TO_EDGE); glitz_texture_ensure_filter (gl, texture, GLITZ_GL_NEAREST); - glitz_texture_tex_coord (texture, x_dst, y_dst, &tl.x, &tl.y); - glitz_texture_tex_coord (texture, - x_dst + width, y_dst + height, &br.x, &br.y); + glitz_set_operator (gl, GLITZ_OPERATOR_SRC); - tl.y = texture->texcoord_height - tl.y; - br.y = texture->texcoord_height - br.y; - - gl->begin (GLITZ_GL_QUADS); - gl->tex_coord_2d (tl.x, tl.y); - gl->vertex_2d (x_dst, y_dst); - gl->tex_coord_2d (br.x, tl.y); - gl->vertex_2d (x_dst + width, y_dst); - gl->tex_coord_2d (br.x, br.y); - gl->vertex_2d (x_dst + width, y_dst + height); - gl->tex_coord_2d (tl.x, br.y); - gl->vertex_2d (x_dst, y_dst + height); - gl->end (); + gl->scissor (x_dst, + dst->height - (y_dst + height), + width, height); + + glitz_geometry_enable_default (gl, dst); + + gl->draw_arrays (GLITZ_GL_QUADS, 0, 4); + + glitz_geometry_disable (gl, dst); if (x_dst == 0 && y_dst == 0 && width == dst->width && height == dst->height) - dst->hint_mask &= ~GLITZ_INT_HINT_DIRTY_MASK; + dst->flags &= ~GLITZ_FLAG_DIRTY_MASK; } glitz_texture_unbind (gl, texture); - dst->hint_mask |= GLITZ_INT_HINT_SOLID_DIRTY_MASK; + dst->flags |= GLITZ_FLAG_SOLID_DIRTY_MASK; if (transform == 0) - glitz_pixel_buffer_unbind (buffer); + glitz_buffer_unbind (buffer); glitz_surface_pop_current (dst); @@ -822,13 +571,14 @@ glitz_get_pixels (glitz_surface_t *src, int y_src, int width, int height, - glitz_pixel_buffer_t *buffer) + glitz_pixel_format_t *format, + glitz_buffer_t *buffer) { glitz_gl_proc_address_list_t *gl; glitz_bool_t from_drawable; glitz_texture_t *texture = NULL; char *pixels, *data = NULL; - glitz_gl_pixel_format_t *format = NULL; + glitz_gl_pixel_format_t *gl_format = NULL; unsigned long transform = 0; int src_x = 0, src_y = 0, src_w = width, src_h = height; int xoffset, bytes_per_line; @@ -839,7 +589,7 @@ glitz_get_pixels (glitz_surface_t *src, return; } - gl = src->gl; + gl = &src->backend->gl; if (glitz_surface_push_current (src, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { from_drawable = 1; @@ -855,14 +605,14 @@ glitz_get_pixels (glitz_surface_t *src, transform |= GLITZ_TRANSFORM_COPY_REGION_MASK; } - if (buffer->format.scanline_order == GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN) + if (format->scanline_order == GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN) transform |= GLITZ_TRANSFORM_SCANLINE_ORDER_MASK; /* find direct format */ - format = _glitz_find_gl_pixel_format (&buffer->format); - if (format == NULL) { + gl_format = _glitz_find_gl_pixel_format (format); + if (gl_format == NULL) { transform |= GLITZ_TRANSFORM_PIXELS_MASK; - format = _glitz_best_gl_pixel_format (src->format); + gl_format = _glitz_best_gl_pixel_format (src->format); } if (transform) { @@ -875,7 +625,7 @@ glitz_get_pixels (glitz_surface_t *src, src_y = y_src; } - stride = (((src_w * format->pixel.masks.bpp) / 8) + 3) & -4; + stride = (((src_w * gl_format->pixel.masks.bpp) / 8) + 3) & -4; data = malloc (stride * src_h); if (!data) { @@ -886,10 +636,10 @@ glitz_get_pixels (glitz_surface_t *src, xoffset = 0; bytes_per_line = stride; } else { - xoffset = buffer->format.xoffset; - bytes_per_line = buffer->format.bytes_per_line; - pixels = glitz_pixel_buffer_bind (buffer, GLITZ_GL_PIXEL_PACK_BUFFER); - pixels += buffer->format.skip_lines * bytes_per_line; + xoffset = format->xoffset; + bytes_per_line = format->bytes_per_line; + pixels = glitz_buffer_bind (buffer, GLITZ_GL_PIXEL_PACK_BUFFER); + pixels += format->skip_lines * bytes_per_line; } gl->pixel_store_i (GLITZ_GL_PACK_ROW_LENGTH, 0); @@ -911,12 +661,12 @@ glitz_get_pixels (glitz_surface_t *src, if (from_drawable) { gl->read_pixels (x_src, src->height - y_src - height, width, height, - format->format, format->type, + gl_format->format, gl_format->type, pixels); } else { glitz_texture_bind (gl, texture); gl->get_tex_image (texture->target, 0, - format->format, format->type, + gl_format->format, gl_format->type, pixels); glitz_texture_unbind (gl, texture); } @@ -924,17 +674,14 @@ glitz_get_pixels (glitz_surface_t *src, if (transform) { glitz_image_t src_image, dst_image; - src_image.data = data + src_y * format->pixel.bytes_per_line; - src_image.format = &format->pixel; + src_image.data = data + src_y * gl_format->pixel.bytes_per_line; + src_image.format = &gl_format->pixel; src_image.width = src_w; src_image.height = src_h; - dst_image.data = - glitz_pixel_buffer_get_data (buffer, - GLITZ_PIXEL_BUFFER_ACCESS_WRITE_ONLY); - dst_image.data += buffer->format.skip_lines * - buffer->format.bytes_per_line; - dst_image.format = &buffer->format; + dst_image.data = glitz_buffer_map (buffer, GLITZ_BUFFER_ACCESS_WRITE_ONLY); + dst_image.data += format->skip_lines * format->bytes_per_line; + dst_image.format = format; dst_image.width = width; dst_image.height = height; @@ -942,12 +689,12 @@ glitz_get_pixels (glitz_surface_t *src, &src_image, &dst_image, src_x, - buffer->format.xoffset, + format->xoffset, width, height); - glitz_pixel_buffer_put_back_data (buffer); + glitz_buffer_unmap (buffer); } else - glitz_pixel_buffer_unbind (buffer); + glitz_buffer_unbind (buffer); glitz_surface_pop_current (src); diff --git a/src/glitz_program.c b/src/glitz_program.c index 23f89d2..885d65b 100644 --- a/src/glitz_program.c +++ b/src/glitz_program.c @@ -38,35 +38,23 @@ #define EXPAND_NO_IN_OP \ "MUL result.color, color, fragment.color.a;" -#define EXPAND_SRC_DECL "TEMP src_pos, src;" +#define EXPAND_SRC_DECL "TEMP src;" #define EXPAND_SRC_2D_IN_OP \ - "DP4 src_pos.x, state.matrix.texture[1].row[0], fragment.texcoord[1];" \ - "DP4 src_pos.y, state.matrix.texture[1].row[1], fragment.texcoord[1];" \ - "DP4 src_pos.w, state.matrix.texture[1].row[3], fragment.texcoord[1];" \ - "TXP src, src_pos, texture[1], 2D;" \ + "TXP src, fragment.texcoord[1], texture[1], 2D;" \ "DP4 color.a, color, fragment.color;" \ "MUL result.color, src, color.a;" #define EXPAND_SRC_RECT_IN_OP \ - "DP4 src_pos.x, state.matrix.texture[1].row[0], fragment.texcoord[1];" \ - "DP4 src_pos.y, state.matrix.texture[1].row[1], fragment.texcoord[1];" \ - "DP4 src_pos.w, state.matrix.texture[1].row[3], fragment.texcoord[1];" \ - "TEX src, fragment.texcoord[1], texture[1], RECT;" \ + "TXP src, fragment.texcoord[1], texture[1], RECT;" \ "DP4 color.a, color, fragment.color;" \ "MUL result.color, src, color.a;" -#define EXPAND_MASK_DECL "TEMP mask_pos, mask;" +#define EXPAND_MASK_DECL "TEMP mask;" #define EXPAND_MASK_2D_IN_OP \ - "DP4 mask_pos.x, state.matrix.texture[0].row[0], fragment.texcoord[0];" \ - "DP4 mask_pos.y, state.matrix.texture[0].row[1], fragment.texcoord[0];" \ - "DP4 mask_pos.w, state.matrix.texture[0].row[3], fragment.texcoord[0];" \ - "TXP mask, mask_pos, texture[0], 2D;" \ + "TXP mask, fragment.texcoord[0], texture[0], 2D;" \ "DP4 mask.a, mask, fragment.color;" \ "MUL result.color, color, mask.a;" #define EXPAND_MASK_RECT_IN_OP \ - "DP4 mask_pos.x, state.matrix.texture[0].row[0], fragment.texcoord[0];" \ - "DP4 mask_pos.y, state.matrix.texture[0].row[1], fragment.texcoord[0];" \ - "DP4 mask_pos.w, state.matrix.texture[0].row[3], fragment.texcoord[0];" \ "TXP mask, fragment.texcoord[0], texture[0], RECT;" \ "DP4 mask.a, mask, fragment.color;" \ "MUL result.color, color, mask.a;" @@ -111,48 +99,31 @@ static const struct _glitz_program_expand_t { }; /* - * minimum vertex program - */ -static const char *_vertex_program[] = { - "!!ARBvp1.0", - "OPTION ARB_position_invariant;", - "MOV result.texcoord[0], vertex.texcoord[0];", - "MOV result.texcoord[1], vertex.texcoord[1];", - "MOV result.color, vertex.color;", - "END", NULL -}; - -/* * general convolution filter (projective transformations might not * produce correct results). */ static const char *_convolution_header[] = { "!!ARBfp1.0", "PARAM p[%d] = { program.local[0..%d] };", - "PARAM m[4] = { state.matrix.texture[%s].row[0..3] };", "ATTRIB pos = fragment.texcoord[%s];", - "TEMP color, in, coord, position;", + "TEMP color, in, coord;", /* extra declerations */ "%s" - /* projective transform */ - "DP4 position.x, m[0], pos;", - "DP4 position.y, m[1], pos;", - "DP4 position.w, m[3], pos;", - "MOV coord, position;", NULL + "MOV coord, pos;", NULL }; static const char *_convolution_sample_first[] = { - "ADD coord.x, position.x, p[0].x;", - "ADD coord.y, position.y, p[0].y;", + "ADD coord.x, pos.x, p[0].x;", + "ADD coord.y, pos.y, p[0].y;", "TXP in, coord, texture[%s], %s;", "MUL color, in, p[0].z;", NULL }; static const char *_convolution_sample[] = { - "ADD coord.x, position.x, p[%d].x;", - "ADD coord.y, position.y, p[%d].y;", + "ADD coord.x, pos.x, p[%d].x;", + "ADD coord.y, pos.y, p[%d].y;", "TXP in, coord, texture[%s], %s;", "MAD color, in, p[%d].z, color;", NULL }; @@ -165,16 +136,11 @@ static const char *_gradient_header[] = { "!!ARBfp1.0", "PARAM gradient = program.local[0];", "PARAM stops[%d] = { program.local[1..%d] };", - "PARAM m[2] = { state.matrix.texture[%s].row[0..1] };", "ATTRIB pos = fragment.texcoord[%s];", "TEMP color, second_color, stop0, stop1, position;", /* extra declerations */ - "%s", - - /* affine transform */ - "DP4 position.x, m[0], pos;", - "DP4 position.y, m[1], pos;", NULL + "%s", NULL }; /* @@ -182,12 +148,12 @@ static const char *_gradient_header[] = { * * gradient.x = start offset * gradient.y = 1 / length - * gradient.z = sin (angle) - * gradient.w = cos (angle) + * gradient.z = cos (angle) + * gradient.w = -sin (angle) */ static const char *_linear_gradient_calculations[] = { - "MUL position.x, gradient.z, position.x;", - "MAD position.x, gradient.w, position.y, position.x;", + "MUL position.x, gradient.z, pos.x;", + "MAD position.x, gradient.w, pos.y, position.x;", "SUB position.z, position.x, gradient.x;", "MUL position.z, position.z, gradient.y;", NULL }; @@ -201,7 +167,7 @@ static const char *_linear_gradient_calculations[] = { * gradient.w = 1 / (radius1 - radius0) */ static const char *_radial_gradient_calculations[] = { - "SUB position, position, gradient;", + "SUB position, pos, gradient;", "MUL position.x, position.x, position.x;", "MAD position.x, position.y, position.y, position.x;", "RSQ position.y, position.x;", @@ -256,46 +222,6 @@ static const char *_gradient_fetch_and_interpolate[] = { }; static glitz_gl_int_t -_glitz_compile_arb_vertex_program (glitz_gl_proc_address_list_t *gl, - char *program_string) -{ - glitz_gl_int_t error, pid = -1; - glitz_gl_uint_t value, program; - - gl->enable (GLITZ_GL_VERTEX_PROGRAM); - - gl->gen_programs (1, &program); - gl->bind_program (GLITZ_GL_VERTEX_PROGRAM, program); - gl->program_string (GLITZ_GL_VERTEX_PROGRAM, - GLITZ_GL_PROGRAM_FORMAT_ASCII, - strlen (program_string), - program_string); - - gl->get_integer_v (GLITZ_GL_PROGRAM_ERROR_POSITION, &error); - if (error == -1) { - gl->get_program_iv (GLITZ_GL_VERTEX_PROGRAM, - GLITZ_GL_PROGRAM_NATIVE_INSTRUCTIONS, - &value); - if (value > 0) { - gl->get_program_iv (GLITZ_GL_VERTEX_PROGRAM, - GLITZ_GL_PROGRAM_UNDER_NATIVE_LIMITS, - &value); - if (value == GLITZ_GL_TRUE) - pid = program; - } - } - - if (pid == -1) { - gl->bind_program (GLITZ_GL_VERTEX_PROGRAM, 0); - gl->delete_programs (1, &program); - } - - gl->disable (GLITZ_GL_VERTEX_PROGRAM); - - return pid; -} - -static glitz_gl_int_t _glitz_compile_arb_fragment_program (glitz_gl_proc_address_list_t *gl, char *program_string) { @@ -348,16 +274,6 @@ _string_array_to_char_array (char *dst, const char *src[]) *dst = '\0'; } -static glitz_gl_uint_t -_glitz_create_vertex_program (glitz_composite_op_t *op) -{ - char program[512]; - - _string_array_to_char_array (program, _vertex_program); - - return _glitz_compile_arb_vertex_program (op->gl, program); -} - /* these should be more than enough */ #define CONVOLUTION_BASE_SIZE 2048 #define CONVOLUTION_SAMPLE_SIZE 256 @@ -398,7 +314,7 @@ _glitz_create_fragment_program (glitz_composite_op_t *op, p = program; _string_array_to_char_array (buffer, _convolution_header); - p += sprintf (p, buffer, id, id - 1, tex, tex, expand->declarations); + p += sprintf (p, buffer, id, id - 1, tex, expand->declarations); _string_array_to_char_array (buffer, _convolution_sample_first); p += sprintf (p, buffer, tex, expand->texture); @@ -425,7 +341,7 @@ _glitz_create_fragment_program (glitz_composite_op_t *op, p = program; _string_array_to_char_array (buffer, _gradient_header); - p += sprintf (p, buffer, id, id, tex, tex, expand->declarations); + p += sprintf (p, buffer, id, id, tex, expand->declarations); switch (fp_type) { case GLITZ_FP_LINEAR_GRADIENT_TRANSPARENT: @@ -519,11 +435,6 @@ glitz_program_map_fini (glitz_gl_proc_address_list_t *gl, } } } - - if (map->vp > 0) { - program = map->vp; - gl->delete_programs (1, &program); - } } #define TEXTURE_INDEX(surface) \ @@ -536,25 +447,6 @@ glitz_program_map_fini (glitz_gl_proc_address_list_t *gl, ) glitz_gl_uint_t -glitz_get_vertex_program (glitz_composite_op_t *op) -{ - glitz_gl_int_t *program; - - program = &op->dst->program_map->vp; - - if (*program == 0) { - glitz_surface_push_current (op->dst, GLITZ_CN_SURFACE_CONTEXT_CURRENT); - *program = _glitz_create_vertex_program (op); - glitz_surface_pop_current (op->dst); - } - - if (*program > 0) - return *program; - else - return 0; -} - -glitz_gl_uint_t glitz_get_fragment_program (glitz_composite_op_t *op, int fp_type, int id) @@ -563,7 +455,8 @@ glitz_get_fragment_program (glitz_composite_op_t *op, int t0 = TEXTURE_INDEX (op->src); int t1 = TEXTURE_INDEX (op->mask); - program = &op->dst->program_map->filters[op->type][fp_type].fp[t0][t1]; + program = + &op->dst->backend->program_map->filters[op->type][fp_type].fp[t0][t1]; if (program->size < id) { int old_size; diff --git a/src/glitz_rect.c b/src/glitz_rect.c index 7480cf6..e9b556e 100644 --- a/src/glitz_rect.c +++ b/src/glitz_rect.c @@ -1,28 +1,26 @@ /* - * Copyright © 2004 David Reveman, Peter Nilsson - * + * Copyright © 2004 David Reveman + * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without * fee, provided that the above copyright notice appear in all copies * and that both that copyright notice and this permission notice * appear in supporting documentation, and that the names of - * David Reveman and Peter Nilsson not be used in advertising or - * publicity pertaining to distribution of the software without - * specific, written prior permission. David Reveman and Peter Nilsson - * makes no representations about the suitability of this software for - * any purpose. It is provided "as is" without express or implied warranty. + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. * - * DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND - * PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA - * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * Authors: David Reveman <c99drn@cs.umu.se> - * Peter Nilsson <c99pnn@cs.umu.se> + * Author: David Reveman <c99drn@cs.umu.se> */ #ifdef HAVE_CONFIG_H @@ -38,10 +36,8 @@ dst) static void -glitz_rectangle_bounds (int x_offset, - int y_offset, +glitz_rectangle_bounds (const glitz_rectangle_t *rects, int n_rects, - const glitz_rectangle_t *rects, glitz_bounding_box_t *box) { box->x1 = MAXSHORT; @@ -59,165 +55,111 @@ glitz_rectangle_bounds (int x_offset, else if ((rects->y + rects->height) > box->y2) box->y2 = rects->y + rects->height; } - - box->x1 += x_offset; - box->x2 += x_offset; - box->y1 += y_offset; - box->y2 += y_offset; } void -glitz_int_fill_rectangles (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_rectangle_t *rects, - int n_rects) +glitz_set_rectangles (glitz_surface_t *dst, + const glitz_color_t *color, + const glitz_rectangle_t *rects, + int n_rects) { - glitz_gl_proc_address_list_t *gl = dst->gl; - glitz_gl_bitfield_t clear_mask; + glitz_bounding_box_t bounds; + glitz_gl_proc_address_list_t *gl = &dst->backend->gl; + + glitz_rectangle_bounds (rects, n_rects, &bounds); + if (bounds.x1 > dst->width || bounds.y1 > dst->height || + bounds.x2 < 0 || bounds.y2 < 0) + return; + + if (SURFACE_SOLID (dst) && SURFACE_OFFSCREEN (dst) && + (bounds.x2 - bounds.x1) > 0 && (bounds.y2 - bounds.y1) > 0) { + STORE_16 (dst->solid.red, dst->format->red_size, color->red); + STORE_16 (dst->solid.green, dst->format->green_size, color->green); + STORE_16 (dst->solid.blue, dst->format->blue_size, color->blue); + STORE_16 (dst->solid.alpha, dst->format->alpha_size, color->alpha); + + dst->flags |= GLITZ_FLAG_DRAWABLE_DIRTY_MASK; + return; + } - if (op == GLITZ_OPERATOR_SRC && (!*dst->stencil_mask)) { - clear_mask = GLITZ_GL_COLOR_BUFFER_BIT; + if (glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { gl->clear_color (color->red / (glitz_gl_clampf_t) 0xffff, color->green / (glitz_gl_clampf_t) 0xffff, color->blue / (glitz_gl_clampf_t) 0xffff, color->alpha / (glitz_gl_clampf_t) 0xffff); - } else if (op == (glitz_operator_t) GLITZ_INT_OPERATOR_STENCIL_RECT_SET) { - clear_mask = GLITZ_GL_STENCIL_BUFFER_BIT; - gl->clear_stencil (*dst->stencil_mask); - } else { - if (op == (glitz_operator_t) GLITZ_INT_OPERATOR_STENCIL_RECT_SRC) - op = GLITZ_OPERATOR_SRC; - - clear_mask = 0x0; - } - - if (clear_mask) { + for (; n_rects; n_rects--, rects++) { - gl->enable (GLITZ_GL_SCISSOR_TEST); - gl->scissor (x_offset + rects->x, - dst->height - (y_offset + rects->y + rects->height), + gl->scissor (rects->x, + dst->height - rects->y - rects->height, rects->width, rects->height); - gl->clear (clear_mask); + gl->clear (GLITZ_GL_COLOR_BUFFER_BIT); } - dst->update_mask |= GLITZ_UPDATE_SCISSOR_MASK; + glitz_surface_dirty (dst, &bounds); } else { - glitz_gl_vertex_2i_t vertex_2i = gl->vertex_2i; - - gl->color_4us (color->red, color->green, color->blue, color->alpha); - - glitz_set_operator (gl, op); - - gl->begin (GLITZ_GL_QUADS); - - for (; n_rects; n_rects--, rects++) { - vertex_2i (x_offset + rects->x, y_offset + rects->y); - vertex_2i (x_offset + rects->x + rects->width, y_offset + rects->y); - vertex_2i (x_offset + rects->x + rects->width, - y_offset + rects->y + rects->height); - vertex_2i (x_offset + rects->x, y_offset + rects->y + rects->height); + static glitz_pixel_format_t pf = { + { + 32, + 0xff000000, + 0x00ff0000, + 0x0000ff00, + 0x000000ff + }, + 0, 0, 0, + GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP + }; + glitz_buffer_t *buffer; + unsigned int size, pixel, *p; + + size = (bounds.x2 - bounds.x1) * (bounds.y2 - bounds.y1); + buffer = + glitz_pixel_buffer_create (dst, + NULL, + size * 4, + GLITZ_BUFFER_HINT_STREAM_DRAW); + if (!buffer) { + glitz_surface_status_add (dst, GLITZ_STATUS_NO_MEMORY_MASK); + return; } - - gl->end (); - } -} + + pixel = + ((((unsigned int) color->red * 0xff) / 0xffff) << 24) | + ((((unsigned int) color->green * 0xff) / 0xffff) << 16) | + ((((unsigned int) color->blue * 0xff) / 0xffff) << 8) | + ((((unsigned int) color->alpha * 0xff) / 0xffff)); + + p = glitz_buffer_map (buffer, GLITZ_BUFFER_ACCESS_WRITE_ONLY); + + for (; size; size--, p++) + *p = pixel; + + glitz_buffer_unmap (buffer); -/* This is a hack that allows drawing with GLITZ_OPERATOR_SRC - to all solid surfaces (1x1 surfaces) just by scaling the color - to the appropriate format and storing it in the surface's solid - color. */ -static void -_glitz_fill_solid (glitz_surface_t *dst, - const glitz_color_t *color) -{ - STORE_16 (dst->solid.red, dst->format->red_size, color->red); - STORE_16 (dst->solid.green, dst->format->green_size, color->green); - STORE_16 (dst->solid.blue, dst->format->blue_size, color->blue); - STORE_16 (dst->solid.alpha, dst->format->alpha_size, color->alpha); + for (; n_rects; n_rects--, rects++) + glitz_set_pixels (dst, + rects->x, rects->y, + rects->width, rects->height, + &pf, buffer); + } - dst->hint_mask |= GLITZ_INT_HINT_DRAWABLE_DIRTY_MASK; + glitz_surface_pop_current (dst); } void -glitz_fill_rectangle (glitz_operator_t op, - glitz_surface_t *dst, - const glitz_color_t *color, - int x, - int y, - unsigned int width, - unsigned int height) +glitz_set_rectangle (glitz_surface_t *dst, + const glitz_color_t *color, + int x, + int y, + unsigned int width, + unsigned int height) { - glitz_bounding_box_t bounds; glitz_rectangle_t rect; - bounds.x1 = x; - bounds.x2 = x + width; - bounds.y1 = y; - bounds.y2 = y + height; - if (bounds.x1 > dst->width || bounds.y1 > dst->height || - bounds.x2 < 0 || bounds.y2 < 0) - return; - - if (SURFACE_SOLID (dst) && SURFACE_OFFSCREEN (dst) && - op == GLITZ_OPERATOR_SRC && width > 0 && height > 0) { - _glitz_fill_solid (dst, color); - return; - } - rect.x = x; rect.y = y; rect.width = width; rect.height = height; - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - glitz_int_fill_rectangles (op, dst, 0, 0, color, &rect, 1); - - glitz_surface_dirty (dst, &bounds); - glitz_surface_pop_current (dst); -} -slim_hidden_def(glitz_fill_rectangle); - -void -glitz_fill_rectangles (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_rectangle_t *rects, - int n_rects) -{ - glitz_bounding_box_t bounds; - - glitz_rectangle_bounds (x_offset, y_offset, n_rects, rects, &bounds); - if (bounds.x1 > dst->width || bounds.y1 > dst->height || - bounds.x2 < 0 || bounds.y2 < 0) - return; - - if (SURFACE_SOLID (dst) && SURFACE_OFFSCREEN (dst) && - op == GLITZ_OPERATOR_SRC && - (bounds.x2 - bounds.x1) > 0 && (bounds.y2 - bounds.y1) > 0) { - _glitz_fill_solid (dst, color); - return; - } - - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - glitz_int_fill_rectangles (op, dst, x_offset, y_offset, - color, rects, n_rects); - - glitz_surface_dirty (dst, &bounds); - glitz_surface_pop_current (dst); + glitz_set_rectangles (dst, color, &rect, 1); } -slim_hidden_def(glitz_fill_rectangles); +slim_hidden_def(glitz_set_rectangle); diff --git a/src/glitz_status.c b/src/glitz_status.c index 7c4ab72..364960b 100644 --- a/src/glitz_status.c +++ b/src/glitz_status.c @@ -37,14 +37,12 @@ glitz_status_to_status_mask (glitz_status_t status) switch (status) { case GLITZ_STATUS_NO_MEMORY: return GLITZ_STATUS_NO_MEMORY_MASK; - case GLITZ_STATUS_NULL_POINTER: - return GLITZ_STATUS_NULL_POINTER_MASK; case GLITZ_STATUS_BAD_COORDINATE: return GLITZ_STATUS_BAD_COORDINATE_MASK; case GLITZ_STATUS_NOT_SUPPORTED: return GLITZ_STATUS_NOT_SUPPORTED_MASK; - case GLITZ_STATUS_INVALID_MATRIX: - return GLITZ_STATUS_INVALID_MATRIX_MASK; + case GLITZ_STATUS_CONTENT_DESTROYED: + return GLITZ_STATUS_CONTENT_DESTROYED_MASK; case GLITZ_STATUS_SUCCESS: break; } @@ -58,19 +56,16 @@ glitz_status_pop_from_mask (unsigned long *mask) if (*mask & GLITZ_STATUS_NO_MEMORY_MASK) { *mask &= ~GLITZ_STATUS_NO_MEMORY_MASK; return GLITZ_STATUS_NO_MEMORY; - } else if (*mask & GLITZ_STATUS_NULL_POINTER_MASK) { - *mask &= ~GLITZ_STATUS_NULL_POINTER_MASK; - return GLITZ_STATUS_NULL_POINTER; } else if (*mask & GLITZ_STATUS_BAD_COORDINATE_MASK) { *mask &= ~GLITZ_STATUS_BAD_COORDINATE_MASK; return GLITZ_STATUS_BAD_COORDINATE; } else if (*mask & GLITZ_STATUS_NOT_SUPPORTED_MASK) { *mask &= ~GLITZ_STATUS_NOT_SUPPORTED_MASK; return GLITZ_STATUS_NOT_SUPPORTED; - } else if (*mask & GLITZ_STATUS_INVALID_MATRIX_MASK) { - *mask &= ~GLITZ_STATUS_INVALID_MATRIX_MASK; - return GLITZ_STATUS_INVALID_MATRIX; - } + } else if (*mask & GLITZ_STATUS_CONTENT_DESTROYED_MASK) { + *mask &= ~GLITZ_STATUS_CONTENT_DESTROYED_MASK; + return GLITZ_STATUS_CONTENT_DESTROYED; + } return GLITZ_STATUS_SUCCESS; } @@ -83,14 +78,12 @@ glitz_status_string (glitz_status_t status) return "success"; case GLITZ_STATUS_NO_MEMORY: return "out of memory"; - case GLITZ_STATUS_NULL_POINTER: - return "NULL pointer"; case GLITZ_STATUS_BAD_COORDINATE: return "bad coordinate"; case GLITZ_STATUS_NOT_SUPPORTED: return "not supported"; - case GLITZ_STATUS_INVALID_MATRIX: - return "invalid matrix"; + case GLITZ_STATUS_CONTENT_DESTROYED: + return "content destroyed"; } return "<unknown error status>"; diff --git a/src/glitz_stencil.c b/src/glitz_stencil.c deleted file mode 100644 index f32fa70..0000000 --- a/src/glitz_stencil.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright © 2004 David Reveman, Peter Nilsson - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the names of - * David Reveman and Peter Nilsson not be used in advertising or - * publicity pertaining to distribution of the software without - * specific, written prior permission. David Reveman and Peter Nilsson - * makes no representations about the suitability of this software for - * any purpose. It is provided "as is" without express or implied warranty. - * - * DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND - * PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA - * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * Author: David Reveman <c99drn@cs.umu.se> - */ - -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif - -#include "glitzint.h" - -void -glitz_stencil_rectangles (glitz_stencil_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_rectangle_t *rects, - int n_rects) -{ - static glitz_color_t color = { 0x0000, 0x0000, 0x0000, 0x0000 }; - glitz_operator_t rect_op; - - if (n_rects == 0) - return; - - if (dst->format->stencil_size < 1) - return; - - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - rect_op = (glitz_operator_t) GLITZ_INT_OPERATOR_STENCIL_RECT_SRC; - - switch (op) { - case GLITZ_STENCIL_OPERATOR_CLEAR: - rect_op = (glitz_operator_t) GLITZ_INT_OPERATOR_STENCIL_RECT_SET; - break; - case GLITZ_STENCIL_OPERATOR_DECR_LESS: - *dst->stencil_mask &= (1 << (dst->format->stencil_size - 1)); - glitz_set_stencil_operator (dst->gl, op, *dst->stencil_mask); - break; - case GLITZ_STENCIL_OPERATOR_INTERSECT: - glitz_set_stencil_operator (dst->gl, GLITZ_STENCIL_OPERATOR_INCR_EQUAL, - *dst->stencil_mask); - break; - case GLITZ_STENCIL_OPERATOR_SET: - case GLITZ_STENCIL_OPERATOR_UNION: - *dst->stencil_mask = 1 << (dst->format->stencil_size - 1); - rect_op = (glitz_operator_t) GLITZ_INT_OPERATOR_STENCIL_RECT_SET; - /* fall-through */ - default: - glitz_set_stencil_operator (dst->gl, op, *dst->stencil_mask); - break; - } - - dst->gl->color_mask (0, 0, 0, 0); - - glitz_int_fill_rectangles (rect_op, - dst, - x_offset, - y_offset, - &color, - rects, - n_rects); - - if (op == GLITZ_STENCIL_OPERATOR_INTERSECT) { - glitz_rectangle_t rect; - - rect.x = rect.y = 0; - rect.width = dst->width; - rect.height = dst->height; - - glitz_set_stencil_operator (dst->gl, GLITZ_STENCIL_OPERATOR_INTERSECT, - *dst->stencil_mask); - glitz_int_fill_rectangles (GLITZ_INT_OPERATOR_STENCIL_RECT_SRC, - dst, 0, 0, &color, &rect, 1); - } else if (op == GLITZ_STENCIL_OPERATOR_INCR_EQUAL) - *dst->stencil_mask |= 0x1; - - dst->gl->color_mask (1, 1, 1, 1); - - dst->update_mask |= GLITZ_UPDATE_STENCIL_OP_MASK; - - glitz_surface_pop_current (dst); -} - -void -glitz_stencil_trapezoids (glitz_stencil_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_trapezoid_t *traps, - int n_traps) -{ - static glitz_color_t color = { 0x0000, 0x0000, 0x0000, 0x0000 }; - - if (n_traps == 0) - return; - - if (dst->format->stencil_size < 1) - return; - - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - switch (op) { - case GLITZ_STENCIL_OPERATOR_DECR_LESS: - *dst->stencil_mask &= (1 << (dst->format->stencil_size - 1)); - glitz_set_stencil_operator (dst->gl, op, *dst->stencil_mask); - break; - case GLITZ_STENCIL_OPERATOR_INTERSECT: - glitz_set_stencil_operator (dst->gl, GLITZ_STENCIL_OPERATOR_INCR_EQUAL, - *dst->stencil_mask); - break; - case GLITZ_STENCIL_OPERATOR_SET: - case GLITZ_STENCIL_OPERATOR_UNION: - *dst->stencil_mask = 1 << (dst->format->stencil_size - 1); - /* fall-through */ - default: - glitz_set_stencil_operator (dst->gl, op, *dst->stencil_mask); - break; - } - - dst->gl->color_mask (0, 0, 0, 0); - - glitz_int_fill_trapezoids (GLITZ_OPERATOR_SRC, - dst, - x_offset, y_offset, - &color, - traps, - n_traps); - - if (op == GLITZ_STENCIL_OPERATOR_INTERSECT) { - glitz_rectangle_t rect; - - rect.x = rect.y = 0; - rect.width = dst->width; - rect.height = dst->height; - - glitz_set_stencil_operator (dst->gl, GLITZ_STENCIL_OPERATOR_INTERSECT, - *dst->stencil_mask); - glitz_int_fill_rectangles (GLITZ_INT_OPERATOR_STENCIL_RECT_SRC, - dst, 0, 0, &color, &rect, 1); - } else if (op == GLITZ_STENCIL_OPERATOR_INCR_EQUAL) - *dst->stencil_mask |= 0x1; - - dst->gl->color_mask (1, 1, 1, 1); - - dst->update_mask |= GLITZ_UPDATE_STENCIL_OP_MASK; - - glitz_surface_pop_current (dst); -} - -void -glitz_stencil_triangles (glitz_stencil_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - glitz_triangle_type_t type, - const glitz_point_fixed_t *points, - int n_points) -{ - static glitz_color_t color = { 0x0000, 0x0000, 0x0000, 0x0000 }; - - if (n_points < 3) - return; - - if (dst->format->stencil_size < 1) - return; - - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - switch (op) { - case GLITZ_STENCIL_OPERATOR_DECR_LESS: - *dst->stencil_mask &= (1 << (dst->format->stencil_size - 1)); - glitz_set_stencil_operator (dst->gl, op, *dst->stencil_mask); - break; - case GLITZ_STENCIL_OPERATOR_INTERSECT: - glitz_set_stencil_operator (dst->gl, GLITZ_STENCIL_OPERATOR_INCR_EQUAL, - *dst->stencil_mask); - break; - case GLITZ_STENCIL_OPERATOR_SET: - case GLITZ_STENCIL_OPERATOR_UNION: - *dst->stencil_mask = 1 << (dst->format->stencil_size - 1); - /* fall-through */ - default: - glitz_set_stencil_operator (dst->gl, op, *dst->stencil_mask); - break; - } - - dst->gl->color_mask (0, 0, 0, 0); - - glitz_int_fill_triangles (GLITZ_OPERATOR_SRC, - dst, - type, - x_offset, y_offset, - &color, - points, - n_points); - - if (op == GLITZ_STENCIL_OPERATOR_INTERSECT) { - glitz_rectangle_t rect; - - rect.x = rect.y = 0; - rect.width = dst->width; - rect.height = dst->height; - - glitz_set_stencil_operator (dst->gl, GLITZ_STENCIL_OPERATOR_INTERSECT, - *dst->stencil_mask); - glitz_int_fill_rectangles (GLITZ_INT_OPERATOR_STENCIL_RECT_SRC, - dst, 0, 0, &color, &rect, 1); - } else if (op == GLITZ_STENCIL_OPERATOR_INCR_EQUAL) - *dst->stencil_mask |= 0x1; - - dst->gl->color_mask (1, 1, 1, 1); - - dst->update_mask |= GLITZ_UPDATE_STENCIL_OP_MASK; - - glitz_surface_pop_current (dst); -} diff --git a/src/glitz_surface.c b/src/glitz_surface.c index 20027dd..a95a61c 100644 --- a/src/glitz_surface.c +++ b/src/glitz_surface.c @@ -1,28 +1,26 @@ /* - * Copyright © 2004 David Reveman, Peter Nilsson - * + * Copyright © 2004 David Reveman + * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without * fee, provided that the above copyright notice appear in all copies * and that both that copyright notice and this permission notice * appear in supporting documentation, and that the names of - * David Reveman and Peter Nilsson not be used in advertising or - * publicity pertaining to distribution of the software without - * specific, written prior permission. David Reveman and Peter Nilsson - * makes no representations about the suitability of this software for - * any purpose. It is provided "as is" without express or implied warranty. + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. * - * DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND - * PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA - * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * Authors: David Reveman <c99drn@cs.umu.se> - * Peter Nilsson <c99pnn@cs.umu.se> + * Author: David Reveman <c99drn@cs.umu.se> */ #ifdef HAVE_CONFIG_H @@ -36,14 +34,10 @@ void glitz_surface_init (glitz_surface_t *surface, - const glitz_surface_backend_t *backend, - glitz_gl_proc_address_list_t *gl, + glitz_surface_backend_t *backend, glitz_format_t *format, - glitz_format_t *formats, - int n_formats, int width, int height, - glitz_program_map_t *program_map, unsigned long texture_mask) { surface->backend = backend; @@ -51,20 +45,20 @@ glitz_surface_init (glitz_surface_t *surface, surface->ref_count = 1; surface->filter = GLITZ_FILTER_NEAREST; - surface->polyedge = GLITZ_POLYEDGE_SMOOTH; - surface->polyedge_smooth_hint = GLITZ_POLYEDGE_SMOOTH_HINT_GOOD; - surface->polyopacity = 0xffff; - surface->program_map = program_map; surface->format = format; - surface->formats = formats; - surface->n_formats = n_formats; surface->width = width; surface->height = height; - surface->gl = gl; - surface->stencil_mask = surface->stencil_masks; surface->update_mask = GLITZ_UPDATE_ALL_MASK; - surface->hint_mask |= GLITZ_INT_HINT_CLIP_MASK; + + surface->geometry.data[0] = 0.0f; + surface->geometry.data[1] = 0.0f; + surface->geometry.data[2] = (glitz_float_t) width; + surface->geometry.data[3] = 0.0f; + surface->geometry.data[4] = (glitz_float_t) width; + surface->geometry.data[5] = (glitz_float_t) height; + surface->geometry.data[6] = 0.0f; + surface->geometry.data[7] = (glitz_float_t) height; if (format->doublebuffer) surface->draw_buffer = surface->read_buffer = GLITZ_GL_BACK; @@ -72,14 +66,17 @@ glitz_surface_init (glitz_surface_t *surface, surface->draw_buffer = surface->read_buffer = GLITZ_GL_FRONT; if (width == 1 && height == 1) { - surface->hint_mask |= GLITZ_INT_HINT_SOLID_MASK; + surface->flags |= GLITZ_FLAG_SOLID_MASK; surface->solid.red = surface->solid.green = surface->solid.blue = 0x0; surface->solid.alpha = 0xffff; } + surface->flags |= GLITZ_FLAG_TEXTURE_COORDS_MASK; + glitz_texture_init (&surface->texture, width, height, - glitz_format_get_best_texture_format (formats, n_formats, + glitz_format_get_best_texture_format (backend->formats, + backend->n_formats, format), texture_mask); } @@ -89,7 +86,7 @@ glitz_surface_fini (glitz_surface_t *surface) { if (surface->texture.name) { glitz_surface_push_current (surface, GLITZ_CN_ANY_CONTEXT_CURRENT); - glitz_texture_fini (surface->gl, &surface->texture); + glitz_texture_fini (&surface->backend->gl, &surface->texture); glitz_surface_pop_current (surface); } @@ -98,6 +95,9 @@ glitz_surface_fini (glitz_surface_t *surface) if (surface->filter_params) glitz_filter_params_destroy (surface->filter_params); + + if (surface->geometry.default_name) + surface->backend->gl.delete_buffers (1, &surface->geometry.default_name); } glitz_format_t * @@ -105,7 +105,8 @@ glitz_surface_find_similar_standard_format (glitz_surface_t *surface, glitz_format_name_t format_name) { return - glitz_format_find_standard (surface->formats, surface->n_formats, + glitz_format_find_standard (surface->backend->formats, + surface->backend->n_formats, format_name); } slim_hidden_def(glitz_surface_find_similar_standard_format); @@ -116,7 +117,8 @@ glitz_surface_find_similar_format (glitz_surface_t *surface, const glitz_format_t *templ, int count) { - return glitz_format_find (surface->formats, surface->n_formats, + return glitz_format_find (surface->backend->formats, + surface->backend->n_formats, mask, templ, count); } @@ -126,18 +128,10 @@ glitz_surface_create_similar (glitz_surface_t *templ, int width, int height) { - glitz_surface_t *surface; - if (width < 1 || height < 1) return NULL; - surface = templ->backend->create_similar (templ, format, width, height); - if (surface) { - surface->polyedge = templ->polyedge; - surface->polyedge_smooth_hint = templ->polyedge_smooth_hint; - } - - return surface; + return templ->backend->create_similar (templ, format, width, height); } void @@ -164,7 +158,7 @@ glitz_surface_destroy (glitz_surface_t *surface) static void _glitz_surface_solid_store (glitz_surface_t *surface) { - glitz_gl_proc_address_list_t *gl = surface->gl; + glitz_gl_proc_address_list_t *gl = &surface->backend->gl; if (SURFACE_DRAWABLE (surface)) { gl->color_4us (surface->solid.red, @@ -172,20 +166,20 @@ _glitz_surface_solid_store (glitz_surface_t *surface) { surface->solid.blue, surface->solid.alpha); glitz_set_operator (gl, GLITZ_OPERATOR_SRC); - gl->begin (GLITZ_GL_QUADS); - gl->vertex_2i (0, 0); - gl->vertex_2i (1, 0); - gl->vertex_2i (1, 1); - gl->vertex_2i (0, 1); - gl->end (); + + glitz_geometry_enable_default (gl, surface); + + gl->draw_arrays (GLITZ_GL_QUADS, 0, 4); + + glitz_geometry_disable (gl, surface); } else { glitz_gl_float_t color[4]; if (surface->texture.allocated) { - color[0] = (glitz_gl_float_t) surface->solid.red / 65535.0; - color[1] = (glitz_gl_float_t) surface->solid.green / 65535.0; - color[2] = (glitz_gl_float_t) surface->solid.blue / 65535.0; - color[3] = (glitz_gl_float_t) surface->solid.alpha / 65535.0; + color[0] = surface->solid.red / 65535.0f; + color[1] = surface->solid.green / 65535.0f; + color[2] = surface->solid.blue / 65535.0f; + color[3] = surface->solid.alpha / 65535.0f; glitz_texture_bind (gl, &surface->texture); gl->tex_sub_image_2d (surface->texture.target, 0, 0, 0, 1, 1, @@ -193,32 +187,33 @@ _glitz_surface_solid_store (glitz_surface_t *surface) { glitz_texture_unbind (gl, &surface->texture); } } - surface->hint_mask &= ~GLITZ_INT_HINT_DRAWABLE_DIRTY_MASK; + surface->flags &= ~GLITZ_FLAG_DRAWABLE_DIRTY_MASK; } void glitz_surface_ensure_solid (glitz_surface_t *surface) { if (SURFACE_DIRTY (surface) || SURFACE_SOLID_DIRTY (surface)) { + glitz_gl_proc_address_list_t *gl = &surface->backend->gl; glitz_gl_float_t color[4]; glitz_texture_t *texture = glitz_surface_get_texture (surface, 0); if (texture) { - glitz_texture_bind (surface->gl, texture); - surface->gl->get_tex_image (texture->target, 0, - GLITZ_GL_RGBA, GLITZ_GL_FLOAT, color); - glitz_texture_unbind (surface->gl, texture); + glitz_texture_bind (gl, texture); + gl->get_tex_image (texture->target, 0, + GLITZ_GL_RGBA, GLITZ_GL_FLOAT, color); + glitz_texture_unbind (gl, texture); } else { - color[0] = color[1] = color[2] = 0.0; - color[3] = 1.0; + color[0] = color[1] = color[2] = 0.0f; + color[3] = 1.0f; } - surface->solid.red = color[0] * 65535.0; - surface->solid.green = color[1] * 65535.0; - surface->solid.blue = color[2] * 65535.0; - surface->solid.alpha = color[3] * 65535.0; + surface->solid.red = color[0] * 65535.0f; + surface->solid.green = color[1] * 65535.0f; + surface->solid.blue = color[2] * 65535.0f; + surface->solid.alpha = color[3] * 65535.0f; - surface->hint_mask &= ~GLITZ_INT_HINT_SOLID_DIRTY_MASK; + surface->flags &= ~GLITZ_FLAG_SOLID_DIRTY_MASK; } } @@ -258,53 +253,83 @@ glitz_surface_set_transform (glitz_surface_t *surface, transform = NULL; if (transform) { + glitz_gl_float_t *m, *t; + if (!surface->transform) { - surface->transform = malloc (sizeof (glitz_projective_transform_t)); + surface->transform = malloc (sizeof (glitz_matrix_t)); if (surface->transform == NULL) { glitz_surface_status_add (surface, GLITZ_STATUS_NO_MEMORY_MASK); return; } } + + m = surface->transform->m; + t = surface->transform->t; + + m[0] = FIXED_TO_FLOAT (transform->matrix[0][0]); + m[4] = FIXED_TO_FLOAT (transform->matrix[0][1]); + m[8] = 0.0f; + m[12] = FIXED_TO_FLOAT (transform->matrix[0][2]); + + m[1] = FIXED_TO_FLOAT (transform->matrix[1][0]); + m[5] = FIXED_TO_FLOAT (transform->matrix[1][1]); + m[9] = 0.0f; + m[13] = FIXED_TO_FLOAT (transform->matrix[1][2]); + + m[2] = 0.0f; + m[6] = 0.0f; + m[10] = 1.0f; + m[14] = 0.0f; - surface->transform->m[0] = FIXED_TO_DOUBLE (transform->matrix[0][0]); - surface->transform->m[1] = FIXED_TO_DOUBLE (transform->matrix[1][0]); - surface->transform->m[2] = 0.0; - surface->transform->m[3] = FIXED_TO_DOUBLE (transform->matrix[2][0]); + m[3] = FIXED_TO_FLOAT (transform->matrix[2][0]); + m[7] = FIXED_TO_FLOAT (transform->matrix[2][1]); + m[11] = 0.0f; + m[15] = FIXED_TO_FLOAT (transform->matrix[2][2]); - surface->transform->m[4] = FIXED_TO_DOUBLE (transform->matrix[0][1]); - surface->transform->m[5] = FIXED_TO_DOUBLE (transform->matrix[1][1]); - surface->transform->m[6] = 0.0; - surface->transform->m[7] = FIXED_TO_DOUBLE (transform->matrix[2][1]); - - surface->transform->m[8] = 0.0; - surface->transform->m[9] = 0.0; - surface->transform->m[10] = 1.0; - surface->transform->m[11] = 0.0; - - surface->transform->m[12] = FIXED_TO_DOUBLE (transform->matrix[0][2]); - surface->transform->m[13] = FIXED_TO_DOUBLE (transform->matrix[1][2]); - surface->transform->m[14] = 0.0; - surface->transform->m[15] = FIXED_TO_DOUBLE (transform->matrix[2][2]); - - /* XXX: Projective transformation matrix conversion to normalized + /* Projective transformation matrix conversion to normalized texture coordinates seems to be working fine. However, it would be good if someone could verify that this is actually a correct way for - doing this. */ - memcpy (surface->transform->m_norm, surface->transform->m, - 16 * sizeof (double)); - - surface->transform->m_norm[12] = - (surface->texture.texcoord_width / surface->width) * - surface->transform->m[12]; - surface->transform->m_norm[13] = - (surface->texture.texcoord_height / surface->height) * - surface->transform->m[13]; + doing this. + + We need to do we this: + + scale (IDENTITY, 0, -1) + translate (IDENTITY, 0, -texture_height) + multiply (TEXTURE_MATRIX, IDENTITY, MATRIX) + scale (TEXTURE_MATRIX, 0, -1) + translate (TEXTURE_MATRIX, 0, -texture_height) + + the following code does it pretty efficiently. */ + t[0] = m[0]; + t[4] = m[4]; + t[8] = 0.0f; + t[12] = surface->texture.texcoord_width_unit * m[12]; - surface->transform->m_norm[3] /= - (surface->texture.texcoord_width / surface->width); - surface->transform->m_norm[7] /= - (surface->texture.texcoord_height / surface->height); + t[3] = m[3] / surface->texture.texcoord_width_unit; + t[7] = m[7] / surface->texture.texcoord_height_unit; + t[11] = 0.0f; + t[15] = m[15]; + t[1] = surface->texture.texcoord_height * t[3] - m[1]; + t[5] = surface->texture.texcoord_height * t[7] - m[5]; + t[9] = 0.0f; + t[13] = surface->texture.texcoord_height * t[15] - + surface->texture.texcoord_height_unit * m[13]; + + t[2] = 0.0f; + t[6] = 0.0f; + t[10] = 1.0f; + t[14] = 0.0f; + + /* scale y = -1 */ + t[4] = -t[4]; + t[5] = -t[5]; + t[7] = -t[7]; + + /* translate y = -texture_height */ + t[12] -= t[4] * surface->texture.texcoord_height; + t[13] -= t[5] * surface->texture.texcoord_height; + t[15] -= t[7] * surface->texture.texcoord_height; } else { if (surface->transform) free (surface->transform); @@ -319,35 +344,25 @@ glitz_surface_set_fill (glitz_surface_t *surface, glitz_fill_t fill) { switch (fill) { - case GLITZ_FILL_CLIP: - surface->hint_mask |= GLITZ_INT_HINT_CLIP_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_PAD_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_REPEAT_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_MIRRORED_MASK; - break; case GLITZ_FILL_TRANSPARENT: - surface->hint_mask &= ~GLITZ_INT_HINT_REPEAT_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_MIRRORED_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_PAD_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_CLIP_MASK; + surface->flags &= ~GLITZ_FLAG_REPEAT_MASK; + surface->flags &= ~GLITZ_FLAG_MIRRORED_MASK; + surface->flags &= ~GLITZ_FLAG_PAD_MASK; break; case GLITZ_FILL_NEAREST: - surface->hint_mask &= ~GLITZ_INT_HINT_REPEAT_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_MIRRORED_MASK; - surface->hint_mask |= GLITZ_INT_HINT_PAD_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_CLIP_MASK; + surface->flags &= ~GLITZ_FLAG_REPEAT_MASK; + surface->flags &= ~GLITZ_FLAG_MIRRORED_MASK; + surface->flags |= GLITZ_FLAG_PAD_MASK; break; case GLITZ_FILL_REPEAT: - surface->hint_mask |= GLITZ_INT_HINT_REPEAT_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_MIRRORED_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_PAD_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_CLIP_MASK; + surface->flags |= GLITZ_FLAG_REPEAT_MASK; + surface->flags &= ~GLITZ_FLAG_MIRRORED_MASK; + surface->flags &= ~GLITZ_FLAG_PAD_MASK; break; case GLITZ_FILL_REFLECT: - surface->hint_mask |= GLITZ_INT_HINT_REPEAT_MASK; - surface->hint_mask |= GLITZ_INT_HINT_MIRRORED_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_PAD_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_CLIP_MASK; + surface->flags |= GLITZ_FLAG_REPEAT_MASK; + surface->flags |= GLITZ_FLAG_MIRRORED_MASK; + surface->flags &= ~GLITZ_FLAG_PAD_MASK; break; } @@ -360,10 +375,9 @@ glitz_surface_set_component_alpha (glitz_surface_t *surface, glitz_bool_t component_alpha) { if (component_alpha && surface->format->red_size) - surface->hint_mask |= GLITZ_INT_HINT_COMPONENT_ALPHA_MASK; + surface->flags |= GLITZ_FLAG_COMPONENT_ALPHA_MASK; else - surface->hint_mask &= ~GLITZ_INT_HINT_COMPONENT_ALPHA_MASK; - + surface->flags &= ~GLITZ_FLAG_COMPONENT_ALPHA_MASK; } slim_hidden_def(glitz_surface_set_component_alpha); @@ -381,30 +395,30 @@ glitz_surface_set_filter (glitz_surface_t *surface, } else { switch (filter) { case GLITZ_FILTER_NEAREST: - surface->hint_mask &= ~GLITZ_INT_HINT_FRAGMENT_FILTER_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_LINEAR_TRANSFORM_FILTER_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_WINDOW_SPACE_TEXCOORDS_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_IGNORE_REPEAT_MASK; + surface->flags &= ~GLITZ_FLAG_FRAGMENT_FILTER_MASK; + surface->flags &= ~GLITZ_FLAG_LINEAR_TRANSFORM_FILTER_MASK; + surface->flags &= ~GLITZ_FLAG_IGNORE_REPEAT_MASK; + surface->flags |= GLITZ_FLAG_TEXTURE_COORDS_MASK; break; case GLITZ_FILTER_BILINEAR: - surface->hint_mask &= ~GLITZ_INT_HINT_FRAGMENT_FILTER_MASK; - surface->hint_mask |= GLITZ_INT_HINT_LINEAR_TRANSFORM_FILTER_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_WINDOW_SPACE_TEXCOORDS_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_IGNORE_REPEAT_MASK; + surface->flags &= ~GLITZ_FLAG_FRAGMENT_FILTER_MASK; + surface->flags |= GLITZ_FLAG_LINEAR_TRANSFORM_FILTER_MASK; + surface->flags &= ~GLITZ_FLAG_IGNORE_REPEAT_MASK; + surface->flags |= GLITZ_FLAG_TEXTURE_COORDS_MASK; break; case GLITZ_FILTER_CONVOLUTION: case GLITZ_FILTER_GAUSSIAN: - surface->hint_mask |= GLITZ_INT_HINT_FRAGMENT_FILTER_MASK; - surface->hint_mask |= GLITZ_INT_HINT_LINEAR_TRANSFORM_FILTER_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_WINDOW_SPACE_TEXCOORDS_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_IGNORE_REPEAT_MASK; + surface->flags |= GLITZ_FLAG_FRAGMENT_FILTER_MASK; + surface->flags |= GLITZ_FLAG_LINEAR_TRANSFORM_FILTER_MASK; + surface->flags &= ~GLITZ_FLAG_IGNORE_REPEAT_MASK; + surface->flags |= GLITZ_FLAG_TEXTURE_COORDS_MASK; break; case GLITZ_FILTER_LINEAR_GRADIENT: case GLITZ_FILTER_RADIAL_GRADIENT: - surface->hint_mask |= GLITZ_INT_HINT_FRAGMENT_FILTER_MASK; - surface->hint_mask &= ~GLITZ_INT_HINT_LINEAR_TRANSFORM_FILTER_MASK; - surface->hint_mask |= GLITZ_INT_HINT_WINDOW_SPACE_TEXCOORDS_MASK; - surface->hint_mask |= GLITZ_INT_HINT_IGNORE_REPEAT_MASK; + surface->flags |= GLITZ_FLAG_FRAGMENT_FILTER_MASK; + surface->flags &= ~GLITZ_FLAG_LINEAR_TRANSFORM_FILTER_MASK; + surface->flags |= GLITZ_FLAG_IGNORE_REPEAT_MASK; + surface->flags &= ~GLITZ_FLAG_TEXTURE_COORDS_MASK; break; } surface->filter = filter; @@ -412,14 +426,6 @@ glitz_surface_set_filter (glitz_surface_t *surface, } slim_hidden_def(glitz_surface_set_filter); -void -glitz_surface_set_polyedge (glitz_surface_t *surface, - glitz_polyedge_t polyedge) -{ - surface->polyedge = polyedge; -} -slim_hidden_def(glitz_surface_set_polyedge); - int glitz_surface_get_width (glitz_surface_t *surface) { @@ -449,20 +455,13 @@ glitz_surface_get_texture (glitz_surface_t *surface, return texture; } -void -glitz_surface_update_size (glitz_surface_t *surface) -{ - surface->backend->update_size (surface); -} -slim_hidden_def(glitz_surface_update_size); - static glitz_gl_enum_t -_gl_buffer (glitz_buffer_t buffer) +_gl_color_buffer (glitz_color_buffer_t buffer) { switch (buffer) { - case GLITZ_BUFFER_FRONT: + case GLITZ_COLOR_BUFFER_FRONT: return GLITZ_GL_FRONT; - case GLITZ_BUFFER_BACK: + case GLITZ_COLOR_BUFFER_BACK: return GLITZ_GL_BACK; default: return GLITZ_GL_BACK; @@ -470,46 +469,34 @@ _gl_buffer (glitz_buffer_t buffer) } void -glitz_surface_set_read_buffer (glitz_surface_t *surface, - glitz_buffer_t buffer) +glitz_surface_set_read_color_buffer (glitz_surface_t *surface, + glitz_color_buffer_t buffer) { glitz_gl_enum_t mode; if (!surface->format->doublebuffer) return; - mode = _gl_buffer (buffer); + mode = _gl_color_buffer (buffer); if (mode != surface->read_buffer) { surface->read_buffer = mode; glitz_surface_dirty (surface, NULL); } } -slim_hidden_def(glitz_surface_set_read_buffer); +slim_hidden_def(glitz_surface_set_read_color_buffer); void -glitz_surface_set_draw_buffer (glitz_surface_t *surface, - glitz_buffer_t buffer) +glitz_surface_set_draw_color_buffer (glitz_surface_t *surface, + glitz_color_buffer_t buffer) { if (!surface->format->doublebuffer) return; - surface->draw_buffer = _gl_buffer (buffer); - surface->stencil_mask = - &surface->stencil_masks[(buffer == GLITZ_BUFFER_FRONT)? 1: 0]; + surface->draw_buffer = _gl_color_buffer (buffer); surface->update_mask |= GLITZ_UPDATE_DRAW_BUFFER_MASK; } -slim_hidden_def(glitz_surface_set_draw_buffer); - -void -glitz_surface_flush (glitz_surface_t *surface) -{ - if (glitz_surface_push_current (surface, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) - surface->gl->flush (); - - glitz_surface_pop_current (surface); -} -slim_hidden_def(glitz_surface_flush); +slim_hidden_def(glitz_surface_set_draw_color_buffer); void glitz_surface_swap_buffers (glitz_surface_t *surface) @@ -518,17 +505,24 @@ glitz_surface_swap_buffers (glitz_surface_t *surface) return; surface->backend->swap_buffers (surface); - - memset (surface->stencil_masks, 0x0, - sizeof (unsigned int) * GLITZ_N_STENCIL_MASKS); } slim_hidden_def(glitz_surface_swap_buffers); void +glitz_surface_flush (glitz_surface_t *surface) +{ + if (glitz_surface_push_current (surface, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) + surface->backend->gl.flush (); + + glitz_surface_pop_current (surface); +} +slim_hidden_def(glitz_surface_flush); + +void glitz_surface_finish (glitz_surface_t *surface) { if (glitz_surface_push_current (surface, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) - surface->gl->finish (); + surface->backend->gl.finish (); glitz_surface_pop_current (surface); } @@ -560,8 +554,7 @@ glitz_surface_dirty (glitz_surface_t *surface, &surface->dirty_box); } - surface->hint_mask |= - (GLITZ_INT_HINT_DIRTY_MASK | GLITZ_INT_HINT_SOLID_DIRTY_MASK); + surface->flags |= (GLITZ_FLAG_DIRTY_MASK | GLITZ_FLAG_SOLID_DIRTY_MASK); } void @@ -580,7 +573,7 @@ slim_hidden_def(glitz_surface_get_status); void glitz_surface_update_state (glitz_surface_t *surface) { - glitz_gl_proc_address_list_t *gl = surface->gl; + glitz_gl_proc_address_list_t *gl = &surface->backend->gl; if (surface->update_mask & GLITZ_UPDATE_VIEWPORT_MASK) { gl->viewport (0, 0, surface->width, surface->height); @@ -589,8 +582,8 @@ glitz_surface_update_state (glitz_surface_t *surface) gl->ortho (0.0, surface->width, 0.0, surface->height, -1.0, 1.0); gl->matrix_mode (GLITZ_GL_MODELVIEW); gl->load_identity (); - gl->scale_d (1.0, -1.0, 1.0); - gl->translate_d (0.0, -surface->height, 0.0); + gl->scale_f (1.0f, -1.0f, 1.0f); + gl->translate_f (0.0f, -surface->height, 0.0f); gl->disable (GLITZ_GL_DEPTH_TEST); gl->hint (GLITZ_GL_PERSPECTIVE_CORRECTION_HINT, GLITZ_GL_FASTEST); gl->disable (GLITZ_GL_CULL_FACE); @@ -598,24 +591,17 @@ glitz_surface_update_state (glitz_surface_t *surface) gl->polygon_mode (GLITZ_GL_FRONT_AND_BACK, GLITZ_GL_FILL); gl->disable (GLITZ_GL_POLYGON_SMOOTH); gl->shade_model (GLITZ_GL_FLAT); - gl->color_mask (1, 1, 1, 1); + gl->color_mask (GLITZ_GL_TRUE, GLITZ_GL_TRUE, GLITZ_GL_TRUE, + GLITZ_GL_TRUE); gl->disable (GLITZ_GL_DITHER); + gl->enable (GLITZ_GL_SCISSOR_TEST); + gl->scissor (0, 0, surface->width, surface->height); + gl->disable (GLITZ_GL_STENCIL_TEST); + gl->enable_client_state (GLITZ_GL_VERTEX_ARRAY); surface->update_mask &= ~GLITZ_UPDATE_VIEWPORT_MASK; } - - if (surface->update_mask & GLITZ_UPDATE_SCISSOR_MASK) { - gl->disable (GLITZ_GL_SCISSOR_TEST); - - surface->update_mask &= ~GLITZ_UPDATE_SCISSOR_MASK; - } - if (surface->update_mask & GLITZ_UPDATE_SCISSOR_MASK) { - gl->disable (GLITZ_GL_SCISSOR_TEST); - - surface->update_mask &= ~GLITZ_UPDATE_SCISSOR_MASK; - } - if (surface->update_mask & GLITZ_UPDATE_DRAW_BUFFER_MASK) { if (surface->format->doublebuffer) gl->draw_buffer (surface->draw_buffer); @@ -623,318 +609,36 @@ glitz_surface_update_state (glitz_surface_t *surface) surface->update_mask &= ~GLITZ_UPDATE_DRAW_BUFFER_MASK; } - if (surface->update_mask & GLITZ_UPDATE_STENCIL_OP_MASK) { - if (*surface->stencil_mask) - glitz_set_stencil_operator (gl, GLITZ_STENCIL_OPERATOR_CLIP, - *surface->stencil_mask); - else - gl->disable (GLITZ_GL_STENCIL_TEST); - - surface->update_mask &= ~GLITZ_UPDATE_STENCIL_OP_MASK; - } - if (surface->update_mask & GLITZ_UPDATE_MULTISAMPLE_MASK) { if (surface->format->multisample.samples) { if (SURFACE_MULTISAMPLE (surface)) { gl->enable (GLITZ_GL_MULTISAMPLE); - if (surface->feature_mask & + if (surface->backend->feature_mask & GLITZ_FEATURE_MULTISAMPLE_FILTER_HINT_MASK) { - if (surface->polyedge_smooth_hint == - GLITZ_POLYEDGE_SMOOTH_HINT_FAST) - gl->hint (GLITZ_GL_MULTISAMPLE_FILTER_HINT, GLITZ_GL_FASTEST); - else + if (SURFACE_NICEST_MULTISAMPLE (surface)) gl->hint (GLITZ_GL_MULTISAMPLE_FILTER_HINT, GLITZ_GL_NICEST); + else + gl->hint (GLITZ_GL_MULTISAMPLE_FILTER_HINT, GLITZ_GL_FASTEST); } } else gl->disable (GLITZ_GL_MULTISAMPLE); } - + surface->update_mask &= ~GLITZ_UPDATE_MULTISAMPLE_MASK; } } -/* This is supposed to be 8x, 4x and 2x rotated grid multi-sample - patterns. I'm not sure they're actually correct. */ -static glitz_sample_offset_t _8x_multi_sample_offsets[] = { - { -0.375, -0.375 }, - { -0.125, -0.125 }, - { 0.375, -0.375 }, - { 0.125, -0.125 }, - { 0.375, 0.375 }, - { 0.125, 0.125 }, - { -0.375, 0.375 }, - { -0.125, 0.125 } -}; - -static unsigned short _8x_multi_sample_weights[] = { - 0x2000, 0x4000, 0x6000, 0x8000, 0xa000, 0xbfff, 0xdfff, 0xffff -}; - -static glitz_multi_sample_info_t _8x_multi_sample = { - _8x_multi_sample_offsets, - _8x_multi_sample_weights, - 8 -}; - -static glitz_sample_offset_t _4x_multi_sample_offsets[] = { - { -0.125, -0.375 }, - { 0.375, -0.125 }, - { 0.125, 0.375 }, - { -0.375, 0.125 } -}; - -static unsigned short _4x_multi_sample_weights[] = { - 0x4000, 0x8000, 0xbfff, 0xffff -}; - -static glitz_multi_sample_info_t _4x_multi_sample = { - _4x_multi_sample_offsets, - _4x_multi_sample_weights, - 4 -}; - -static glitz_sample_offset_t _2x_multi_sample_offsets[] = { - { -0.24, -0.24 }, - { 0.24, 0.24 } -}; - -static unsigned short _2x_multi_sample_weights[] = { - 0x8000, 0xffff -}; - -static glitz_multi_sample_info_t _2x_multi_sample = { - _2x_multi_sample_offsets, - _2x_multi_sample_weights, - 2 -}; - -void -glitz_surface_enable_anti_aliasing (glitz_surface_t *surface) -{ - if (surface->format->multisample.samples > 1) { - if (surface->polyedge == GLITZ_POLYEDGE_SMOOTH) { - surface->hint_mask |= GLITZ_INT_HINT_MULTISAMPLE_MASK; - surface->update_mask |= GLITZ_UPDATE_MULTISAMPLE_MASK; - } - } else { - if (surface->polyedge == GLITZ_POLYEDGE_SMOOTH && - surface->format->stencil_size >= 4) { - switch (surface->polyedge_smooth_hint) { - case GLITZ_POLYEDGE_SMOOTH_HINT_BEST: - if (surface->format->stencil_size >= 8) { - surface->multi_sample = &_8x_multi_sample; - break; - } - /* fall-through */ - case GLITZ_POLYEDGE_SMOOTH_HINT_GOOD: - surface->multi_sample = &_4x_multi_sample; - break; - case GLITZ_POLYEDGE_SMOOTH_HINT_FAST: - surface->multi_sample = &_2x_multi_sample; - break; - } - } - } -} - -void -glitz_surface_disable_anti_aliasing (glitz_surface_t *surface) -{ - if (surface->format->multisample.samples > 1) { - if (surface->polyedge == GLITZ_POLYEDGE_SMOOTH) { - surface->hint_mask &= ~GLITZ_INT_HINT_MULTISAMPLE_MASK; - surface->update_mask |= GLITZ_UPDATE_MULTISAMPLE_MASK; - } - } else - surface->multi_sample = NULL; -} - -void -glitz_surface_set_polyedge_smooth_hint (glitz_surface_t *surface, - glitz_polyedge_smooth_hint_t hint) -{ - surface->polyedge_smooth_hint = hint; -} - -void -glitz_surface_get_gl_texture (glitz_surface_t *surface, - unsigned int *name, - unsigned int *target, - double *texcoord_width, - double *texcoord_height) -{ - glitz_texture_t *texture = glitz_surface_get_texture (surface, 1); - - if (!texture) - return; - - glitz_texture_bind (surface->gl, texture); - - if (SURFACE_LINEAR_TRANSFORM_FILTER (surface)) - glitz_texture_ensure_filter (surface->gl, texture, GLITZ_GL_LINEAR); - else - glitz_texture_ensure_filter (surface->gl, texture, GLITZ_GL_NEAREST); - - glitz_texture_ensure_wrap (surface->gl, texture, GLITZ_GL_CLAMP_TO_EDGE); - - glitz_texture_unbind (surface->gl, texture); - - if (name) - *name = texture->name; - - if (target) - *target = texture->target; - - if (texcoord_width) - *texcoord_width = texture->texcoord_width; - - if (texcoord_height) - *texcoord_height = texture->texcoord_height; -} -slim_hidden_def(glitz_surface_get_gl_texture); - -void -glitz_surface_gl_begin (glitz_surface_t *surface) -{ - glitz_surface_push_current (surface, GLITZ_CN_SURFACE_DRAWABLE_CURRENT); -} -slim_hidden_def(glitz_surface_gl_begin); - -void -glitz_surface_gl_end (glitz_surface_t *surface) -{ - glitz_bounding_box_t box; - - box.x1 = box.y1 = 0; - box.x2 = surface->width; - box.y2 = surface->height; - - glitz_surface_dirty (surface, &box); - - glitz_surface_pop_current (surface); -} -slim_hidden_def(glitz_surface_gl_end); - unsigned long glitz_surface_get_features (glitz_surface_t *surface) { - return surface->feature_mask; + return surface->backend->feature_mask; } slim_hidden_def(glitz_surface_get_features); -void -glitz_surface_clip_rectangles (glitz_surface_t *surface, - glitz_clip_operator_t op, - int x_offset, - int y_offset, - const glitz_rectangle_t *rects, - int n_rects) -{ - if ((op == GLITZ_CLIP_OPERATOR_SET ||op == GLITZ_CLIP_OPERATOR_UNION) && - n_rects == 1 && - (rects->x + x_offset) <= 0 && - (rects->y + y_offset) <= 0 && - (rects->width + x_offset) >= surface->width && - (rects->height + y_offset) >= surface->height) { - *surface->stencil_mask = 0x0; - surface->update_mask |= GLITZ_UPDATE_STENCIL_OP_MASK; - return; - } else if (*surface->stencil_mask == 0x0) { - glitz_rectangle_t rect; - - rect.x = rect.y = 0; - rect.width = surface->width; - rect.height = surface->height; - - glitz_stencil_rectangles (GLITZ_STENCIL_OPERATOR_CLEAR, - surface, - 0, 0, - &rect, 1); - } - - glitz_stencil_rectangles ((glitz_stencil_operator_t) op, - surface, - x_offset, y_offset, - rects, n_rects); -} -slim_hidden_def(glitz_surface_clip_rectangles); - -void -glitz_surface_clip_trapezoids (glitz_surface_t *surface, - glitz_clip_operator_t op, - int x_offset, - int y_offset, - const glitz_trapezoid_t *traps, - int n_traps) -{ - if (*surface->stencil_mask == 0x0) { - glitz_rectangle_t rect; - - rect.x = rect.y = 0; - rect.width = surface->width; - rect.height = surface->height; - - glitz_stencil_rectangles (GLITZ_STENCIL_OPERATOR_CLEAR, - surface, 0, 0, &rect, 1); - } - - glitz_stencil_trapezoids ((glitz_stencil_operator_t) op, - surface, - x_offset, y_offset, - traps, n_traps); -} -slim_hidden_def(glitz_surface_clip_trapezoids); - -void -glitz_surface_clip_triangles (glitz_surface_t *surface, - glitz_clip_operator_t op, - int x_offset, - int y_offset, - const glitz_triangle_t *tris, - int n_tris) -{ - if (*surface->stencil_mask == 0x0) { - glitz_rectangle_t rect; - - rect.x = rect.y = 0; - rect.width = surface->width; - rect.height = surface->height; - - glitz_stencil_rectangles (GLITZ_STENCIL_OPERATOR_CLEAR, - surface, 0, 0, &rect, 1); - } - - glitz_stencil_triangles ((glitz_stencil_operator_t) op, - surface, - x_offset, y_offset, - GLITZ_TRIANGLE_TYPE_NORMAL, - (glitz_point_fixed_t *) tris, n_tris * 3); -} -slim_hidden_def(glitz_surface_clip_triangles); - glitz_format_t * glitz_surface_get_format (glitz_surface_t *surface) { return surface->format; } slim_hidden_def(glitz_surface_get_format); - -unsigned long -glitz_surface_get_hints (glitz_surface_t *surface) -{ - unsigned hint_mask; - - hint_mask = surface->hint_mask & GLITZ_HINT_OFFSCREEN_MASK; - - if (*surface->stencil_mask) - hint_mask |= GLITZ_HINT_CLIPPING_MASK; - - if (surface->polyedge == GLITZ_POLYEDGE_SMOOTH && - surface->format->multisample.samples < 2 && - surface->format->stencil_size >= 4) - hint_mask |= GLITZ_HINT_MULTISAMPLE_MASK; - - return hint_mask; -} -slim_hidden_def(glitz_surface_get_hints); diff --git a/src/glitz_texture.c b/src/glitz_texture.c index b746a70..b7aacc1 100644 --- a/src/glitz_texture.c +++ b/src/glitz_texture.c @@ -49,13 +49,13 @@ glitz_texture_init (glitz_texture_t *texture, if (target_mask & GLITZ_TEXTURE_TARGET_NON_POWER_OF_TWO_MASK) { texture->target = GLITZ_GL_TEXTURE_2D; texture->repeatable = 1; - texture->texcoord_width = texture->texcoord_height = 1.0; + texture->texcoord_width = texture->texcoord_height = 1.0f; } else { if (POWER_OF_TWO (width) && POWER_OF_TWO (height)) { texture->target = GLITZ_GL_TEXTURE_2D; texture->repeatable = 1; - texture->texcoord_width = texture->texcoord_height = 1.0; + texture->texcoord_width = texture->texcoord_height = 1.0f; } else { texture->repeatable = 0; if (target_mask & GLITZ_TEXTURE_TARGET_RECTANGLE_MASK) { @@ -71,11 +71,14 @@ glitz_texture_init (glitz_texture_t *texture, if (!POWER_OF_TWO (texture->height)) texture->height = glitz_uint_to_power_of_two (texture->height); - texture->texcoord_width = (double) width / (double) texture->width; - texture->texcoord_height = (double) height / (double) texture->height; + texture->texcoord_width = (glitz_float_t) width / texture->width; + texture->texcoord_height = (glitz_float_t) height / texture->height; } } } + + texture->texcoord_width_unit = texture->texcoord_width / texture->width; + texture->texcoord_height_unit = texture->texcoord_height / texture->height; } void @@ -177,49 +180,69 @@ glitz_texture_copy_surface (glitz_texture_t *texture, int x_texture, int y_texture) { + glitz_gl_proc_address_list_t *gl = &surface->backend->gl; int tex_height; glitz_surface_push_current (surface, GLITZ_CN_SURFACE_DRAWABLE_CURRENT); - glitz_texture_bind (surface->gl, texture); + glitz_texture_bind (gl, texture); if (surface->format->doublebuffer) - surface->gl->read_buffer (surface->read_buffer); + gl->read_buffer (surface->read_buffer); if (texture->target == GLITZ_GL_TEXTURE_2D) - tex_height = (int) ((double) texture->height * texture->texcoord_height); + tex_height = (int) (texture->height * texture->texcoord_height); else tex_height = (int) texture->texcoord_height; - surface->gl->copy_tex_sub_image_2d (texture->target, 0, - x_texture, - tex_height - y_texture - height, - x_surface, - surface->height - y_surface - height, - width, height); - - glitz_texture_unbind (surface->gl, texture); + gl->copy_tex_sub_image_2d (texture->target, 0, + x_texture, + tex_height - y_texture - height, + x_surface, + surface->height - y_surface - height, + width, height); + + glitz_texture_unbind (gl, texture); glitz_surface_pop_current (surface); } void -glitz_texture_tex_coord (glitz_texture_t *texture, - double x, - double y, - double *return_x, - double *return_y) +glitz_texture_set_tex_gen (glitz_gl_proc_address_list_t *gl, + glitz_texture_t *texture, + int x_src, + int y_src, + int height, + unsigned long flags) { - if (texture->texcoord_width > 1.0) { - *return_x = x; + glitz_vec4_t plane; + + if (flags & GLITZ_FLAG_TEXTURE_COORDS_MASK) { + plane.v[1] = plane.v[2] = 0.0f; + plane.v[0] = texture->texcoord_width_unit; + plane.v[3] = -x_src * texture->texcoord_width_unit; } else { - *return_x = (x / (texture->width * texture->texcoord_width)) * - texture->texcoord_width; - } + plane.v[1] = plane.v[2] = 0.0f; + plane.v[0] = 1.0; + plane.v[3] = -x_src; + } - if (texture->texcoord_height > 1.0) { - *return_y = y; + gl->tex_gen_i (GLITZ_GL_S, GLITZ_GL_TEXTURE_GEN_MODE, + GLITZ_GL_EYE_LINEAR); + gl->tex_gen_fv (GLITZ_GL_S, GLITZ_GL_EYE_PLANE, plane.v); + gl->enable (GLITZ_GL_TEXTURE_GEN_S); + + if (flags & GLITZ_FLAG_TEXTURE_COORDS_MASK) { + plane.v[0] = 0.0f; + plane.v[1] = -texture->texcoord_height_unit; + plane.v[3] = (y_src + height) * texture->texcoord_height_unit; } else { - *return_y = (y / (texture->height * texture->texcoord_height)) * - texture->texcoord_height; + plane.v[0] = 0.0f; + plane.v[1] = 1.0; + plane.v[3] = -y_src; } + + gl->tex_gen_i (GLITZ_GL_T, GLITZ_GL_TEXTURE_GEN_MODE, + GLITZ_GL_EYE_LINEAR); + gl->tex_gen_fv (GLITZ_GL_T, GLITZ_GL_EYE_PLANE, plane.v); + gl->enable (GLITZ_GL_TEXTURE_GEN_T); } diff --git a/src/glitz_trap.c b/src/glitz_trap.c deleted file mode 100644 index b926151..0000000 --- a/src/glitz_trap.c +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright © 2004 David Reveman, Peter Nilsson - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the names of - * David Reveman and Peter Nilsson not be used in advertising or - * publicity pertaining to distribution of the software without - * specific, written prior permission. David Reveman and Peter Nilsson - * makes no representations about the suitability of this software for - * any purpose. It is provided "as is" without express or implied warranty. - * - * DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND - * PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA - * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * Authors: David Reveman <c99drn@cs.umu.se> - * Peter Nilsson <c99pnn@cs.umu.se> - */ - -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif - -#include "glitzint.h" - -/* whether 't' is a well defined not obviously empty trapezoid */ -#define TRAPEZOID_VALID(t) ((t)->top.left <= (t)->top.right && \ - (t)->bottom.left <= (t)->bottom.right && \ - (int) ((t)->bottom.y - (t)->top.y) >= 0) - -static void -glitz_trapezoid_bounds (int x_offset, - int y_offset, - int n_traps, - const glitz_trapezoid_t *traps, - glitz_bounding_box_t *box) -{ - box->x1 = MAXSHORT; - box->x2 = MINSHORT; - box->y1 = MAXSHORT; - box->y2 = MINSHORT; - - for (; n_traps; n_traps--, traps++) { - int x1, y1, x2, y2; - - if (!TRAPEZOID_VALID (traps)) - continue; - - x1 = MIN (FIXED_TO_INT (traps->top.left), - FIXED_TO_INT (traps->bottom.left)); - if (x1 < box->x1) - box->x1 = x1; - - x2 = MAX (FIXED_TO_INT (FIXED_CEIL (traps->top.right)), - FIXED_TO_INT (FIXED_CEIL (traps->bottom.right))); - if (x2 > box->x2) - box->x2 = x2; - - y1 = FIXED_TO_INT (traps->top.y); - if (y1 < box->y1) - box->y1 = y1; - - y2 = FIXED_TO_INT (FIXED_CEIL (traps->bottom.y)); - if (y2 > box->y2) - box->y2 = y2; - } - - box->x1 += x_offset; - box->x2 += x_offset; - box->y1 += y_offset; - box->y2 += y_offset; -} - -void -glitz_int_fill_trapezoids (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_trapezoid_t *traps, - int n_traps) -{ - glitz_gl_vertex_2d_t vertex_2d; - static glitz_sample_offset_t zero_offset = { 0.0, 0.0 }; - glitz_sample_offset_t *offset; - int i, passes; - - dst->gl->color_4us (color->red, color->green, color->blue, color->alpha); - - glitz_set_operator (dst->gl, op); - - if (dst->multi_sample) { - passes = dst->multi_sample->n_samples; - offset = dst->multi_sample->offsets; - } else { - passes = 1; - offset = &zero_offset; - } - - vertex_2d = dst->gl->vertex_2d; - - dst->gl->begin (GLITZ_GL_QUADS); - - for (; n_traps; n_traps--, traps++) { - double top, topleft, topright; - double bottom, bottomleft, bottomright; - - if (!TRAPEZOID_VALID (traps)) - continue; - - top = y_offset + FIXED_TO_DOUBLE (traps->top.y); - bottom = y_offset + FIXED_TO_DOUBLE (traps->bottom.y); - bottomleft = x_offset + FIXED_TO_DOUBLE (traps->bottom.left); - topleft = x_offset + FIXED_TO_DOUBLE (traps->top.left); - topright = x_offset + FIXED_TO_DOUBLE (traps->top.right); - bottomright = x_offset + FIXED_TO_DOUBLE (traps->bottom.right); - - for (i = 0; i < passes; i++) { - vertex_2d (offset[i].x + bottomleft, offset[i].y + bottom); - vertex_2d (offset[i].x + topleft, offset[i].y + top); - vertex_2d (offset[i].x + topright, offset[i].y + top); - vertex_2d (offset[i].x + bottomright, offset[i].y + bottom); - } - } - - dst->gl->end (); -} - -void -glitz_fill_trapezoids (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_trapezoid_t *traps, - int n_traps) -{ - glitz_bounding_box_t bounds; - - glitz_trapezoid_bounds (x_offset, y_offset, n_traps, traps, &bounds); - if (bounds.x1 > dst->width || bounds.y1 > dst->height || - bounds.x2 < 0 || bounds.y2 < 0) - return; - - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - glitz_int_fill_trapezoids (op, dst, - x_offset, y_offset, - color, traps, n_traps); - - glitz_surface_dirty (dst, &bounds); - glitz_surface_pop_current (dst); -} -slim_hidden_def(glitz_fill_trapezoids); - -void -glitz_add_trapezoids (glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_trapezoid_t *traps, - int n_traps) -{ - glitz_bounding_box_t bounds; - glitz_color_t color; - - glitz_trapezoid_bounds (x_offset, y_offset, n_traps, traps, &bounds); - if (bounds.x1 > dst->width || bounds.y1 > dst->height || - bounds.x2 < 0 || bounds.y2 < 0) - return; - - glitz_surface_enable_anti_aliasing (dst); - - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - if (dst->multi_sample) - color.red = color.green = color.blue = color.alpha = - 0xffff / dst->multi_sample->n_samples; - else - color.red = color.green = color.blue = color.alpha = 0xffff; - - glitz_int_fill_trapezoids (GLITZ_OPERATOR_ADD, dst, - x_offset, y_offset, - &color, traps, n_traps); - - glitz_surface_disable_anti_aliasing (dst); - - glitz_surface_dirty (dst, &bounds); - glitz_surface_pop_current (dst); -} -slim_hidden_def(glitz_add_trapezoids); - -void -glitz_composite_trapezoids (glitz_operator_t op, - glitz_surface_t *src, - glitz_surface_t *dst, - int x_src, - int y_src, - int x_offset, - int y_offset, - unsigned short opacity, - const glitz_trapezoid_t *traps, - int n_traps) -{ - glitz_bounding_box_t bounds; - glitz_rectangle_t rect; - - if (n_traps == 0) - return; - - if (dst->format->stencil_size < ((*dst->stencil_mask)? 2: 1)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - return; - } - - glitz_trapezoid_bounds (x_offset, y_offset, n_traps, traps, &bounds); - if (bounds.x1 > dst->width || bounds.y1 > dst->height || - bounds.x2 < 0 || bounds.y2 < 0) - return; - - rect.x = bounds.x1; - rect.y = bounds.y1; - rect.width = bounds.x2 - bounds.x1; - rect.height = bounds.y2 - bounds.y1; - - glitz_surface_enable_anti_aliasing (dst); - - if (*dst->stencil_mask == 0x0) - glitz_stencil_rectangles (GLITZ_STENCIL_OPERATOR_CLEAR, - dst, 0, 0, &rect, 1); - - glitz_stencil_trapezoids (GLITZ_STENCIL_OPERATOR_INCR_EQUAL, - dst, - x_offset, y_offset, - traps, n_traps); - - dst->polyopacity = opacity; - dst->hint_mask |= GLITZ_INT_HINT_POLYGON_OP_MASK; - - glitz_composite (op, - src, - NULL, - dst, - x_src + bounds.x1, - y_src + bounds.y1, - 0, 0, - rect.x, rect.y, - rect.width, rect.height); - - dst->hint_mask &= ~GLITZ_INT_HINT_POLYGON_OP_MASK; - - glitz_surface_disable_anti_aliasing (dst); - - if (*dst->stencil_mask != 0x1) - glitz_stencil_rectangles (GLITZ_STENCIL_OPERATOR_DECR_LESS, - dst, 0, 0, &rect, 1); - else - *dst->stencil_mask = 0x0; - - dst->update_mask |= GLITZ_UPDATE_STENCIL_OP_MASK; -} -slim_hidden_def(glitz_composite_trapezoids); - -static void -glitz_color_trapezoid_bounds (int x_offset, - int y_offset, - int n_color_traps, - const glitz_color_trapezoid_t *color_traps, - glitz_bounding_box_t *box) -{ - box->x1 = MAXSHORT; - box->x2 = MINSHORT; - box->y1 = MAXSHORT; - box->y2 = MINSHORT; - - for (; n_color_traps; n_color_traps--, color_traps++) { - int x1, y1, x2, y2; - - if (!TRAPEZOID_VALID (color_traps)) - continue; - - x1 = MIN (FIXED_TO_INT (color_traps->top.left), - FIXED_TO_INT (color_traps->bottom.left)); - if (x1 < box->x1) - box->x1 = x1; - - x2 = MAX (FIXED_TO_INT (FIXED_CEIL (color_traps->top.right)), - FIXED_TO_INT (FIXED_CEIL (color_traps->bottom.right))); - if (x2 > box->x2) - box->x2 = x2; - - y1 = FIXED_TO_INT (color_traps->top.y); - if (y1 < box->y1) - box->y1 = y1; - - y2 = FIXED_TO_INT (FIXED_CEIL (color_traps->bottom.y)); - if (y2 > box->y2) - box->y2 = y2; - } - - box->x1 += x_offset; - box->x2 += x_offset; - box->y1 += y_offset; - box->y2 += y_offset; -} - -void -glitz_color_trapezoids (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_trapezoid_t *color_traps, - int n_color_traps) -{ - glitz_gl_vertex_2d_t vertex_2d; - glitz_gl_color_4us_t color_4us; - glitz_bounding_box_t bounds; - - glitz_color_trapezoid_bounds (x_offset, y_offset, - n_color_traps, color_traps, &bounds); - if (bounds.x1 > dst->width || bounds.y1 > dst->height || - bounds.x2 < 0 || bounds.y2 < 0) - return; - - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - glitz_set_operator (dst->gl, op); - - dst->gl->shade_model (GLITZ_GL_SMOOTH); - - dst->gl->begin (GLITZ_GL_QUADS); - - vertex_2d = dst->gl->vertex_2d; - color_4us = dst->gl->color_4us; - for (; n_color_traps; n_color_traps--, color_traps++) { - - if (!TRAPEZOID_VALID (color_traps)) - continue; - - color_4us (color_traps->bottom.left_color.red, - color_traps->bottom.left_color.green, - color_traps->bottom.left_color.blue, - color_traps->bottom.left_color.alpha); - vertex_2d (x_offset + FIXED_TO_DOUBLE (color_traps->bottom.left), - y_offset + FIXED_TO_DOUBLE (color_traps->bottom.y)); - - color_4us (color_traps->top.left_color.red, - color_traps->top.left_color.green, - color_traps->top.left_color.blue, - color_traps->top.left_color.alpha); - vertex_2d (x_offset + FIXED_TO_DOUBLE (color_traps->top.left), - y_offset + FIXED_TO_DOUBLE (color_traps->top.y)); - - color_4us (color_traps->top.right_color.red, - color_traps->top.right_color.green, - color_traps->top.right_color.blue, - color_traps->top.right_color.alpha); - vertex_2d (x_offset + FIXED_TO_DOUBLE (color_traps->top.right), - y_offset + FIXED_TO_DOUBLE (color_traps->top.y)); - - color_4us (color_traps->bottom.right_color.red, - color_traps->bottom.right_color.green, - color_traps->bottom.right_color.blue, - color_traps->bottom.right_color.alpha); - vertex_2d (x_offset + FIXED_TO_DOUBLE (color_traps->bottom.right), - y_offset + FIXED_TO_DOUBLE (color_traps->bottom.y)); - } - - dst->gl->end (); - - dst->gl->shade_model (GLITZ_GL_FLAT); - - glitz_surface_dirty (dst, &bounds); - glitz_surface_pop_current (dst); -} -slim_hidden_def(glitz_color_trapezoids); diff --git a/src/glitz_tri.c b/src/glitz_tri.c deleted file mode 100644 index b37c796..0000000 --- a/src/glitz_tri.c +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Copyright © 2004 David Reveman, Peter Nilsson - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the names of - * David Reveman and Peter Nilsson not be used in advertising or - * publicity pertaining to distribution of the software without - * specific, written prior permission. David Reveman and Peter Nilsson - * makes no representations about the suitability of this software for - * any purpose. It is provided "as is" without express or implied warranty. - * - * DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND - * PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA - * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * Authors: David Reveman <c99drn@cs.umu.se> - * Peter Nilsson <c99pnn@cs.umu.se> - */ - -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif - -#include "glitzint.h" - -static void -glitz_point_fixed_bounds (int x_offset, - int y_offset, - int n_points, - const glitz_point_fixed_t *points, - glitz_bounding_box_t *box) -{ - box->x1 = MAXSHORT; - box->x2 = MINSHORT; - box->y1 = MAXSHORT; - box->y2 = MINSHORT; - - for (; n_points; n_points--, points++) { - int x1, y1, x2, y2; - - x1 = FIXED_TO_INT (points->x); - x2 = FIXED_TO_INT (FIXED_CEIL (points->x)); - y1 = FIXED_TO_INT (points->y); - y2 = FIXED_TO_INT (FIXED_CEIL (points->y)); - - if (x1 < box->x1) - box->x1 = x1; - else if (x2 > box->x2) - box->x2 = x2; - if (y1 < box->y1) - box->y1 = y1; - else if (y2 > box->y2) - box->y2 = y2; - } - - box->x1 += x_offset; - box->x2 += x_offset; - box->y1 += y_offset; - box->y2 += y_offset; -} - -void -glitz_int_fill_triangles (glitz_operator_t op, - glitz_surface_t *dst, - glitz_triangle_type_t type, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_point_fixed_t *points, - int n_points) -{ - glitz_gl_vertex_2d_t vertex_2d; - static glitz_sample_offset_t zero_offset = { 0.0, 0.0 }; - glitz_sample_offset_t *offset; - int i, passes; - - dst->gl->color_4us (color->red, color->green, color->blue, color->alpha); - - glitz_set_operator (dst->gl, op); - - if (dst->multi_sample) { - passes = dst->multi_sample->n_samples; - offset = dst->multi_sample->offsets; - } else { - passes = 1; - offset = &zero_offset; - } - - vertex_2d = dst->gl->vertex_2d; - - switch (type) { - case GLITZ_TRIANGLE_TYPE_NORMAL: - dst->gl->begin (GLITZ_GL_TRIANGLES); - break; - case GLITZ_TRIANGLE_TYPE_STRIP: - dst->gl->begin (GLITZ_GL_TRIANGLE_STRIP); - break; - case GLITZ_TRIANGLE_TYPE_FAN: - dst->gl->begin (GLITZ_GL_TRIANGLE_FAN); - break; - } - - while (passes--) - for (i = 0; i < n_points; i++) - vertex_2d (offset[passes].x + x_offset + FIXED_TO_DOUBLE (points[i].x), - offset[passes].y + y_offset + FIXED_TO_DOUBLE (points[i].y)); - - dst->gl->end (); -} - -void -glitz_fill_triangles (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_triangle_t *tris, - int n_tris) -{ - glitz_bounding_box_t bounds; - - glitz_point_fixed_bounds (x_offset, y_offset, - n_tris * 3, (glitz_point_fixed_t *) tris, &bounds); - if (bounds.x1 > dst->width || bounds.y1 > dst->height || - bounds.x2 < 0 || bounds.y2 < 0) - return; - - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - glitz_int_fill_triangles (op, - dst, - GLITZ_TRIANGLE_TYPE_NORMAL, - x_offset, y_offset, - color, - (glitz_point_fixed_t *) tris, - n_tris * 3); - - glitz_surface_dirty (dst, &bounds); - glitz_surface_pop_current (dst); -} -slim_hidden_def(glitz_fill_triangles); - -void -glitz_add_triangles (glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_triangle_t *tris, - int n_tris) -{ - glitz_bounding_box_t bounds; - glitz_color_t color; - - glitz_point_fixed_bounds (x_offset, y_offset, - n_tris * 3, (glitz_point_fixed_t *) tris, &bounds); - if (bounds.x1 > dst->width || bounds.y1 > dst->height || - bounds.x2 < 0 || bounds.y2 < 0) - return; - - glitz_surface_enable_anti_aliasing (dst); - - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - if (dst->multi_sample) - color.red = color.green = color.blue = color.alpha = - 0xffff / dst->multi_sample->n_samples; - else - color.red = color.green = color.blue = color.alpha = 0xffff; - - glitz_int_fill_triangles (GLITZ_OPERATOR_ADD, - dst, - GLITZ_TRIANGLE_TYPE_NORMAL, - x_offset, y_offset, - &color, - (glitz_point_fixed_t *) tris, - n_tris * 3); - - glitz_surface_disable_anti_aliasing (dst); - - glitz_surface_dirty (dst, &bounds); - glitz_surface_pop_current (dst); -} -slim_hidden_def(glitz_add_triangles); - -static void -glitz_int_composite_triangles (glitz_operator_t op, - glitz_surface_t *src, - glitz_surface_t *dst, - int x_src, - int y_src, - int x_offset, - int y_offset, - unsigned short opacity, - glitz_triangle_type_t type, - const glitz_point_fixed_t *points, - int n_points) -{ - glitz_bounding_box_t bounds; - glitz_rectangle_t rect; - - if (dst->format->stencil_size < ((*dst->stencil_mask)? 2: 1)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - return; - } - - glitz_point_fixed_bounds (x_offset, y_offset, n_points, points, &bounds); - if (bounds.x1 > dst->width || bounds.y1 > dst->height || - bounds.x2 < 0 || bounds.y2 < 0) - return; - - rect.x = bounds.x1; - rect.y = bounds.y1; - rect.width = bounds.x2 - bounds.x1; - rect.height = bounds.y2 - bounds.y1; - - glitz_surface_enable_anti_aliasing (dst); - - if (*dst->stencil_mask == 0x0) - glitz_stencil_rectangles (GLITZ_STENCIL_OPERATOR_CLEAR, - dst, 0, 0, &rect, 1); - - glitz_stencil_triangles (GLITZ_STENCIL_OPERATOR_INCR_EQUAL, - dst, x_offset, y_offset, type, - points, n_points); - - dst->polyopacity = opacity; - dst->hint_mask |= GLITZ_INT_HINT_POLYGON_OP_MASK; - - glitz_composite (op, - src, - NULL, - dst, - x_src + bounds.x1, - y_src + bounds.y1, - 0, 0, - rect.x, rect.y, - rect.width, rect.height); - - dst->hint_mask &= ~GLITZ_INT_HINT_POLYGON_OP_MASK; - - glitz_surface_disable_anti_aliasing (dst); - - if (*dst->stencil_mask != 0x1) - glitz_stencil_rectangles (GLITZ_STENCIL_OPERATOR_DECR_LESS, - dst, 0, 0, &rect, 1); - else - *dst->stencil_mask = 0x0; - - dst->update_mask |= GLITZ_UPDATE_STENCIL_OP_MASK; -} - -void -glitz_composite_triangles (glitz_operator_t op, - glitz_surface_t *src, - glitz_surface_t *dst, - int x_src, - int y_src, - int x_offset, - int y_offset, - unsigned short opacity, - const glitz_triangle_t *tris, - int n_tris) -{ - glitz_int_composite_triangles (op, src, dst, - x_src, y_src, x_offset, y_offset, - opacity, GLITZ_TRIANGLE_TYPE_NORMAL, - (glitz_point_fixed_t *) tris, - n_tris * 3); -} -slim_hidden_def(glitz_composite_triangles); - -void -glitz_composite_tri_strip (glitz_operator_t op, - glitz_surface_t *src, - glitz_surface_t *dst, - int x_src, - int y_src, - int x_offset, - int y_offset, - unsigned short opacity, - const glitz_point_fixed_t *points, - int n_points) -{ - glitz_int_composite_triangles (op, src, dst, - x_src, y_src, x_offset, y_offset, - opacity, GLITZ_TRIANGLE_TYPE_STRIP, - points, n_points); -} -slim_hidden_def(glitz_composite_tri_strip); - -void -glitz_composite_tri_fan (glitz_operator_t op, - glitz_surface_t *src, - glitz_surface_t *dst, - int x_src, - int y_src, - int x_offset, - int y_offset, - unsigned short opacity, - const glitz_point_fixed_t *points, - int n_points) -{ - glitz_int_composite_triangles (op, src, dst, - x_src, y_src, x_offset, y_offset, - opacity, GLITZ_TRIANGLE_TYPE_FAN, - points, n_points); -} -slim_hidden_def(glitz_composite_tri_fan); - -static void -glitz_color_triangle_bounds (int x_offset, - int y_offset, - int n_color_tris, - const glitz_color_triangle_t *color_tris, - glitz_bounding_box_t *box) -{ - box->x1 = MAXSHORT; - box->x2 = MINSHORT; - box->y1 = MAXSHORT; - box->y2 = MINSHORT; - - for (; n_color_tris; n_color_tris--, color_tris++) { - int x1, y1, x2, y2; - - x1 = MIN (MIN (FIXED_TO_INT (color_tris->p1.point.x), - FIXED_TO_INT (color_tris->p2.point.x)), - FIXED_TO_INT (color_tris->p3.point.x)); - if (x1 < box->x1) - box->x1 = x1; - - x2 = MAX (MAX (FIXED_TO_INT (FIXED_CEIL (color_tris->p1.point.x)), - FIXED_TO_INT (FIXED_CEIL (color_tris->p2.point.x))), - FIXED_TO_INT (FIXED_CEIL (color_tris->p3.point.x))); - if (x2 > box->x2) - box->x2 = x2; - - y1 = MIN (MIN (FIXED_TO_INT (color_tris->p1.point.y), - FIXED_TO_INT (color_tris->p2.point.y)), - FIXED_TO_INT (color_tris->p3.point.y)); - if (y1 < box->y1) - box->y1 = y1; - - y2 = MAX (MAX (FIXED_TO_INT (FIXED_CEIL (color_tris->p1.point.y)), - FIXED_TO_INT (FIXED_CEIL (color_tris->p2.point.y))), - FIXED_TO_INT (FIXED_CEIL (color_tris->p3.point.y))); - if (y2 > box->y2) - box->y2 = y2; - } - - box->x1 += x_offset; - box->x2 += x_offset; - box->y1 += y_offset; - box->y2 += y_offset; -} - - -void -glitz_color_triangles (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_triangle_t *color_tris, - int n_color_tris) -{ - glitz_gl_vertex_2d_t vertex_2d; - glitz_gl_color_4us_t color_4us; - glitz_bounding_box_t bounds; - - glitz_color_triangle_bounds (x_offset, y_offset, - n_color_tris, color_tris, &bounds); - if (bounds.x1 > dst->width || bounds.y1 > dst->height || - bounds.x2 < 0 || bounds.y2 < 0) - return; - - if (!glitz_surface_push_current (dst, GLITZ_CN_SURFACE_DRAWABLE_CURRENT)) { - glitz_surface_status_add (dst, GLITZ_STATUS_NOT_SUPPORTED_MASK); - glitz_surface_pop_current (dst); - return; - } - - glitz_set_operator (dst->gl, op); - - dst->gl->shade_model (GLITZ_GL_SMOOTH); - - dst->gl->begin (GLITZ_GL_TRIANGLES); - - vertex_2d = dst->gl->vertex_2d; - color_4us = dst->gl->color_4us; - for (; n_color_tris; n_color_tris--, color_tris++) { - color_4us (color_tris->p1.color.red, - color_tris->p1.color.green, - color_tris->p1.color.blue, - color_tris->p1.color.alpha); - vertex_2d (x_offset + FIXED_TO_DOUBLE (color_tris->p1.point.x), - y_offset + FIXED_TO_DOUBLE (color_tris->p1.point.y)); - - color_4us (color_tris->p2.color.red, - color_tris->p2.color.green, - color_tris->p2.color.blue, - color_tris->p2.color.alpha); - vertex_2d (x_offset + FIXED_TO_DOUBLE (color_tris->p2.point.x), - y_offset + FIXED_TO_DOUBLE (color_tris->p2.point.y)); - - color_4us (color_tris->p3.color.red, - color_tris->p3.color.green, - color_tris->p3.color.blue, - color_tris->p3.color.alpha); - vertex_2d (x_offset + FIXED_TO_DOUBLE (color_tris->p3.point.x), - y_offset + FIXED_TO_DOUBLE (color_tris->p3.point.y)); - } - - dst->gl->end (); - - dst->gl->shade_model (GLITZ_GL_FLAT); - - glitz_surface_dirty (dst, &bounds); - glitz_surface_pop_current (dst); -} -slim_hidden_def(glitz_color_triangles); diff --git a/src/glitz_util.c b/src/glitz_util.c index 51a0820..00bd3fe 100644 --- a/src/glitz_util.c +++ b/src/glitz_util.c @@ -127,7 +127,7 @@ glitz_set_raster_pos (glitz_gl_proc_address_list_t *gl, gl->depth_range (0, 1); gl->viewport (-1, -1, 2, 2); - gl->raster_pos_2d (0, 0); + gl->raster_pos_2f (0, 0); gl->bitmap (0, 0, 1, 1, x, y, NULL); gl->pop_matrix (); @@ -137,11 +137,11 @@ glitz_set_raster_pos (glitz_gl_proc_address_list_t *gl, } void -glitz_clamp_value (double *value, double min, double max) +glitz_clamp_value (glitz_float_t *value, + glitz_float_t min, glitz_float_t max) { if (*value < min) *value = min; else if (*value > max) *value = max; } - diff --git a/src/glitzint.h b/src/glitzint.h index 03c2a12..4e6eb1e 100644 --- a/src/glitzint.h +++ b/src/glitzint.h @@ -1,28 +1,26 @@ /* - * Copyright © 2004 David Reveman, Peter Nilsson - * + * Copyright © 2004 David Reveman + * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without * fee, provided that the above copyright notice appear in all copies * and that both that copyright notice and this permission notice * appear in supporting documentation, and that the names of - * David Reveman and Peter Nilsson not be used in advertising or - * publicity pertaining to distribution of the software without - * specific, written prior permission. David Reveman and Peter Nilsson - * makes no representations about the suitability of this software for - * any purpose. It is provided "as is" without express or implied warranty. + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. * - * DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND - * PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA - * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * Authors: David Reveman <c99drn@cs.umu.se> - * Peter Nilsson <c99pnn@cs.umu.se> + * Author: David Reveman <c99drn@cs.umu.se> */ #ifndef GLITZINT_H_INCLUDED @@ -65,10 +63,9 @@ #endif #define GLITZ_STATUS_NO_MEMORY_MASK (1L << 0) -#define GLITZ_STATUS_NULL_POINTER_MASK (1L << 1) -#define GLITZ_STATUS_BAD_COORDINATE_MASK (1L << 2) -#define GLITZ_STATUS_NOT_SUPPORTED_MASK (1L << 3) -#define GLITZ_STATUS_INVALID_MATRIX_MASK (1L << 4) +#define GLITZ_STATUS_BAD_COORDINATE_MASK (1L << 1) +#define GLITZ_STATUS_NOT_SUPPORTED_MASK (1L << 2) +#define GLITZ_STATUS_CONTENT_DESTROYED_MASK (1L << 3) #define GLITZ_TEXTURE_TARGET_2D_MASK (1L << 0) #define GLITZ_TEXTURE_TARGET_RECTANGLE_MASK (1L << 1) @@ -83,15 +80,16 @@ typedef struct _glitz_gl_proc_address_list_t { glitz_gl_enable_t enable; glitz_gl_disable_t disable; - glitz_gl_begin_t begin; - glitz_gl_end_t end; - glitz_gl_vertex_2i_t vertex_2i; - glitz_gl_vertex_2d_t vertex_2d; + glitz_gl_enable_client_state_t enable_client_state; + glitz_gl_disable_client_state_t disable_client_state; + glitz_gl_vertex_pointer_t vertex_pointer; + glitz_gl_draw_arrays_t draw_arrays; glitz_gl_tex_env_f_t tex_env_f; glitz_gl_tex_env_fv_t tex_env_fv; - glitz_gl_tex_coord_2d_t tex_coord_2d; + glitz_gl_tex_gen_i_t tex_gen_i; + glitz_gl_tex_gen_fv_t tex_gen_fv; glitz_gl_color_4us_t color_4us; - glitz_gl_color_4d_t color_4d; + glitz_gl_color_4f_t color_4f; glitz_gl_scissor_t scissor; glitz_gl_blend_func_t blend_func; glitz_gl_clear_t clear; @@ -105,11 +103,10 @@ typedef struct _glitz_gl_proc_address_list_t { glitz_gl_push_matrix_t push_matrix; glitz_gl_pop_matrix_t pop_matrix; glitz_gl_load_identity_t load_identity; - glitz_gl_load_matrix_d_t load_matrix_d; - glitz_gl_mult_matrix_d_t mult_matrix_d; + glitz_gl_load_matrix_f_t load_matrix_f; glitz_gl_depth_range_t depth_range; glitz_gl_viewport_t viewport; - glitz_gl_raster_pos_2d_t raster_pos_2d; + glitz_gl_raster_pos_2f_t raster_pos_2f; glitz_gl_bitmap_t bitmap; glitz_gl_read_buffer_t read_buffer; glitz_gl_draw_buffer_t draw_buffer; @@ -118,8 +115,8 @@ typedef struct _glitz_gl_proc_address_list_t { glitz_gl_finish_t finish; glitz_gl_pixel_store_i_t pixel_store_i; glitz_gl_ortho_t ortho; - glitz_gl_scale_d_t scale_d; - glitz_gl_translate_d_t translate_d; + glitz_gl_scale_f_t scale_f; + glitz_gl_translate_f_t translate_f; glitz_gl_hint_t hint; glitz_gl_depth_mask_t depth_mask; glitz_gl_polygon_mode_t polygon_mode; @@ -131,7 +128,6 @@ typedef struct _glitz_gl_proc_address_list_t { glitz_gl_gen_textures_t gen_textures; glitz_gl_delete_textures_t delete_textures; glitz_gl_bind_texture_t bind_texture; - glitz_gl_tex_image_1d_t tex_image_1d; glitz_gl_tex_image_2d_t tex_image_2d; glitz_gl_tex_parameter_i_t tex_parameter_i; glitz_gl_get_tex_level_parameter_iv_t get_tex_level_parameter_iv; @@ -139,19 +135,21 @@ typedef struct _glitz_gl_proc_address_list_t { glitz_gl_get_integer_v_t get_integer_v; glitz_gl_active_texture_t active_texture; - glitz_gl_multi_tex_coord_2d_t multi_tex_coord_2d; glitz_gl_gen_programs_t gen_programs; glitz_gl_delete_programs_t delete_programs; glitz_gl_program_string_t program_string; glitz_gl_bind_program_t bind_program; - glitz_gl_program_local_param_4d_t program_local_param_4d; + glitz_gl_program_local_param_4fv_t program_local_param_4fv; glitz_gl_get_program_iv_t get_program_iv; glitz_gl_gen_buffers_t gen_buffers; glitz_gl_delete_buffers_t delete_buffers; glitz_gl_bind_buffer_t bind_buffer; glitz_gl_buffer_data_t buffer_data; + glitz_gl_buffer_sub_data_t buffer_sub_data; + glitz_gl_get_buffer_sub_data_t get_buffer_sub_data; glitz_gl_map_buffer_t map_buffer; glitz_gl_unmap_buffer_t unmap_buffer; + glitz_bool_t need_lookup; } glitz_gl_proc_address_list_t; @@ -214,7 +212,6 @@ typedef struct _glitz_filter_map_t { typedef struct _glitz_program_map_t { glitz_filter_map_t filters[GLITZ_COMBINE_TYPES][GLITZ_FP_TYPES]; - glitz_gl_int_t vp; } glitz_program_map_t; typedef enum { @@ -224,22 +221,16 @@ typedef enum { GLITZ_CN_SURFACE_DRAWABLE_CURRENT } glitz_constraint_t; -typedef enum { - GLITZ_TRIANGLE_TYPE_NORMAL, - GLITZ_TRIANGLE_TYPE_STRIP, - GLITZ_TRIANGLE_TYPE_FAN -} glitz_triangle_type_t; - typedef struct _glitz_bounding_box_t { int x1, x2, y1, y2; } glitz_bounding_box_t; typedef struct _glitz_point_t { - double x, y; + glitz_float_t x, y; } glitz_point_t; typedef struct _glitz_vec_t { - double v[4]; + glitz_float_t v[4]; } glitz_vec4_t; typedef struct _glitz_texture { @@ -254,12 +245,37 @@ typedef struct _glitz_texture { unsigned int width; unsigned int height; - double texcoord_width; - double texcoord_height; + glitz_float_t texcoord_width; + glitz_float_t texcoord_height; + glitz_float_t texcoord_width_unit; + glitz_float_t texcoord_height_unit; glitz_bool_t repeatable; } glitz_texture_t; +struct _glitz_buffer { + glitz_gl_sizei_t size; + glitz_gl_uint_t name; + glitz_gl_enum_t target; + void *data; + int owns_data; + int ref_count; + glitz_surface_t *surface; +}; + +typedef struct _glitz_geometry { + glitz_gl_enum_t primitive; + glitz_gl_enum_t type; + glitz_gl_int_t first; + glitz_gl_sizei_t count; + glitz_buffer_t *buffer; + glitz_float_t x_offset; + glitz_float_t y_offset; + + glitz_gl_uint_t default_name; + glitz_gl_float_t data[8]; +} glitz_geometry_t; + typedef struct glitz_surface_backend { glitz_surface_t * (*create_similar) (void *surface, @@ -282,139 +298,123 @@ typedef struct glitz_surface_backend { glitz_bool_t allocate); void - (*update_size) (void *surface); - - void (*swap_buffers) (void *surface); glitz_bool_t (*make_current_read) (void *surface); + + glitz_gl_proc_address_list_t gl; + glitz_format_t *formats; + int n_formats; + glitz_program_map_t *program_map; + unsigned long feature_mask; } glitz_surface_backend_t; -#define GLITZ_INT_HINT_SOLID_MASK (1L << 3) -#define GLITZ_INT_HINT_REPEAT_MASK (1L << 4) -#define GLITZ_INT_HINT_MIRRORED_MASK (1L << 5) -#define GLITZ_INT_HINT_PAD_MASK (1L << 6) -#define GLITZ_INT_HINT_CLIP_MASK (1L << 7) -#define GLITZ_INT_HINT_DIRTY_MASK (1L << 8) -#define GLITZ_INT_HINT_COMPONENT_ALPHA_MASK (1L << 9) -#define GLITZ_INT_HINT_MULTISAMPLE_MASK (1L << 10) -#define GLITZ_INT_HINT_SOLID_DIRTY_MASK (1L << 11) -#define GLITZ_INT_HINT_DRAWABLE_DIRTY_MASK (1L << 12) -#define GLITZ_INT_HINT_POLYGON_OP_MASK (1L << 13) -#define GLITZ_INT_HINT_FRAGMENT_FILTER_MASK (1L << 14) -#define GLITZ_INT_HINT_LINEAR_TRANSFORM_FILTER_MASK (1L << 15) -#define GLITZ_INT_HINT_WINDOW_SPACE_TEXCOORDS_MASK (1L << 16) -#define GLITZ_INT_HINT_DRAWABLE_MASK (1L << 17) -#define GLITZ_INT_HINT_IGNORE_REPEAT_MASK (1L << 18) +#define GLITZ_FLAG_SOLID_MASK (1L << 0) +#define GLITZ_FLAG_OFFSCREEN_MASK (1L << 1) +#define GLITZ_FLAG_REPEAT_MASK (1L << 2) +#define GLITZ_FLAG_MIRRORED_MASK (1L << 3) +#define GLITZ_FLAG_PAD_MASK (1L << 4) +#define GLITZ_FLAG_DIRTY_MASK (1L << 5) +#define GLITZ_FLAG_COMPONENT_ALPHA_MASK (1L << 6) +#define GLITZ_FLAG_MULTISAMPLE_MASK (1L << 7) +#define GLITZ_FLAG_NICEST_MULTISAMPLE_MASK (1L << 8) +#define GLITZ_FLAG_SOLID_DIRTY_MASK (1L << 9) +#define GLITZ_FLAG_DRAWABLE_DIRTY_MASK (1L << 10) +#define GLITZ_FLAG_FRAGMENT_FILTER_MASK (1L << 11) +#define GLITZ_FLAG_LINEAR_TRANSFORM_FILTER_MASK (1L << 12) +#define GLITZ_FLAG_DRAWABLE_MASK (1L << 13) +#define GLITZ_FLAG_IGNORE_REPEAT_MASK (1L << 14) +#define GLITZ_FLAG_TEXTURE_COORDS_MASK (1L << 15) #define SURFACE_OFFSCREEN(surface) \ - ((surface)->hint_mask & GLITZ_HINT_OFFSCREEN_MASK) + ((surface)->flags & GLITZ_FLAG_OFFSCREEN_MASK) #define SURFACE_SOLID(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_SOLID_MASK) + ((surface)->flags & GLITZ_FLAG_SOLID_MASK) #define SURFACE_REPEAT(surface) \ - (((surface)->hint_mask & GLITZ_INT_HINT_REPEAT_MASK) && \ - (!((surface)->hint_mask & GLITZ_INT_HINT_IGNORE_REPEAT_MASK))) + (((surface)->flags & GLITZ_FLAG_REPEAT_MASK) && \ + (!((surface)->flags & GLITZ_FLAG_IGNORE_REPEAT_MASK))) #define SURFACE_MIRRORED(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_MIRRORED_MASK) + ((surface)->flags & GLITZ_FLAG_MIRRORED_MASK) #define SURFACE_PAD(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_PAD_MASK) + ((surface)->flags & GLITZ_FLAG_PAD_MASK) #define SURFACE_DIRTY(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_DIRTY_MASK) + ((surface)->flags & GLITZ_FLAG_DIRTY_MASK) #define SURFACE_COMPONENT_ALPHA(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_COMPONENT_ALPHA_MASK) + ((surface)->flags & GLITZ_FLAG_COMPONENT_ALPHA_MASK) #define SURFACE_MULTISAMPLE(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_MULTISAMPLE_MASK) + ((surface)->flags & GLITZ_FLAG_MULTISAMPLE_MASK) + +#define SURFACE_NICEST_MULTISAMPLE(surface) \ + ((surface)->flags & GLITZ_FLAG_NICEST_MULTISAMPLE_MASK) #define SURFACE_SOLID_DIRTY(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_SOLID_DIRTY_MASK) + ((surface)->flags & GLITZ_FLAG_SOLID_DIRTY_MASK) #define SURFACE_DRAWABLE_DIRTY(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_DRAWABLE_DIRTY_MASK) - -#define SURFACE_POLYGON_OP(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_POLYGON_OP_MASK) + ((surface)->flags & GLITZ_FLAG_DRAWABLE_DIRTY_MASK) #define SURFACE_FRAGMENT_FILTER(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_FRAGMENT_FILTER_MASK) + ((surface)->flags & GLITZ_FLAG_FRAGMENT_FILTER_MASK) #define SURFACE_LINEAR_TRANSFORM_FILTER(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_LINEAR_TRANSFORM_FILTER_MASK) - -#define SURFACE_WINDOW_SPACE_TEXCOORDS(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_WINDOW_SPACE_TEXCOORDS_MASK) + ((surface)->flags & GLITZ_FLAG_LINEAR_TRANSFORM_FILTER_MASK) #define SURFACE_DRAWABLE(surface) \ - ((surface)->hint_mask & GLITZ_INT_HINT_DRAWABLE_MASK) + ((surface)->flags & GLITZ_FLAG_DRAWABLE_MASK) -#define SURFACE_CLIP(surface) \ - (((surface)->hint_mask & GLITZ_INT_HINT_CLIP_MASK) && \ - (!SURFACE_FRAGMENT_FILTER (surface)) && \ - (!(surface)->transform)) +#define SURFACE_TEXTURE_COORDS(surface) \ + ((surface)->flags & GLITZ_FLAG_TEXTURE_COORDS_MASK) typedef struct _glitz_sample_offset { - double x; - double y; + glitz_float_t x; + glitz_float_t y; } glitz_sample_offset_t; typedef struct _glitz_multi_sample_info { glitz_sample_offset_t *offsets; unsigned short *weights; int n_samples; -} glitz_multi_sample_info_t; - -/* GLITZ_BUFFER_BACK and GLITZ_BUFFER_FRONT */ -#define GLITZ_N_STENCIL_MASKS 2 +} glitz_sample_info_t; typedef struct _glitz_filter_params_t glitz_filter_params_t; -typedef struct _glitz_projective_transform { - double m[16]; - double m_norm[16]; -} glitz_projective_transform_t; +typedef struct _glitz_matrix { + glitz_float_t t[16]; + glitz_float_t m[16]; +} glitz_matrix_t; #define GLITZ_UPDATE_VIEWPORT_MASK (1L << 0) -#define GLITZ_UPDATE_SCISSOR_MASK (1L << 1) -#define GLITZ_UPDATE_DRAW_BUFFER_MASK (1L << 2) -#define GLITZ_UPDATE_STENCIL_OP_MASK (1L << 3) -#define GLITZ_UPDATE_MULTISAMPLE_MASK (1L << 4) -#define GLITZ_UPDATE_ALL_MASK ((1L << 5) - 1) +#define GLITZ_UPDATE_DRAW_BUFFER_MASK (1L << 1) +#define GLITZ_UPDATE_MULTISAMPLE_MASK (1L << 2) +#define GLITZ_UPDATE_ALL_MASK ((1L << 3) - 1) struct _glitz_surface { - const glitz_surface_backend_t *backend; + glitz_surface_backend_t *backend; int ref_count; glitz_format_t *format; - glitz_format_t *formats; - int n_formats; glitz_texture_t texture; unsigned long status_mask; - unsigned long feature_mask; unsigned long update_mask; glitz_filter_t filter; glitz_filter_params_t *filter_params; - glitz_polyedge_t polyedge; - glitz_polyedge_smooth_hint_t polyedge_smooth_hint; - glitz_projective_transform_t *transform; + glitz_matrix_t *transform; int width, height; glitz_bounding_box_t dirty_box; - glitz_gl_proc_address_list_t *gl; - glitz_program_map_t *program_map; - unsigned int stencil_masks[GLITZ_N_STENCIL_MASKS]; - unsigned int *stencil_mask; - unsigned long hint_mask; - unsigned short polyopacity; + unsigned long flags; glitz_gl_enum_t draw_buffer; glitz_gl_enum_t read_buffer; - glitz_multi_sample_info_t *multi_sample; + glitz_sample_info_t *indirect; glitz_color_t solid; + glitz_geometry_t geometry; }; typedef struct _glitz_composite_op_t glitz_composite_op_t; @@ -445,7 +445,6 @@ struct _glitz_composite_op_t { glitz_color_t alpha_mask; glitz_component_alpha_type_t component_alpha; glitz_gl_uint_t fp; - glitz_gl_uint_t vp; int count; }; @@ -454,30 +453,9 @@ typedef struct _glitz_extension_map { int mask; } glitz_extension_map; -typedef enum glitz_int_operator { - GLITZ_INT_OPERATOR_STENCIL_RECT_SET = 1000, - GLITZ_INT_OPERATOR_STENCIL_RECT_SRC -} glitz_int_operator_t; - extern void __internal_linkage glitz_set_operator (glitz_gl_proc_address_list_t *gl, glitz_operator_t op); -typedef enum glitz_stencil_operator { - GLITZ_STENCIL_OPERATOR_SET = GLITZ_CLIP_OPERATOR_SET, - GLITZ_STENCIL_OPERATOR_UNION = GLITZ_CLIP_OPERATOR_UNION, - GLITZ_STENCIL_OPERATOR_INTERSECT = GLITZ_CLIP_OPERATOR_INTERSECT, - GLITZ_STENCIL_OPERATOR_CLEAR, - GLITZ_STENCIL_OPERATOR_INCR_EQUAL, - GLITZ_STENCIL_OPERATOR_DECR_LESS, - GLITZ_STENCIL_OPERATOR_CLIP_EQUAL, - GLITZ_STENCIL_OPERATOR_CLIP -} glitz_stencil_operator_t; - -extern void __internal_linkage -glitz_set_stencil_operator (glitz_gl_proc_address_list_t *gl, - glitz_stencil_operator_t op, - unsigned int mask); - void glitz_intersect_bounding_box (glitz_bounding_box_t *box1, glitz_bounding_box_t *box2, @@ -501,7 +479,8 @@ glitz_set_raster_pos (glitz_gl_proc_address_list_t *gl, int y); extern void __internal_linkage -glitz_clamp_value (double *value, double min, double max); +glitz_clamp_value (glitz_float_t *value, + glitz_float_t min, glitz_float_t max); void glitz_texture_init (glitz_texture_t *texture, @@ -547,22 +526,19 @@ glitz_texture_copy_surface (glitz_texture_t *texture, int y_texture); void -glitz_texture_tex_coord (glitz_texture_t *texture, - double x, - double y, - double *return_x, - double *return_y); +glitz_texture_set_tex_gen (glitz_gl_proc_address_list_t *gl, + glitz_texture_t *texture, + int x_src, + int y_src, + int height, + unsigned long flags); void glitz_surface_init (glitz_surface_t *surface, - const glitz_surface_backend_t *backend, - glitz_gl_proc_address_list_t *gl, + glitz_surface_backend_t *backend, glitz_format_t *format, - glitz_format_t *formats, - int n_formats, int width, int height, - glitz_program_map_t *program_map, unsigned long texture_mask); void @@ -573,12 +549,6 @@ glitz_surface_get_texture (glitz_surface_t *surface, glitz_bool_t allocate); extern void __internal_linkage -glitz_surface_reference (glitz_surface_t *surface); - -extern void __internal_linkage -glitz_surface_destory (glitz_surface_t *surface); - -extern void __internal_linkage glitz_surface_ensure_solid (glitz_surface_t *surface); glitz_bool_t @@ -601,12 +571,6 @@ glitz_surface_status_add (glitz_surface_t *surface, int flags); void glitz_surface_update_state (glitz_surface_t *surface); -extern void __internal_linkage -glitz_surface_enable_anti_aliasing (glitz_surface_t *surface); - -extern void __internal_linkage -glitz_surface_disable_anti_aliasing (glitz_surface_t *surface); - extern unsigned long __internal_linkage glitz_status_to_status_mask (glitz_status_t status); @@ -617,7 +581,7 @@ typedef void (*glitz_format_call_back_t) (glitz_format_t *, void *ptr); void glitz_format_for_each_texture_format (glitz_format_call_back_t call_back, - glitz_gl_proc_address_list_t *gl, + glitz_gl_proc_address_list_t *gl, void *ptr); glitz_format_t * @@ -645,67 +609,11 @@ glitz_program_map_fini (glitz_gl_proc_address_list_t *gl, glitz_program_map_t *map); extern glitz_gl_uint_t __internal_linkage -glitz_get_vertex_program (glitz_composite_op_t *op); - -extern glitz_gl_uint_t __internal_linkage glitz_get_fragment_program (glitz_composite_op_t *op, int fp_type, int id); extern void __internal_linkage -glitz_int_fill_rectangles (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_rectangle_t *rects, - int n_rects); - -extern void __internal_linkage -glitz_int_fill_trapezoids (glitz_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_trapezoid_t *traps, - int n_traps); - -extern void __internal_linkage -glitz_int_fill_triangles (glitz_operator_t op, - glitz_surface_t *dst, - glitz_triangle_type_t type, - int x_offset, - int y_offset, - const glitz_color_t *color, - const glitz_point_fixed_t *points, - int n_points); - -extern void __internal_linkage -glitz_stencil_rectangles (glitz_stencil_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_rectangle_t *rects, - int n_rects); - -extern void __internal_linkage -glitz_stencil_trapezoids (glitz_stencil_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - const glitz_trapezoid_t *traps, - int n_traps); - -extern void __internal_linkage -glitz_stencil_triangles (glitz_stencil_operator_t op, - glitz_surface_t *dst, - int x_offset, - int y_offset, - glitz_triangle_type_t type, - const glitz_point_fixed_t *points, - int n_points); - -extern void __internal_linkage glitz_composite_op_init (glitz_composite_op_t *op, glitz_surface_t *src, glitz_surface_t *mask, @@ -717,12 +625,12 @@ glitz_composite_enable (glitz_composite_op_t *op); extern void __internal_linkage glitz_composite_disable (glitz_composite_op_t *op); -extern char *__internal_linkage -glitz_pixel_buffer_bind (glitz_pixel_buffer_t *buffer, - glitz_gl_enum_t target); +extern void *__internal_linkage +glitz_buffer_bind (glitz_buffer_t *buffer, + glitz_gl_enum_t target); extern void __internal_linkage -glitz_pixel_buffer_unbind (glitz_pixel_buffer_t *buffer); +glitz_buffer_unbind (glitz_buffer_t *buffer); extern glitz_status_t __internal_linkage glitz_filter_set_params (glitz_surface_t *surface, @@ -749,6 +657,21 @@ extern void __internal_linkage glitz_filter_enable (glitz_surface_t *surface, glitz_composite_op_t *op); +extern void __internal_linkage +glitz_geometry_enable_default (glitz_gl_proc_address_list_t *gl, + glitz_surface_t *dst); + +extern void __internal_linkage +glitz_geometry_enable (glitz_gl_proc_address_list_t *gl, + glitz_surface_t *dst, + glitz_gl_enum_t *primitive, + glitz_gl_int_t *first, + glitz_gl_sizei_t *count); + +extern void __internal_linkage +glitz_geometry_disable (glitz_gl_proc_address_list_t *gl, + glitz_surface_t *dst); + #define MAXSHORT SHRT_MAX #define MINSHORT SHRT_MIN @@ -766,7 +689,7 @@ glitz_filter_enable (glitz_surface_t *surface, # define BITMAP_BIT_ORDER LSBFirst #endif -#define GLITZ_PI 3.14159265358979323846 +#define GLITZ_PI 3.14159265358979323846f /* Fixed point updates from Carl Worth, USC, Information Sciences Institute */ @@ -813,8 +736,8 @@ typedef glitz_fixed_16_16 glitz_fixed; #define FIXED_FRACTION(f) ((f) & FIXED1_MINUS_E) #define FIXED_MOD2(f) ((f) & (FIXED1 | FIXED1_MINUS_E)) -#define FIXED_TO_DOUBLE(f) (((double) (f)) / 65536) -#define DOUBLE_TO_FIXED(f) ((int) ((f) * 65536)) +#define FIXED_TO_FLOAT(f) (((glitz_float_t) (f)) / 65536) +#define FLOAT_TO_FIXED(f) ((int) ((f) * 65536)) #define SHORT_MULT(s1, s2) \ ((s1 == 0xffff)? s2: ((s2 == 0xffff)? s1: \ @@ -832,36 +755,20 @@ slim_hidden_proto(glitz_surface_set_transform) slim_hidden_proto(glitz_surface_set_fill) slim_hidden_proto(glitz_surface_set_component_alpha) slim_hidden_proto(glitz_surface_set_filter) -slim_hidden_proto(glitz_surface_set_polyedge) slim_hidden_proto(glitz_surface_get_width) slim_hidden_proto(glitz_surface_get_height) -slim_hidden_proto(glitz_surface_update_size) -slim_hidden_proto(glitz_surface_set_read_buffer) -slim_hidden_proto(glitz_surface_set_draw_buffer) +slim_hidden_proto(glitz_surface_set_read_color_buffer) +slim_hidden_proto(glitz_surface_set_draw_color_buffer) slim_hidden_proto(glitz_surface_flush) slim_hidden_proto(glitz_surface_swap_buffers) slim_hidden_proto(glitz_surface_finish) slim_hidden_proto(glitz_surface_get_status) -slim_hidden_proto(glitz_surface_get_gl_texture) -slim_hidden_proto(glitz_surface_gl_begin) -slim_hidden_proto(glitz_surface_gl_end) slim_hidden_proto(glitz_surface_get_features) -slim_hidden_proto(glitz_surface_clip_rectangles) -slim_hidden_proto(glitz_surface_clip_trapezoids) -slim_hidden_proto(glitz_surface_clip_triangles) slim_hidden_proto(glitz_surface_get_format) -slim_hidden_proto(glitz_surface_get_hints) -slim_hidden_proto(glitz_fill_rectangle) -slim_hidden_proto(glitz_fill_rectangles) -slim_hidden_proto(glitz_fill_trapezoids) -slim_hidden_proto(glitz_add_trapezoids) -slim_hidden_proto(glitz_composite_trapezoids) -slim_hidden_proto(glitz_color_trapezoids) -slim_hidden_proto(glitz_fill_triangles) -slim_hidden_proto(glitz_add_triangles) -slim_hidden_proto(glitz_composite_triangles) -slim_hidden_proto(glitz_composite_tri_strip) -slim_hidden_proto(glitz_composite_tri_fan) -slim_hidden_proto(glitz_color_triangles) +slim_hidden_proto(glitz_set_rectangle) +slim_hidden_proto(glitz_set_rectangles) +slim_hidden_proto(glitz_set_geometry) +slim_hidden_proto(glitz_buffer_set_data) +slim_hidden_proto(glitz_buffer_get_data) #endif /* GLITZINT_H_INCLUDED */ |