Enlightenment CVS committal
Author : raster
Project : e17
Module : libs/evas
Dir : e17/libs/evas/src/lib/engines/gl_common
Modified Files:
evas_gl_context.c evas_gl_font.c evas_gl_private.h
evas_gl_texture.c
Log Message:
open gl is fulyl functional now - it coudl defnitely do with optimizations
with texture upload. it does NOt check error returns anywhere from gl... this
may mean issues with LOTs of images, LARGE images etc. need to fix that later
===================================================================
RCS file:
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/gl_common/evas_gl_context.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- evas_gl_context.c 7 Sep 2003 11:24:48 -0000 1.1
+++ evas_gl_context.c 9 Sep 2003 05:51:02 -0000 1.2
@@ -65,8 +65,16 @@
{
if (strstr(ext, "GL_SGIS_generate_mipmap")) gc->ext.sgis_generate_mipmap
= 1;
if (strstr(ext, "GL_NV_texture_rectangle")) gc->ext.nv_texture_rectangle
= 1;
- printf("EXT supported: GL_SGIS_generate_mipmap = %x\n",
gc->ext.sgis_generate_mipmap);
- printf("EXT supported: GL_NV_texture_rectangle = %x\n",
gc->ext.nv_texture_rectangle);
+ /* technically this should work, as its a compatible */
+ /* implementation of the nvidia texture_rectangle extension */
+ /* since the #define value is the same as is the description */
+ /* if (strstr(ext, "GL_EXT_texture_rectangle"))
gc->ext.nv_texture_rectangle = 1; */
+ printf("GL EXT supported: GL_SGIS_generate_mipmap = %x\n",
gc->ext.sgis_generate_mipmap);
+ printf("GL EXT supported: GL_NV_texture_rectangle = %x\n",
gc->ext.nv_texture_rectangle);
+ }
+ else
+ {
+ printf("GL EXT supported: No extensions!!!!!\n");
}
gc->ext.checked = 1;
}
@@ -76,6 +84,7 @@
_evas_gl_common_blend_set(gc);
_evas_gl_common_color_set(gc);
_evas_gl_common_texture_set(gc);
+ _evas_gl_common_texture_set(gc);
_evas_gl_common_clip_set(gc);
_evas_gl_common_buf_set(gc);
_evas_gl_common_other_set(gc);
@@ -132,6 +141,11 @@
void
evas_gl_common_context_texture_set(Evas_GL_Context *gc, Evas_GL_Texture *tex, int
smooth, int w, int h)
{
+ if (gc->font_texture > 0)
+ {
+ gc->font_texture = 0;
+ gc->change.texture = 1;
+ }
if (gc->texture != tex)
{
if (gc->texture) gc->texture->references--;
@@ -154,6 +168,24 @@
}
void
+evas_gl_common_context_font_texture_set(Evas_GL_Context *gc, Evas_GL_Font_Texture *ft)
+{
+ if (gc->texture)
+ {
+ if (gc->texture) gc->texture->references--;
+ gc->texture = NULL;
+ gc->change.texture = 1;
+ }
+ if (gc->font_texture != ft->texture)
+ {
+ gc->font_texture = ft->texture;
+ gc->font_texture_not_power_of_two = ft->pool->not_power_of_two;
+ gc->change.texture = 1;
+ }
+ if (_evas_gl_common_context == gc) _evas_gl_common_texture_set(gc);
+}
+
+void
evas_gl_common_context_clip_set(Evas_GL_Context *gc, int on, int x, int y, int w, int
h)
{
if (((!on) && (!gc->clip.active)) ||
@@ -245,7 +277,23 @@
_evas_gl_common_texture_set(Evas_GL_Context *gc)
{
if (!gc->change.texture) return;
- if (gc->texture)
+ if (gc->font_texture > 0)
+ {
+ if (gc->font_texture_not_power_of_two)
+ {
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_TEXTURE_RECTANGLE_NV);
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV, gc->font_texture);
+ }
+ else
+ {
+ if (gc->ext.nv_texture_rectangle)
+ glDisable(GL_TEXTURE_RECTANGLE_NV);
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, gc->font_texture);
+ }
+ }
+ else if (gc->texture)
{
if (gc->texture->not_power_of_two)
{
@@ -255,7 +303,7 @@
}
else
{
- glDisable(GL_TEXTURE_RECTANGLE_NV);
+ if (gc->ext.nv_texture_rectangle) glDisable(GL_TEXTURE_RECTANGLE_NV);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, gc->texture->texture);
}
@@ -287,8 +335,11 @@
}
}
}
- else
- glDisable(GL_TEXTURE_2D);
+ else if (gc->font_texture == 0)
+ {
+ glDisable(GL_TEXTURE_2D);
+ if (gc->ext.nv_texture_rectangle) glDisable(GL_TEXTURE_RECTANGLE_NV);
+ }
gc->change.texture = 0;
}
===================================================================
RCS file:
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/gl_common/evas_gl_font.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- evas_gl_font.c 7 Sep 2003 11:24:48 -0000 1.1
+++ evas_gl_font.c 9 Sep 2003 05:51:02 -0000 1.2
@@ -1 +1,370 @@
#include "evas_gl_private.h"
+
+static Evas_GL_Font_Texture_Pool_Allocation
*_evas_gl_font_texture_pool_request(Evas_GL_Context *gc, int w, int h);
+static void
_evas_gl_font_texture_pool_relinquish(Evas_GL_Font_Texture_Pool_Allocation *fa);
+static int
_evas_gl_font_texture_pool_rect_find(Evas_GL_Font_Texture_Pool *fp, int w, int h, int
*x, int *y);
+
+static Evas_GL_Font_Texture_Pool_Allocation *
+_evas_gl_font_texture_pool_request(Evas_GL_Context *gc, int w, int h)
+{
+ Evas_List *l;
+ Evas_GL_Font_Texture_Pool_Allocation *fa;
+ Evas_GL_Font_Texture_Pool *fp;
+ int minw = 256;
+ int minh = 256;
+ int shift;
+
+ for (l = gc->tex_pool; l; l = l->next)
+ {
+ int x, y;
+
+ fp = l->data;
+ if (_evas_gl_font_texture_pool_rect_find(fp, w, h, &x, &y))
+ {
+ fa = calloc(1, sizeof(Evas_GL_Font_Texture_Pool_Allocation));
+ if (!fa) return NULL;
+ fa->pool = fp;
+ fa->x = x;
+ fa->y = y;
+ fa->w = w;
+ fa->h = h;
+ fp->allocations = evas_list_prepend(fp->allocations, fa);
+ fp->references++;
+ return fa;
+ }
+ }
+ /* need new font texture pool entry */
+ /* minimum size either minw x minh OR the size of glyph up to power 2 */
+ if (w > minw)
+ {
+ minw = w;
+ shift = 1; while (minw > shift) shift = shift << 1; minw = shift;
+ }
+ if (h > minh)
+ {
+ minh = h;
+ shift = 1; while (minh > shift) shift = shift << 1; minh = shift;
+ }
+
+ fp = calloc(1, sizeof(Evas_GL_Font_Texture_Pool));
+ if (!fp) return NULL;
+ fp->gc = gc;
+ fp->w = minw;
+ fp->h = minh;
+ if (gc->ext.nv_texture_rectangle) fp->not_power_of_two = 1;
+ gc->tex_pool = evas_list_append(gc->tex_pool, fp);
+
+ if (gc->ext.sgis_generate_mipmap)
+ glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_FALSE);
+ glEnable(GL_TEXTURE_2D);
+ if (fp->not_power_of_two)
+ {
+ glEnable(GL_TEXTURE_RECTANGLE_NV);
+ glGenTextures(1, &(fp->texture));
+
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV, fp->texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0,
+ GL_ALPHA8, fp->w, fp->h, 0,
+ GL_ALPHA, GL_UNSIGNED_BYTE, NULL);
+ }
+ else
+ {
+ glGenTextures(1, &(fp->texture));
+
+ glBindTexture(GL_TEXTURE_2D, fp->texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D, 0,
+ GL_ALPHA8, fp->w, fp->h, 0,
+ GL_ALPHA, GL_UNSIGNED_BYTE, NULL);
+ }
+
+ /* new allocation entirely */
+ fa = calloc(1, sizeof(Evas_GL_Font_Texture_Pool_Allocation));
+ if (!fa) return NULL;
+ fa->pool = fp;
+ fa->x = 0;
+ fa->y = 0;
+ fa->w = w;
+ fa->h = h;
+ fp->allocations = evas_list_prepend(fp->allocations, fa);
+ fp->references++;
+ return fa;
+}
+
+static void
+_evas_gl_font_texture_pool_relinquish(Evas_GL_Font_Texture_Pool_Allocation *fa)
+{
+ fa->pool->allocations = evas_list_remove(fa->pool->allocations, fa);
+ fa->pool->references--;
+ if (fa->pool->references <= 0)
+ {
+ fa->pool->gc->tex_pool =
+ evas_list_remove(fa->pool->gc->tex_pool, fa->pool);
+ glDeleteTextures(1, &(fa->pool->texture));
+ free(fa->pool);
+ }
+ free(fa);
+}
+
+static int
+_evas_gl_font_texture_pool_rect_find(Evas_GL_Font_Texture_Pool *fp,
+ int w, int h,
+ int *x, int *y)
+{
+ Evas_List *l;
+
+ if ((w > fp->w) || (h > fp->h)) return 0;
+ for (l = fp->allocations; l; l = l->next)
+ {
+ Evas_GL_Font_Texture_Pool_Allocation *fa;
+ Evas_List *l2;
+ int tx, ty, tw, th;
+ int t1, t2;
+ int intersects;
+
+ fa = l->data;
+ t1 = t2 = 1;
+ if ((fa->x + fa->w + w) > fp->w) t1 = 0;
+ if ((fa->y + h) > fp->h) t1 = 0;
+ if ((fa->y + fa->h + h) > fp->h) t2 = 0;
+ if ((fa->x + w) > fp->w) t2 = 0;
+ intersects = 0;
+ if (t1)
+ {
+ /* 1. try here:
+ * +----++--+
+ * |AAAA||??|
+ * |AAAA|+--+
+ * |AAAA|
+ * +----+
+ */
+ tx = fa->x + fa->w;
+ ty = fa->y;
+ tw = w;
+ th = h;
+ for (l2 = fp->allocations; l2; l2 = l2->next)
+ {
+ Evas_GL_Font_Texture_Pool_Allocation *fa2;
+ int rx, ry, rw, rh;
+
+ /* dont do the rect we are just using as our offset */
+ if (l2 == l) continue;
+ fa2 = l2->data;
+ rx = fa2->x;
+ ry = fa2->y;
+ rw = fa2->w;
+ rh = fa2->h;
+ if (RECTS_INTERSECT(tx, ty, tw, th, rx, ry, rw, rh))
+ {
+ intersects = 1;
+ break;
+ }
+ }
+ if (!intersects)
+ {
+ *x = tx;
+ *y = ty;
+ return 1;
+ }
+ }
+ intersects = 0;
+ if (t2)
+ {
+ /* 2. try here:
+ * +----+
+ * |AAAA|
+ * |AAAA|
+ * |AAAA|
+ * +----+
+ * +--+
+ * |??|
+ * +--+
+ */
+ tx = fa->x;
+ ty = fa->y + fa->h;
+ tw = w;
+ th = h;
+ for (l2 = fp->allocations; l2; l2 = l2->next)
+ {
+ Evas_GL_Font_Texture_Pool_Allocation *fa2;
+ int rx, ry, rw, rh;
+
+ /* dont do the rect we are just using as our offset */
+ if (l2 == l) continue;
+ fa2 = l2->data;
+
+ rx = fa2->x;
+ ry = fa2->y;
+ rw = fa2->w;
+ rh = fa2->h;
+ if (RECTS_INTERSECT(tx, ty, tw, th, rx, ry, rw, rh))
+ {
+ intersects = 1;
+ break;
+ }
+ }
+ if (!intersects)
+ {
+ *x = tx;
+ *y = ty;
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
+Evas_GL_Font_Texture *
+evas_gl_font_texture_new(Evas_GL_Context *gc, RGBA_Font_Glyph *fg)
+{
+ Evas_GL_Font_Texture *ft;
+ DATA8 *data;
+ int w, h, j;
+
+ int nw;
+ DATA8 *ndata;
+
+ ft = calloc(1, sizeof(Evas_GL_Font_Texture));
+ if (!ft) return NULL;
+
+ data = fg->glyph_out->bitmap.buffer;
+ w = fg->glyph_out->bitmap.width;
+ h = fg->glyph_out->bitmap.rows;
+ j = fg->glyph_out->bitmap.pitch;
+ if (j < w) j = w;
+
+ ft->gc = gc;
+
+ /* bug bug! glTexSubImage2D need a multiple of 4 pixels horizontally! :( */
+ nw = ((w + 3) / 4 ) * 4;
+ ndata = malloc(nw *h);
+ if (!ndata)
+ {
+ free(ft);
+ return NULL;
+ }
+ {
+ int x, y;
+ DATA8 *p1, *p2;
+
+ for (y = 0; y < h; y++)
+ {
+ p1 = data + (j * y);
+ p2 = ndata + (nw * y);
+ for (x = 0; x < w; x++)
+ {
+ *p2 = *p1;
+ p1++;
+ p2++;
+ }
+ }
+ }
+
+ /* where in pool texture does this live */
+ ft->w = w;
+ ft->h = h;
+ ft->aw = nw;
+ ft->ah = h;
+
+ ft->alloc = _evas_gl_font_texture_pool_request(gc, ft->aw, ft->ah);
+ ft->x = ft->alloc->x;
+ ft->y = ft->alloc->y;
+ ft->pool = ft->alloc->pool;
+ ft->texture = ft->pool->texture;
+ if (ft->pool->not_power_of_two)
+ {
+ glEnable(GL_TEXTURE_RECTANGLE_NV);
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV, ft->texture);
+ glTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0,
+ ft->x, ft->y, nw, ft->h,
+ GL_ALPHA, GL_UNSIGNED_BYTE, ndata);
+ }
+ else
+ {
+ glBindTexture(GL_TEXTURE_2D, ft->texture);
+ glTexSubImage2D(GL_TEXTURE_2D, 0,
+ ft->x, ft->y, nw, ft->h,
+ GL_ALPHA, GL_UNSIGNED_BYTE, ndata);
+ }
+ if (ndata) free(ndata);
+ if (gc->texture)
+ {
+ if (gc->texture) gc->texture->references--;
+ gc->texture = NULL;
+ }
+ gc->font_texture = ft->texture;
+ gc->font_texture_not_power_of_two = ft->pool->not_power_of_two;
+ gc->change.texture = 1;
+
+ return ft;
+}
+
+void
+evas_gl_font_texture_free(Evas_GL_Font_Texture *ft)
+{
+ if (ft->gc->font_texture == ft->texture)
+ {
+ ft->gc->font_texture = 0;
+ ft->gc->change.texture = 1;
+ }
+
+ _evas_gl_font_texture_pool_relinquish(ft->alloc);
+ free(ft);
+}
+
+void
+evas_gl_font_texture_draw(Evas_GL_Context *gc, void *surface, RGBA_Draw_Context *dc,
RGBA_Font_Glyph *fg, int x, int y)
+{
+ int r, g, b, a;
+ Evas_GL_Font_Texture *ft;
+
+ ft = fg->ext_dat;
+ if (!ft) return;
+ a = (dc->col.col >> 24) & 0xff;
+ r = (dc->col.col >> 16) & 0xff;
+ g = (dc->col.col >> 8 ) & 0xff;
+ b = (dc->col.col ) & 0xff;
+ evas_gl_common_context_color_set(gc, r, g, b, a);
+ if (dc->clip.use)
+ evas_gl_common_context_clip_set(gc, 1,
+ dc->clip.x, dc->clip.y,
+ dc->clip.w, dc->clip.h);
+ else
+ evas_gl_common_context_clip_set(gc, 0,
+ 0, 0, 0, 0);
+ evas_gl_common_context_font_texture_set(gc, ft);
+ evas_gl_common_context_blend_set(gc, 1);
+ evas_gl_common_context_read_buf_set(gc, GL_BACK);
+ evas_gl_common_context_write_buf_set(gc, GL_BACK);
+ {
+ double tx1, ty1, tx2, ty2;
+
+ if (ft->pool->not_power_of_two)
+ {
+ tx1 = ft->x;
+ ty1 = ft->y;
+ tx2 = ft->x + ft->w;
+ ty2 = ft->y + ft->h;
+ }
+ else
+ {
+ tx1 = (double)(ft->x ) / (double)(ft->pool->w);
+ ty1 = (double)(ft->y ) / (double)(ft->pool->h);
+ tx2 = (double)(ft->x + ft->w) / (double)(ft->pool->w);
+ ty2 = (double)(ft->y + ft->h) / (double)(ft->pool->h);
+ }
+ glBegin(GL_QUADS);
+ glTexCoord2d(tx1, ty1); glVertex2i(x , y );
+ glTexCoord2d(tx2, ty1); glVertex2i(x + ft->w, y );
+ glTexCoord2d(tx2, ty2); glVertex2i(x + ft->w, y + ft->h);
+ glTexCoord2d(tx1, ty2); glVertex2i(x , y + ft->h);
+ glEnd();
+ }
+}
===================================================================
RCS file:
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/gl_common/evas_gl_private.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- evas_gl_private.h 7 Sep 2003 11:24:48 -0000 1.1
+++ evas_gl_private.h 9 Sep 2003 05:51:02 -0000 1.2
@@ -3,7 +3,7 @@
#include "evas_gl_common.h"
-#if 0
+#if 1
/* nvidia extensions */
extern void glPixelDataRangeNV(GLenum target, GLsizei length, void *pointer);
#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878
===================================================================
RCS file:
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/gl_common/evas_gl_texture.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- evas_gl_texture.c 7 Sep 2003 11:24:48 -0000 1.1
+++ evas_gl_texture.c 9 Sep 2003 05:51:03 -0000 1.2
@@ -13,10 +13,8 @@
tex = calloc(1, sizeof(Evas_GL_Texture));
if (!tex) return NULL;
- if ((gc->ext.nv_texture_rectangle) && (1))
+ if (gc->ext.nv_texture_rectangle)
{
- printf("new rect tex %ix%i\n", im->image->w, im->image->h);
-
tex->gc = gc;
tex->w = im->image->w;
tex->h = im->image->h;
@@ -52,12 +50,12 @@
tex->gc = gc;
tex->w = tw;
tex->h = th;
- printf("new tex %ix%i\n", tw, th);
tex->tw = im->image->w;
tex->th = im->image->h;
tex->references = 0;
tex->smooth = 0;
tex->changed = 1;
+ if (gc->ext.nv_texture_rectangle) glDisable(GL_TEXTURE_RECTANGLE_NV);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &(tex->texture));
glBindTexture(GL_TEXTURE_2D, tex->texture);
@@ -151,7 +149,9 @@
glPixelDataRangeNV(GL_WRITE_PIXEL_DATA_RANGE_NV,
im->image->w * im->image->h * 4,
im->image->data);
+ printf("ER1: %s\n", gluErrorString(glGetError()));
glEnableClientState(GL_WRITE_PIXEL_DATA_RANGE_NV);
+ printf("ER2: %s\n", gluErrorString(glGetError()));
tex->opt = 1;
}
*/
@@ -186,6 +186,7 @@
th = tex->h;
tex->changed = 1;
tex->have_mipmaps = 0;
+ if (tex->gc->ext.nv_texture_rectangle) glDisable(GL_TEXTURE_RECTANGLE_NV);
glEnable(GL_TEXTURE_2D);
if (tex->not_power_of_two)
{
@@ -310,6 +311,7 @@
pixfmt = NATIVE_PIX_FORMAT;
printf("building mipmaps... [%i x %i]\n", tw, th);
+ if (tex->gc->ext.nv_texture_rectangle) glDisable(GL_TEXTURE_RECTANGLE_NV);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex->texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs