Fix pow <small> and a very stypid bug with dummy srcs(0 equals to tmp0.x)</small...
[mesa.git] / src / mesa / main / texrender.c
index f7f3fdb4b0bb1f79d52493f77b0222691685af01..a4efe64038246498e6853390db9231819b533a80 100644 (file)
@@ -27,14 +27,29 @@ static void
 texture_get_row(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
                 GLint x, GLint y, void *values)
 {
-   /* XXX unfinished */
+   const struct texture_renderbuffer *trb
+      = (const struct texture_renderbuffer *) rb;
+   const GLint z = trb->Zoffset;
+   GLchan *rgbaOut = (GLchan *) values;
+   GLuint i;
+   for (i = 0; i < count; i++) {
+      trb->TexImage->FetchTexelc(trb->TexImage, x + i, y, z, rgbaOut + 4 * i);
+   }
 }
 
 static void
 texture_get_values(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
                    const GLint x[], const GLint y[], void *values)
 {
-   /* XXX unfinished */
+   const struct texture_renderbuffer *trb
+      = (const struct texture_renderbuffer *) rb;
+   const GLint z = trb->Zoffset;
+   GLchan *rgbaOut = (GLchan *) values;
+   GLuint i;
+   for (i = 0; i < count; i++) {
+      trb->TexImage->FetchTexelc(trb->TexImage, x[i], y[i], z,
+                                 rgbaOut + 4 * i);
+   }
 }
 
 static void
@@ -109,6 +124,7 @@ texture_put_mono_values(GLcontext *ctx, struct gl_renderbuffer *rb,
 static void
 delete_texture_wrapper(struct gl_renderbuffer *rb)
 {
+   ASSERT(rb->RefCount == 0);
    _mesa_free(rb);
 }
 
@@ -147,9 +163,10 @@ wrap_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att)
 
    trb->Zoffset = att->Zoffset;
 
+   trb->Base.RefCount = 1;
    trb->Base.Width = trb->TexImage->Width;
    trb->Base.Height = trb->TexImage->Height;
-   trb->Base.InternalFormat = trb->TexImage->IntFormat; /* XXX fix? */
+   trb->Base.InternalFormat = trb->TexImage->InternalFormat; /* XXX fix? */
    trb->Base._BaseFormat = trb->TexImage->TexFormat->BaseFormat;
 #if 0
    /* fix/avoid this assertion someday */
@@ -170,6 +187,13 @@ wrap_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att)
    trb->Base.Delete = delete_texture_wrapper;
    trb->Base.AllocStorage = NULL; /* illegal! */
 
+   /* XXX fix these */
+   trb->Base.RedBits = trb->TexImage->TexFormat->RedBits;
+   trb->Base.GreenBits = trb->TexImage->TexFormat->GreenBits;
+   trb->Base.BlueBits = trb->TexImage->TexFormat->BlueBits;
+   trb->Base.AlphaBits = trb->TexImage->TexFormat->AlphaBits;
+   trb->Base.DepthBits = trb->TexImage->TexFormat->DepthBits;
+
    att->Renderbuffer = &(trb->Base);
 }
 
@@ -191,8 +215,8 @@ _mesa_renderbuffer_texture(GLcontext *ctx,
    if (texObj) {
       _mesa_set_texture_attachment(ctx, att, texObj,
                                    texTarget, level, zoffset);
-
-      wrap_texture(ctx, att);
+      if (!att->Renderbuffer)
+         wrap_texture(ctx, att);
    }
    else {
       _mesa_remove_attachment(ctx, att);