Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_gles.c @ 5143:e743b9c3f6d6
Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 31 Jan 2011 23:23:57 -0800 |
parents | da10636e5eca |
children | 31e7f523ab3d |
comparison
equal
deleted
inserted
replaced
5142:57851a238c8f | 5143:e743b9c3f6d6 |
---|---|
69 int firstcolor, int ncolors); | 69 int firstcolor, int ncolors); |
70 static int GLES_SetTextureColorMod(SDL_Renderer * renderer, | 70 static int GLES_SetTextureColorMod(SDL_Renderer * renderer, |
71 SDL_Texture * texture); | 71 SDL_Texture * texture); |
72 static int GLES_SetTextureAlphaMod(SDL_Renderer * renderer, | 72 static int GLES_SetTextureAlphaMod(SDL_Renderer * renderer, |
73 SDL_Texture * texture); | 73 SDL_Texture * texture); |
74 static int GLES_SetTextureBlendMode(SDL_Renderer * renderer, | |
75 SDL_Texture * texture); | |
76 static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 74 static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
77 const SDL_Rect * rect, const void *pixels, | 75 const SDL_Rect * rect, const void *pixels, |
78 int pitch); | 76 int pitch); |
79 static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 77 static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
80 const SDL_Rect * rect, int markDirty, | 78 const SDL_Rect * rect, int markDirty, |
106 "opengl_es", | 104 "opengl_es", |
107 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD | | 105 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD | |
108 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), | 106 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), |
109 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | | 107 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | |
110 SDL_TEXTUREMODULATE_ALPHA), | 108 SDL_TEXTUREMODULATE_ALPHA), |
111 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | | |
112 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), | |
113 { | 109 { |
114 /* OpenGL ES 1.x supported formats list */ | 110 /* OpenGL ES 1.x supported formats list */ |
115 SDL_PIXELFORMAT_RGBA4444, | 111 SDL_PIXELFORMAT_RGBA4444, |
116 SDL_PIXELFORMAT_RGBA5551, | 112 SDL_PIXELFORMAT_RGBA5551, |
117 SDL_PIXELFORMAT_RGB565, | 113 SDL_PIXELFORMAT_RGB565, |
235 renderer->QueryTexturePixels = GLES_QueryTexturePixels; | 231 renderer->QueryTexturePixels = GLES_QueryTexturePixels; |
236 renderer->SetTexturePalette = GLES_SetTexturePalette; | 232 renderer->SetTexturePalette = GLES_SetTexturePalette; |
237 renderer->GetTexturePalette = GLES_GetTexturePalette; | 233 renderer->GetTexturePalette = GLES_GetTexturePalette; |
238 renderer->SetTextureColorMod = GLES_SetTextureColorMod; | 234 renderer->SetTextureColorMod = GLES_SetTextureColorMod; |
239 renderer->SetTextureAlphaMod = GLES_SetTextureAlphaMod; | 235 renderer->SetTextureAlphaMod = GLES_SetTextureAlphaMod; |
240 renderer->SetTextureBlendMode = GLES_SetTextureBlendMode; | |
241 renderer->UpdateTexture = GLES_UpdateTexture; | 236 renderer->UpdateTexture = GLES_UpdateTexture; |
242 renderer->LockTexture = GLES_LockTexture; | 237 renderer->LockTexture = GLES_LockTexture; |
243 renderer->UnlockTexture = GLES_UnlockTexture; | 238 renderer->UnlockTexture = GLES_UnlockTexture; |
244 renderer->DirtyTexture = GLES_DirtyTexture; | 239 renderer->DirtyTexture = GLES_DirtyTexture; |
245 renderer->RenderDrawPoints = GLES_RenderDrawPoints; | 240 renderer->RenderDrawPoints = GLES_RenderDrawPoints; |
512 { | 507 { |
513 return 0; | 508 return 0; |
514 } | 509 } |
515 | 510 |
516 static int | 511 static int |
517 GLES_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
518 { | |
519 switch (texture->blendMode) { | |
520 case SDL_BLENDMODE_NONE: | |
521 case SDL_BLENDMODE_MASK: | |
522 case SDL_BLENDMODE_BLEND: | |
523 case SDL_BLENDMODE_ADD: | |
524 case SDL_BLENDMODE_MOD: | |
525 return 0; | |
526 default: | |
527 SDL_Unsupported(); | |
528 texture->blendMode = SDL_BLENDMODE_NONE; | |
529 return -1; | |
530 } | |
531 } | |
532 | |
533 static int | |
534 GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 512 GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
535 const SDL_Rect * rect, const void *pixels, int pitch) | 513 const SDL_Rect * rect, const void *pixels, int pitch) |
536 { | 514 { |
537 GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; | 515 GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; |
538 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; | 516 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; |
610 SDL_AddDirtyRect(&data->dirty, &rects[i]); | 588 SDL_AddDirtyRect(&data->dirty, &rects[i]); |
611 } | 589 } |
612 } | 590 } |
613 | 591 |
614 static void | 592 static void |
615 GLES_SetBlendMode(GLES_RenderData * data, int blendMode, int isprimitive) | 593 GLES_SetBlendMode(GLES_RenderData * data, int blendMode) |
616 { | 594 { |
617 if (blendMode != data->blendMode) { | 595 if (blendMode != data->blendMode) { |
618 switch (blendMode) { | 596 switch (blendMode) { |
619 case SDL_BLENDMODE_NONE: | 597 case SDL_BLENDMODE_NONE: |
620 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 598 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
621 data->glDisable(GL_BLEND); | 599 data->glDisable(GL_BLEND); |
622 break; | 600 break; |
623 case SDL_BLENDMODE_MASK: | |
624 if (isprimitive) { | |
625 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | |
626 data->glDisable(GL_BLEND); | |
627 /* The same as SDL_BLENDMODE_NONE */ | |
628 blendMode = SDL_BLENDMODE_NONE; | |
629 break; | |
630 } | |
631 /* fall through */ | |
632 case SDL_BLENDMODE_BLEND: | 601 case SDL_BLENDMODE_BLEND: |
633 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | 602 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
634 data->glEnable(GL_BLEND); | 603 data->glEnable(GL_BLEND); |
635 data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 604 data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
636 break; | 605 break; |
637 case SDL_BLENDMODE_ADD: | 606 case SDL_BLENDMODE_ADD: |
638 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | 607 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
639 data->glEnable(GL_BLEND); | 608 data->glEnable(GL_BLEND); |
640 data->glBlendFunc(GL_SRC_ALPHA, GL_ONE); | 609 data->glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
641 break; | 610 break; |
642 case SDL_BLENDMODE_MOD: | |
643 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | |
644 data->glEnable(GL_BLEND); | |
645 data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); | |
646 break; | |
647 } | 611 } |
648 data->blendMode = blendMode; | 612 data->blendMode = blendMode; |
649 } | 613 } |
650 } | 614 } |
651 | 615 |
655 { | 619 { |
656 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | 620 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
657 int i; | 621 int i; |
658 GLshort *vertices; | 622 GLshort *vertices; |
659 | 623 |
660 GLES_SetBlendMode(data, renderer->blendMode, 1); | 624 GLES_SetBlendMode(data, renderer->blendMode); |
661 | 625 |
662 data->glColor4f((GLfloat) renderer->r * inv255f, | 626 data->glColor4f((GLfloat) renderer->r * inv255f, |
663 (GLfloat) renderer->g * inv255f, | 627 (GLfloat) renderer->g * inv255f, |
664 (GLfloat) renderer->b * inv255f, | 628 (GLfloat) renderer->b * inv255f, |
665 (GLfloat) renderer->a * inv255f); | 629 (GLfloat) renderer->a * inv255f); |
682 { | 646 { |
683 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | 647 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
684 int i; | 648 int i; |
685 GLshort *vertices; | 649 GLshort *vertices; |
686 | 650 |
687 GLES_SetBlendMode(data, renderer->blendMode, 1); | 651 GLES_SetBlendMode(data, renderer->blendMode); |
688 | 652 |
689 data->glColor4f((GLfloat) renderer->r * inv255f, | 653 data->glColor4f((GLfloat) renderer->r * inv255f, |
690 (GLfloat) renderer->g * inv255f, | 654 (GLfloat) renderer->g * inv255f, |
691 (GLfloat) renderer->b * inv255f, | 655 (GLfloat) renderer->b * inv255f, |
692 (GLfloat) renderer->a * inv255f); | 656 (GLfloat) renderer->a * inv255f); |
715 int count) | 679 int count) |
716 { | 680 { |
717 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | 681 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
718 int i; | 682 int i; |
719 | 683 |
720 GLES_SetBlendMode(data, renderer->blendMode, 1); | 684 GLES_SetBlendMode(data, renderer->blendMode); |
721 | 685 |
722 data->glColor4f((GLfloat) renderer->r * inv255f, | 686 data->glColor4f((GLfloat) renderer->r * inv255f, |
723 (GLfloat) renderer->g * inv255f, | 687 (GLfloat) renderer->g * inv255f, |
724 (GLfloat) renderer->b * inv255f, | 688 (GLfloat) renderer->b * inv255f, |
725 (GLfloat) renderer->a * inv255f); | 689 (GLfloat) renderer->a * inv255f); |
752 int count) | 716 int count) |
753 { | 717 { |
754 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | 718 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
755 int i; | 719 int i; |
756 | 720 |
757 GLES_SetBlendMode(data, renderer->blendMode, 1); | 721 GLES_SetBlendMode(data, renderer->blendMode); |
758 | 722 |
759 data->glColor4f((GLfloat) renderer->r * inv255f, | 723 data->glColor4f((GLfloat) renderer->r * inv255f, |
760 (GLfloat) renderer->g * inv255f, | 724 (GLfloat) renderer->g * inv255f, |
761 (GLfloat) renderer->b * inv255f, | 725 (GLfloat) renderer->b * inv255f, |
762 (GLfloat) renderer->a * inv255f); | 726 (GLfloat) renderer->a * inv255f); |
851 (GLfloat) texture->a * inv255f); | 815 (GLfloat) texture->a * inv255f); |
852 } else { | 816 } else { |
853 data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | 817 data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f); |
854 } | 818 } |
855 | 819 |
856 GLES_SetBlendMode(data, texture->blendMode, 0); | 820 GLES_SetBlendMode(data, texture->blendMode); |
857 | 821 |
858 if (data->GL_OES_draw_texture_supported && data->useDrawTexture) { | 822 if (data->GL_OES_draw_texture_supported && data->useDrawTexture) { |
859 /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */ | 823 /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */ |
860 SDL_Window *window = renderer->window; | 824 SDL_Window *window = renderer->window; |
861 GLint cropRect[4]; | 825 GLint cropRect[4]; |