Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_gles.c @ 3536:0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
SDL_DrawPoints()
SDL_BlendPoints()
SDL_BlendLines()
SDL_DrawLines()
SDL_FillRects()
SDL_BlendRects()
SDL_RenderPoints()
SDL_RenderLines()
SDL_RenderRects()
Renamed SDL_RenderFill() to SDL_RenderRect()
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 09 Dec 2009 15:56:56 +0000 |
parents | 83518f8fcd61 |
children | 8b18669c2663 |
comparison
equal
deleted
inserted
replaced
3535:b403f790df65 | 3536:0267b8b1595c |
---|---|
83 void **pixels, int *pitch); | 83 void **pixels, int *pitch); |
84 static void GLES_UnlockTexture(SDL_Renderer * renderer, | 84 static void GLES_UnlockTexture(SDL_Renderer * renderer, |
85 SDL_Texture * texture); | 85 SDL_Texture * texture); |
86 static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 86 static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
87 int numrects, const SDL_Rect * rects); | 87 int numrects, const SDL_Rect * rects); |
88 static int GLES_RenderPoint(SDL_Renderer * renderer, int x, int y); | 88 static int GLES_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, |
89 static int GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, | 89 int count); |
90 int y2); | 90 static int GLES_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, |
91 static int GLES_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); | 91 int count); |
92 static int GLES_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, | |
93 int count); | |
92 static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 94 static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
93 const SDL_Rect * srcrect, | 95 const SDL_Rect * srcrect, |
94 const SDL_Rect * dstrect); | 96 const SDL_Rect * dstrect); |
95 static void GLES_RenderPresent(SDL_Renderer * renderer); | 97 static void GLES_RenderPresent(SDL_Renderer * renderer); |
96 static void GLES_DestroyTexture(SDL_Renderer * renderer, | 98 static void GLES_DestroyTexture(SDL_Renderer * renderer, |
240 renderer->SetTextureScaleMode = GLES_SetTextureScaleMode; | 242 renderer->SetTextureScaleMode = GLES_SetTextureScaleMode; |
241 renderer->UpdateTexture = GLES_UpdateTexture; | 243 renderer->UpdateTexture = GLES_UpdateTexture; |
242 renderer->LockTexture = GLES_LockTexture; | 244 renderer->LockTexture = GLES_LockTexture; |
243 renderer->UnlockTexture = GLES_UnlockTexture; | 245 renderer->UnlockTexture = GLES_UnlockTexture; |
244 renderer->DirtyTexture = GLES_DirtyTexture; | 246 renderer->DirtyTexture = GLES_DirtyTexture; |
245 renderer->RenderPoint = GLES_RenderPoint; | 247 renderer->RenderPoints = GLES_RenderPoints; |
246 renderer->RenderLine = GLES_RenderLine; | 248 renderer->RenderLines = GLES_RenderLines; |
247 renderer->RenderFill = GLES_RenderFill; | 249 renderer->RenderRects = GLES_RenderRects; |
248 renderer->RenderCopy = GLES_RenderCopy; | 250 renderer->RenderCopy = GLES_RenderCopy; |
249 renderer->RenderPresent = GLES_RenderPresent; | 251 renderer->RenderPresent = GLES_RenderPresent; |
250 renderer->DestroyTexture = GLES_DestroyTexture; | 252 renderer->DestroyTexture = GLES_DestroyTexture; |
251 renderer->DestroyRenderer = GLES_DestroyRenderer; | 253 renderer->DestroyRenderer = GLES_DestroyRenderer; |
252 renderer->info = GL_ES_RenderDriver.info; | 254 renderer->info = GL_ES_RenderDriver.info; |
639 data->blendMode = blendMode; | 641 data->blendMode = blendMode; |
640 } | 642 } |
641 } | 643 } |
642 | 644 |
643 static int | 645 static int |
644 GLES_RenderPoint(SDL_Renderer * renderer, int x, int y) | 646 GLES_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) |
645 { | 647 { |
646 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | 648 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
647 | 649 |
648 GLES_SetBlendMode(data, renderer->blendMode, 1); | 650 GLES_SetBlendMode(data, renderer->blendMode, 1); |
649 | 651 |
650 data->glColor4f((GLfloat) renderer->r * inv255f, | 652 data->glColor4f((GLfloat) renderer->r * inv255f, |
651 (GLfloat) renderer->g * inv255f, | 653 (GLfloat) renderer->g * inv255f, |
652 (GLfloat) renderer->b * inv255f, | 654 (GLfloat) renderer->b * inv255f, |
653 (GLfloat) renderer->a * inv255f); | 655 (GLfloat) renderer->a * inv255f); |
654 | 656 |
655 GLshort vertices[2]; | 657 data->glVertexPointer(2, GL_INT, 0, points); |
656 vertices[0] = x; | |
657 vertices[1] = y; | |
658 | |
659 data->glVertexPointer(2, GL_SHORT, 0, vertices); | |
660 data->glEnableClientState(GL_VERTEX_ARRAY); | 658 data->glEnableClientState(GL_VERTEX_ARRAY); |
661 data->glDrawArrays(GL_POINTS, 0, 1); | 659 data->glDrawArrays(GL_POINTS, 0, count); |
662 data->glDisableClientState(GL_VERTEX_ARRAY); | 660 data->glDisableClientState(GL_VERTEX_ARRAY); |
663 | 661 |
664 return 0; | 662 return 0; |
665 } | 663 } |
666 | 664 |
667 static int | 665 static int |
668 GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) | 666 GLES_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) |
669 { | 667 { |
670 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | 668 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
671 | 669 |
672 GLES_SetBlendMode(data, renderer->blendMode, 1); | 670 GLES_SetBlendMode(data, renderer->blendMode, 1); |
673 | 671 |
674 data->glColor4f((GLfloat) renderer->r * inv255f, | 672 data->glColor4f((GLfloat) renderer->r * inv255f, |
675 (GLfloat) renderer->g * inv255f, | 673 (GLfloat) renderer->g * inv255f, |
676 (GLfloat) renderer->b * inv255f, | 674 (GLfloat) renderer->b * inv255f, |
677 (GLfloat) renderer->a * inv255f); | 675 (GLfloat) renderer->a * inv255f); |
678 | 676 |
679 GLshort vertices[4]; | 677 data->glVertexPointer(2, GL_INT, 0, points); |
680 vertices[0] = x1; | |
681 vertices[1] = y1; | |
682 vertices[2] = x2; | |
683 vertices[3] = y2; | |
684 | |
685 data->glVertexPointer(2, GL_SHORT, 0, vertices); | |
686 data->glEnableClientState(GL_VERTEX_ARRAY); | 678 data->glEnableClientState(GL_VERTEX_ARRAY); |
687 data->glDrawArrays(GL_LINES, 0, 2); | 679 if (count > 2 && |
680 points[0].x == points[count-1].x && points[0].y == points[count-1].y) { | |
681 /* GL_LINE_LOOP takes care of the final segment */ | |
682 --count; | |
683 data->glDrawArrays(GL_LINE_LOOP, 0, count); | |
684 } else { | |
685 data->glDrawArrays(GL_LINE_STRIP, 0, count); | |
686 } | |
688 data->glDisableClientState(GL_VERTEX_ARRAY); | 687 data->glDisableClientState(GL_VERTEX_ARRAY); |
689 | 688 |
690 return 0; | 689 return 0; |
691 } | 690 } |
692 | 691 |
693 static int | 692 static int |
694 GLES_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) | 693 GLES_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) |
695 { | 694 { |
696 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | 695 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
696 int i; | |
697 | 697 |
698 GLES_SetBlendMode(data, renderer->blendMode, 1); | 698 GLES_SetBlendMode(data, renderer->blendMode, 1); |
699 | 699 |
700 data->glColor4f((GLfloat) renderer->r * inv255f, | 700 data->glColor4f((GLfloat) renderer->r * inv255f, |
701 (GLfloat) renderer->g * inv255f, | 701 (GLfloat) renderer->g * inv255f, |
702 (GLfloat) renderer->b * inv255f, | 702 (GLfloat) renderer->b * inv255f, |
703 (GLfloat) renderer->a * inv255f); | 703 (GLfloat) renderer->a * inv255f); |
704 | 704 |
705 GLshort minx = rect->x; | |
706 GLshort maxx = rect->x + rect->w; | |
707 GLshort miny = rect->y; | |
708 GLshort maxy = rect->y + rect->h; | |
709 | |
710 GLshort vertices[8]; | |
711 vertices[0] = minx; | |
712 vertices[1] = miny; | |
713 vertices[2] = maxx; | |
714 vertices[3] = miny; | |
715 vertices[4] = minx; | |
716 vertices[5] = maxy; | |
717 vertices[6] = maxx; | |
718 vertices[7] = maxy; | |
719 | |
720 data->glVertexPointer(2, GL_SHORT, 0, vertices); | |
721 data->glEnableClientState(GL_VERTEX_ARRAY); | 705 data->glEnableClientState(GL_VERTEX_ARRAY); |
722 data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 706 for (i = 0; i < count; ++i) { |
707 const SDL_Rect *rect = rects[i]; | |
708 GLshort minx = rect->x; | |
709 GLshort maxx = rect->x + rect->w; | |
710 GLshort miny = rect->y; | |
711 GLshort maxy = rect->y + rect->h; | |
712 GLshort vertices[8]; | |
713 vertices[0] = minx; | |
714 vertices[1] = miny; | |
715 vertices[2] = maxx; | |
716 vertices[3] = miny; | |
717 vertices[4] = minx; | |
718 vertices[5] = maxy; | |
719 vertices[6] = maxx; | |
720 vertices[7] = maxy; | |
721 | |
722 data->glVertexPointer(2, GL_SHORT, 0, vertices); | |
723 data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | |
724 } | |
723 data->glDisableClientState(GL_VERTEX_ARRAY); | 725 data->glDisableClientState(GL_VERTEX_ARRAY); |
724 | 726 |
725 return 0; | 727 return 0; |
726 } | 728 } |
727 | 729 |