[OpenGL] Corruption avec glTexSubImage2D ?

Corruption avec glTexSubImage2D ? [OpenGL] - C - Programmation

Marsh Posté le 15-08-2006 à 09:14:41    

Bonjour à tous :hello:  
 
j'ai un blème avec le morceau de code ci-dessous. J'explique vite fait, l'intérêt n'est pas de comprendre le code mais de comprendre le problème : basiquement je propose deux méthodes pour dessiner des surfaces à l'écran, la plus simple charge la surface entière quelle que soit la portion qui nous intéresse ( SourceRectangle ) ( par ex. si on veut seulement afficher un rectangle 256x256 d'une surface 1024x1024 on chargera quand même entièrement la surface 1024x1024 ) puis dessine un seul quad et la seconde plus complexe divise la surface en plusieurs morceaux et colle plusieurs quads pour reformer le quad qu'on veut dessiner. Le rendu en utilisant la première méthode est nickel mais avec la seconde j'ai un petit problème de corruption plus ou moins aléatoire ( et ça scintille ) lorsque je dessine plusieurs rectangles de la même surface, ils se pompent les uns sur les autres comme on le voit bien sur ces captures :
 
http://moigeeknevro.com/wine/capture16.png
http://moigeeknevro.com/wine/capture17.png
 
Bon là encore c'est pas très embêtant, mais d'en d'autres cas c'est complètement illisible. La seconde méthode utilise en fait une "texture tampon" qu'on reremplit avec glTexSubImage2D à chaque fois qu'on dessine un nouveau morceau /ou une nouvelle portion ( suffit de jeter un coup d'oeil au code pour comprendre ). Ma question est : je suis assez nouveau en 3D, est-ce que glTexSubImage2D a besoin qu'on lui laisse le tampon ( ici bltBuffer ) pendant un certain temps ? J'ai essayé de placer des glFinish un peu partout pour voir mais ça n'a pas aidé. Quelqu'un qui connaît bien le fonctionnement de glTexSubImage2D et des drivers/matos ( j'ai le problème avec r200 dri et fglrx avec une 9250 sous Linux ) peut me dire ce qui ne va pas ?
 
edit : bon tout compte fait spa très clair tout ça je vais essayer de reproduire le problème avec un exemple plus simple :o  
 
edit 2 : ah ben en réalité la première méthode marche correctement avec fglrx [:croquignol] , je me suis démené pour rien

Code :
  1. if(splitDrawing) {
  2.     /* The trick is : we split the surface into 128x128,256x256,whatever
  3.         * squares then we draws multiple quads. This helps to upload and bind only
  4.         * needed portions of (especially full-dirty and/or full-screen) surfaces
  5.         * and also will someday take advantage of asynchronous texture uploads
  6.         * ( upload/draw the quad while we convert another portion ).
  7.         * NOTE: the quad size doesn't depend on the rectangle size because this will
  8.         * complexify the code and eat more memory without notable performance boost. */
  9.     /* TODO: There should be a reasonable balance between dirtyfying rate,
  10.         * surface/rect ratio and the drawing method.
  11.         * ( e.g when a surface is never dirtyfied and the rect is not too
  12.         * smaller than the surface size basic drawings should be at least as fast )
  13.         * For instance remember the blts count ( !! max one per frame ) performed
  14.         * since the last dirtyfying */
  15.     d3dfmt_get_conv(Src, (Flags & DDBLT_KEYSRC)?TRUE:FALSE, TRUE, &format, &internal, &type, &convert, &bpp);
  16.     /* Allocate the buffer */
  17.     if(Src->bltBuffer == NULL) /*FIXME: check bpp*/{
  18.         Src->bltBuffer = HeapAlloc(GetProcessHeap(), 0, QUAD_SIZE*QUAD_SIZE*bpp);
  19.         glGenTextures(1, &Src->bltBufferTextureName);
  20.         glBindTexture(GL_TEXTURE_2D, Src->bltBufferTextureName);
  21.         checkGLcall("glBindTexture" );
  22.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  23.         checkGLcall("glTexParameteri" );
  24.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  25.         checkGLcall("glTexParameteri" );
  26.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  27.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  28.         checkGLcall("glTexParameteri" );
  29.         glTexImage2D(GL_TEXTURE_2D, 0, internal,
  30.             QUAD_SIZE, QUAD_SIZE, 0,
  31.             format, type, NULL);
  32.         checkGLcall("glTexImage2D" );
  33.     }
  34.     /* FIXME: redundant.. */
  35.     glBindTexture(GL_TEXTURE_2D, Src->bltBufferTextureName);
  36.     checkGLcall("glBindTexture" );
  37. } else {
  38.     /* Now load the surface */
  39.     IWineD3DSurface_PreLoad((IWineD3DSurface *) Src);
  40.     /* Bind the texture */
  41.     glBindTexture(GL_TEXTURE_2D, Src->glDescription.textureName);
  42.     checkGLcall("glBindTexture" );
  43.     /* No filtering for blts */
  44.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  45.     checkGLcall("glTexParameteri" );
  46.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  47.     checkGLcall("glTexParameteri" );
  48.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  49.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  50.     checkGLcall("glTexParameteri" );
  51. }
  52. glColor3d(1.0f, 1.0f, 1.0f);
  53. if(splitDrawing) {
  54.     int x,y,i;
  55.     UINT pitch = IWineD3DSurface_GetPitch(SrcSurface);
  56.     int width, height;
  57.     float x_stretch, y_stretch;
  58.     width = SourceRectangle.right - SourceRectangle.left;
  59.     height = SourceRectangle.bottom - SourceRectangle.top;
  60.     x_stretch = (float) (rect.x2 - rect.x1) / (float) width;
  61.     y_stretch = (float) (rect.y2 - rect.y1) / (float) height;
  62.     glTexCoord[0] = 0.0;
  63.     glTexCoord[2] = 0.0;
  64.     glPixelStorei(GL_UNPACK_ROW_LENGTH, QUAD_SIZE);
  65.     checkGLcall("glPixelStorei" );
  66.     for (y = 0; y < height; y += QUAD_SIZE) {
  67.         UINT flush_height;
  68.         if(y + QUAD_SIZE > height) {
  69.             flush_height = height - y;
  70.             glTexCoord[3] = (float) flush_height / (float) QUAD_SIZE;
  71.         } else {
  72.             flush_height = QUAD_SIZE;
  73.             glTexCoord[3] = 1.0;
  74.         }
  75.         for (x = 0; x < width; x += QUAD_SIZE) {
  76.             UINT flush_width;
  77.             BYTE *srcRow = Src->resource.allocatedMemory + ((SourceRectangle.left+x)*bpp) + ((SourceRectangle.top+y)*pitch);
  78.             if(x + QUAD_SIZE > width) {
  79.                 flush_width = width - x;
  80.                 glTexCoord[1] = (float) flush_width / (float) QUAD_SIZE;
  81.             } else {
  82.                 flush_width = QUAD_SIZE;
  83.                 glTexCoord[1] = 1.0;
  84.             }
  85.             for (i = 0; i < flush_height; i++, srcRow += pitch) /* row by row */
  86.                 d3dfmt_convert_surface(srcRow, Src->bltBuffer + (i*QUAD_SIZE*bpp),
  87.                     flush_width, convert, Src);
  88.             glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
  89.                 flush_width, flush_height,
  90.                 format, type, Src->bltBuffer);
  91.             checkGLcall("glTexSubImage2D" );
  92.             glBegin(GL_QUADS);
  93.             glTexCoord2f(glTexCoord[0], glTexCoord[2]);
  94.             glVertex3f(rect.x1 + (x * x_stretch),
  95.                     rect.y1 + (y * y_stretch),
  96.                     0.0);
  97.             glTexCoord2f(glTexCoord[0], glTexCoord[3]);
  98.             glVertex3f(rect.x1 + (x * x_stretch),
  99.                     rect.y1 + ((y + flush_height) * y_stretch),
  100.                     0.0);
  101.             glTexCoord2f(glTexCoord[1], glTexCoord[3]);
  102.             glVertex3f(rect.x1 + ((x + flush_width) * x_stretch),
  103.                     rect.y1 + ((y + flush_height) * y_stretch),
  104.                     0.0);
  105.             glTexCoord2f(glTexCoord[1], glTexCoord[2]);
  106.             glVertex3f(rect.x1 + ((x + flush_width) * x_stretch),
  107.                     rect.y1 + (y * y_stretch),
  108.                     0.0);
  109.             glEnd();
  110.             checkGLcall("glEnd" );
  111.         }
  112.     }
  113.     glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
  114.     checkGLcall("glPixelStorei" );
  115. } else {
  116.     /* Draw a textured quad */
  117.     glBegin(GL_QUADS);
  118.     glTexCoord2f(glTexCoord[0], glTexCoord[2]);
  119.     glVertex3f(rect.x1,
  120.             rect.y1,
  121.             0.0);
  122.     glTexCoord2f(glTexCoord[0], glTexCoord[3]);
  123.     glVertex3f(rect.x1, rect.y2, 0.0);
  124.     glTexCoord2f(glTexCoord[1], glTexCoord[3]);
  125.     glVertex3f(rect.x2,
  126.             rect.y2,
  127.             0.0);
  128.     glTexCoord2f(glTexCoord[1], glTexCoord[2]);
  129.     glVertex3f(rect.x2,
  130.             rect.y1,
  131.             0.0);
  132.     glEnd();
  133.     checkGLcall("glEnd" );
  134. }


Message édité par SuperDindon le 30-08-2006 à 07:00:33
Reply

Marsh Posté le 15-08-2006 à 09:14:41   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed