[gegl/gsoc2009-gpu] Do not allocate GPU texture memory lazily



commit b80a22c8947f57a9729f954d15d121e74adca0f5
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date:   Thu Jul 9 03:07:48 2009 +0800

    Do not allocate GPU texture memory lazily

 gegl/gpu/gegl-gpu-texture.c |   39 ++++++++-------------------------------
 1 files changed, 8 insertions(+), 31 deletions(-)
---
diff --git a/gegl/gpu/gegl-gpu-texture.c b/gegl/gpu/gegl-gpu-texture.c
index ff4473a..9c1fef4 100644
--- a/gegl/gpu/gegl-gpu-texture.c
+++ b/gegl/gpu/gegl-gpu-texture.c
@@ -25,9 +25,13 @@
 #include "gegl-gpu-types.h"
 #include "gegl-gpu-texture.h"
 
-static void
-allocate_texture_data (GeglGpuTexture *texture)
+GeglGpuTexture *
+gegl_gpu_texture_new (gint        width,
+                      gint        height,
+                      const Babl *format)
 {
+  GeglGpuTexture *texture = g_new (GeglGpuTexture, 1);
+
   glGenTextures (1, &texture->handle);
   glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture->handle);
 
@@ -39,20 +43,11 @@ allocate_texture_data (GeglGpuTexture *texture)
   glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
 
   glTexImage2D  (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA32F_ARB,
-                 texture->width, texture->height, 0, GL_RGBA, GL_FLOAT, 0);
+                 width, height, 0, GL_RGBA, GL_FLOAT, 0);
   glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
 
   gegl_gpu_texture_clear (texture, NULL);
-}
 
-GeglGpuTexture *
-gegl_gpu_texture_new (gint        width,
-                      gint        height,
-                      const Babl *format)
-{
-  GeglGpuTexture *texture = g_new (GeglGpuTexture, 1);
-
-  texture->handle = 0;
   texture->width  = width;
   texture->height = height;
 
@@ -66,10 +61,7 @@ gegl_gpu_texture_new (gint        width,
 void
 gegl_gpu_texture_free (GeglGpuTexture *texture)
 {
-  if (texture->handle > 0)
-    {
-      glDeleteTextures (1, &texture->handle);
-    }
+  glDeleteTextures (1, &texture->handle);
   g_free (texture);
 }
 
@@ -84,9 +76,6 @@ gegl_gpu_texture_get (const GeglGpuTexture *texture,
                          ? roi->width * roi->height
                          : gegl_gpu_texture_get_pixel_count (texture);
 
-  if (texture->handle == 0)
-    allocate_texture_data ((GeglGpuTexture *) texture);
-
   if (format != NULL && format != texture->format)
     {
       gint bpp = babl_format_get_bytes_per_pixel (texture->format);
@@ -129,9 +118,6 @@ gegl_gpu_texture_set (GeglGpuTexture      *texture,
 {
   gpointer buf;
 
-  if (texture->handle == 0)
-    allocate_texture_data (texture);
-
   if (format != NULL && format != texture->format)
     {
       Babl *fish = babl_fish ((gpointer) format,
@@ -176,9 +162,6 @@ gegl_gpu_texture_clear (GeglGpuTexture      *texture,
 {
   gint bpp = babl_format_get_bytes_per_pixel (texture->format);
 
-  if (texture->handle == 0)
-    allocate_texture_data (texture);
-
   if (roi == NULL || (roi->x == 0 && roi->y == 0
         && roi->width == texture->width
         && roi->height == texture->height))
@@ -211,12 +194,6 @@ gegl_gpu_texture_copy (const GeglGpuTexture *src,
                        gint                  dest_x,
                        gint                  dest_y)
 {
-  if (src->handle == 0)
-    allocate_texture_data ((GeglGpuTexture *) src);
-
-  if (dest->handle == 0)
-    allocate_texture_data (dest);
-
   if (src->format == dest->format)
     {
       glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]