src/video/SDL_renderer_gles.c
changeset 3536 0267b8b1595c
parent 3520 83518f8fcd61
child 3547 8b18669c2663
     1.1 --- a/src/video/SDL_renderer_gles.c	Mon Dec 07 10:08:24 2009 +0000
     1.2 +++ b/src/video/SDL_renderer_gles.c	Wed Dec 09 15:56:56 2009 +0000
     1.3 @@ -85,10 +85,12 @@
     1.4                                 SDL_Texture * texture);
     1.5  static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
     1.6                                int numrects, const SDL_Rect * rects);
     1.7 -static int GLES_RenderPoint(SDL_Renderer * renderer, int x, int y);
     1.8 -static int GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
     1.9 -                           int y2);
    1.10 -static int GLES_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
    1.11 +static int GLES_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points,
    1.12 +                             int count);
    1.13 +static int GLES_RenderLines(SDL_Renderer * renderer, const SDL_Point * points,
    1.14 +                            int count);
    1.15 +static int GLES_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
    1.16 +                            int count);
    1.17  static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    1.18                             const SDL_Rect * srcrect,
    1.19                             const SDL_Rect * dstrect);
    1.20 @@ -242,9 +244,9 @@
    1.21      renderer->LockTexture = GLES_LockTexture;
    1.22      renderer->UnlockTexture = GLES_UnlockTexture;
    1.23      renderer->DirtyTexture = GLES_DirtyTexture;
    1.24 -    renderer->RenderPoint = GLES_RenderPoint;
    1.25 -    renderer->RenderLine = GLES_RenderLine;
    1.26 -    renderer->RenderFill = GLES_RenderFill;
    1.27 +    renderer->RenderPoints = GLES_RenderPoints;
    1.28 +    renderer->RenderLines = GLES_RenderLines;
    1.29 +    renderer->RenderRects = GLES_RenderRects;
    1.30      renderer->RenderCopy = GLES_RenderCopy;
    1.31      renderer->RenderPresent = GLES_RenderPresent;
    1.32      renderer->DestroyTexture = GLES_DestroyTexture;
    1.33 @@ -641,7 +643,7 @@
    1.34  }
    1.35  
    1.36  static int
    1.37 -GLES_RenderPoint(SDL_Renderer * renderer, int x, int y)
    1.38 +GLES_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
    1.39  {
    1.40      GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
    1.41  
    1.42 @@ -652,20 +654,16 @@
    1.43                      (GLfloat) renderer->b * inv255f,
    1.44                      (GLfloat) renderer->a * inv255f);
    1.45  
    1.46 -    GLshort vertices[2];
    1.47 -    vertices[0] = x;
    1.48 -    vertices[1] = y;
    1.49 -
    1.50 -    data->glVertexPointer(2, GL_SHORT, 0, vertices);
    1.51 +    data->glVertexPointer(2, GL_INT, 0, points);
    1.52      data->glEnableClientState(GL_VERTEX_ARRAY);
    1.53 -    data->glDrawArrays(GL_POINTS, 0, 1);
    1.54 +    data->glDrawArrays(GL_POINTS, 0, count);
    1.55      data->glDisableClientState(GL_VERTEX_ARRAY);
    1.56  
    1.57      return 0;
    1.58  }
    1.59  
    1.60  static int
    1.61 -GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
    1.62 +GLES_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
    1.63  {
    1.64      GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
    1.65  
    1.66 @@ -676,24 +674,26 @@
    1.67                      (GLfloat) renderer->b * inv255f,
    1.68                      (GLfloat) renderer->a * inv255f);
    1.69  
    1.70 -    GLshort vertices[4];
    1.71 -    vertices[0] = x1;
    1.72 -    vertices[1] = y1;
    1.73 -    vertices[2] = x2;
    1.74 -    vertices[3] = y2;
    1.75 -
    1.76 -    data->glVertexPointer(2, GL_SHORT, 0, vertices);
    1.77 +    data->glVertexPointer(2, GL_INT, 0, points);
    1.78      data->glEnableClientState(GL_VERTEX_ARRAY);
    1.79 -    data->glDrawArrays(GL_LINES, 0, 2);
    1.80 +    if (count > 2 && 
    1.81 +        points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
    1.82 +        /* GL_LINE_LOOP takes care of the final segment */
    1.83 +        --count;
    1.84 +        data->glDrawArrays(GL_LINE_LOOP, 0, count);
    1.85 +    } else {
    1.86 +        data->glDrawArrays(GL_LINE_STRIP, 0, count);
    1.87 +    }
    1.88      data->glDisableClientState(GL_VERTEX_ARRAY);
    1.89  
    1.90      return 0;
    1.91  }
    1.92  
    1.93  static int
    1.94 -GLES_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
    1.95 +GLES_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
    1.96  {
    1.97      GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
    1.98 +    int i;
    1.99  
   1.100      GLES_SetBlendMode(data, renderer->blendMode, 1);
   1.101  
   1.102 @@ -702,24 +702,26 @@
   1.103                      (GLfloat) renderer->b * inv255f,
   1.104                      (GLfloat) renderer->a * inv255f);
   1.105  
   1.106 -    GLshort minx = rect->x;
   1.107 -    GLshort maxx = rect->x + rect->w;
   1.108 -    GLshort miny = rect->y;
   1.109 -    GLshort maxy = rect->y + rect->h;
   1.110 +    data->glEnableClientState(GL_VERTEX_ARRAY);
   1.111 +    for (i = 0; i < count; ++i) {
   1.112 +        const SDL_Rect *rect = rects[i];
   1.113 +        GLshort minx = rect->x;
   1.114 +        GLshort maxx = rect->x + rect->w;
   1.115 +        GLshort miny = rect->y;
   1.116 +        GLshort maxy = rect->y + rect->h;
   1.117 +        GLshort vertices[8];
   1.118 +        vertices[0] = minx;
   1.119 +        vertices[1] = miny;
   1.120 +        vertices[2] = maxx;
   1.121 +        vertices[3] = miny;
   1.122 +        vertices[4] = minx;
   1.123 +        vertices[5] = maxy;
   1.124 +        vertices[6] = maxx;
   1.125 +        vertices[7] = maxy;
   1.126  
   1.127 -    GLshort vertices[8];
   1.128 -    vertices[0] = minx;
   1.129 -    vertices[1] = miny;
   1.130 -    vertices[2] = maxx;
   1.131 -    vertices[3] = miny;
   1.132 -    vertices[4] = minx;
   1.133 -    vertices[5] = maxy;
   1.134 -    vertices[6] = maxx;
   1.135 -    vertices[7] = maxy;
   1.136 -
   1.137 -    data->glVertexPointer(2, GL_SHORT, 0, vertices);
   1.138 -    data->glEnableClientState(GL_VERTEX_ARRAY);
   1.139 -    data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   1.140 +        data->glVertexPointer(2, GL_SHORT, 0, vertices);
   1.141 +        data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   1.142 +    }
   1.143      data->glDisableClientState(GL_VERTEX_ARRAY);
   1.144  
   1.145      return 0;