Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_gles.c @ 2936:066384910f50
iPhone build compiles again (drawing routines need to be implemented)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 31 Dec 2008 07:56:56 +0000 |
parents | 9dde605c7540 |
children | 017d4334accf |
comparison
equal
deleted
inserted
replaced
2935:59e3e0aaa725 | 2936:066384910f50 |
---|---|
64 void **pixels, int *pitch); | 64 void **pixels, int *pitch); |
65 static void GLES_UnlockTexture(SDL_Renderer * renderer, | 65 static void GLES_UnlockTexture(SDL_Renderer * renderer, |
66 SDL_Texture * texture); | 66 SDL_Texture * texture); |
67 static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 67 static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
68 int numrects, const SDL_Rect * rects); | 68 int numrects, const SDL_Rect * rects); |
69 static int GLES_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, | 69 static int GLES_RenderPoint(SDL_Renderer * renderer, int x, int y); |
70 Uint8 a, const SDL_Rect * rect); | 70 static int GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, |
71 int y2); | |
72 static int GLES_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); | |
71 static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 73 static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
72 const SDL_Rect * srcrect, | 74 const SDL_Rect * srcrect, |
73 const SDL_Rect * dstrect); | 75 const SDL_Rect * dstrect); |
74 static void GLES_RenderPresent(SDL_Renderer * renderer); | 76 static void GLES_RenderPresent(SDL_Renderer * renderer); |
75 static void GLES_DestroyTexture(SDL_Renderer * renderer, | 77 static void GLES_DestroyTexture(SDL_Renderer * renderer, |
224 renderer->SetTextureScaleMode = GLES_SetTextureScaleMode; | 226 renderer->SetTextureScaleMode = GLES_SetTextureScaleMode; |
225 renderer->UpdateTexture = GLES_UpdateTexture; | 227 renderer->UpdateTexture = GLES_UpdateTexture; |
226 renderer->LockTexture = GLES_LockTexture; | 228 renderer->LockTexture = GLES_LockTexture; |
227 renderer->UnlockTexture = GLES_UnlockTexture; | 229 renderer->UnlockTexture = GLES_UnlockTexture; |
228 renderer->DirtyTexture = GLES_DirtyTexture; | 230 renderer->DirtyTexture = GLES_DirtyTexture; |
231 renderer->RenderPoint = GLES_RenderPoint; | |
232 renderer->RenderLine = GLES_RenderLine; | |
229 renderer->RenderFill = GLES_RenderFill; | 233 renderer->RenderFill = GLES_RenderFill; |
230 renderer->RenderCopy = GLES_RenderCopy; | 234 renderer->RenderCopy = GLES_RenderCopy; |
231 renderer->RenderPresent = GLES_RenderPresent; | 235 renderer->RenderPresent = GLES_RenderPresent; |
232 renderer->DestroyTexture = GLES_DestroyTexture; | 236 renderer->DestroyTexture = GLES_DestroyTexture; |
233 renderer->DestroyRenderer = GLES_DestroyRenderer; | 237 renderer->DestroyRenderer = GLES_DestroyRenderer; |
584 for (i = 0; i < numrects; ++i) { | 588 for (i = 0; i < numrects; ++i) { |
585 SDL_AddDirtyRect(&data->dirty, &rects[i]); | 589 SDL_AddDirtyRect(&data->dirty, &rects[i]); |
586 } | 590 } |
587 } | 591 } |
588 | 592 |
589 static int | 593 static void |
590 GLES_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a, | 594 GLES_SetBlendMode(GLES_RenderData * data, int blendMode) |
591 const SDL_Rect * rect) | 595 { |
592 { | 596 if (blendMode != data->blendMode) { |
593 | 597 switch (blendMode) { |
594 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | |
595 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | |
596 | |
597 /* set proper drawing color */ | |
598 GLfloat oldClearColor[4]; | |
599 | |
600 data->glGetFloatv(GL_COLOR_CLEAR_VALUE, oldClearColor); | |
601 | |
602 data->glClearColor((GLclampf) r * inv255f, (GLclampf) g * inv255f, | |
603 (GLclampf) b * inv255f, (GLclampf) a * inv255f); | |
604 | |
605 data->glScissor(rect->x, window->h - rect->y - rect->h, rect->w, rect->h); | |
606 data->glEnable(GL_SCISSOR_TEST); | |
607 data->glClear(GL_COLOR_BUFFER_BIT); | |
608 data->glDisable(GL_SCISSOR_TEST); | |
609 | |
610 /* reset clear color */ | |
611 data->glClearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], | |
612 oldClearColor[2]); | |
613 | |
614 return 0; | |
615 } | |
616 | |
617 static int | |
618 GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | |
619 const SDL_Rect * srcrect, const SDL_Rect * dstrect) | |
620 { | |
621 | |
622 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | |
623 GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; | |
624 int minx, miny, maxx, maxy; | |
625 GLfloat minu, maxu, minv, maxv; | |
626 int i; | |
627 void *temp_buffer; /* used for reformatting dirty rect pixels */ | |
628 void *temp_ptr; | |
629 | |
630 if (texturedata->dirty.list) { | |
631 SDL_DirtyRect *dirty; | |
632 void *pixels; | |
633 int bpp = SDL_BYTESPERPIXEL(texture->format); | |
634 int pitch = texturedata->pitch; | |
635 | |
636 SetupTextureUpdate(data, texture, pitch); | |
637 | |
638 data->glBindTexture(texturedata->type, texturedata->texture); | |
639 for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) { | |
640 SDL_Rect *rect = &dirty->rect; | |
641 pixels = | |
642 (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch + | |
643 rect->x * bpp); | |
644 /* There is no GL_UNPACK_ROW_LENGTH in OpenGLES | |
645 we must do this reformatting ourselves(!) | |
646 | |
647 maybe it'd be a good idea to keep a temp buffer around | |
648 for this purpose rather than allocating it each time | |
649 */ | |
650 temp_buffer = SDL_malloc(rect->w * rect->h * bpp); | |
651 temp_ptr = temp_buffer; | |
652 for (i = 0; i < rect->h; i++) { | |
653 SDL_memcpy(temp_ptr, pixels, rect->w * bpp); | |
654 temp_ptr += rect->w * bpp; | |
655 pixels += pitch; | |
656 } | |
657 | |
658 data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y, | |
659 rect->w, rect->h, texturedata->format, | |
660 texturedata->formattype, temp_buffer); | |
661 | |
662 SDL_free(temp_buffer); | |
663 | |
664 } | |
665 SDL_ClearDirtyRects(&texturedata->dirty); | |
666 } | |
667 | |
668 data->glBindTexture(texturedata->type, texturedata->texture); | |
669 data->glEnable(GL_TEXTURE_2D); | |
670 | |
671 if (texture->modMode) { | |
672 data->glColor4f((GLfloat) texture->r * inv255f, | |
673 (GLfloat) texture->g * inv255f, | |
674 (GLfloat) texture->b * inv255f, | |
675 (GLfloat) texture->a * inv255f); | |
676 } else { | |
677 data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | |
678 } | |
679 | |
680 if (texture->blendMode != data->blendMode) { | |
681 switch (texture->blendMode) { | |
682 case SDL_BLENDMODE_NONE: | 598 case SDL_BLENDMODE_NONE: |
683 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); | 599 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
684 data->glDisable(GL_BLEND); | 600 data->glDisable(GL_BLEND); |
685 break; | 601 break; |
686 case SDL_BLENDMODE_MASK: | 602 case SDL_BLENDMODE_MASK: |
687 case SDL_BLENDMODE_BLEND: | 603 case SDL_BLENDMODE_BLEND: |
688 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | 604 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
698 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | 614 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
699 data->glEnable(GL_BLEND); | 615 data->glEnable(GL_BLEND); |
700 data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); | 616 data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); |
701 break; | 617 break; |
702 } | 618 } |
703 data->blendMode = texture->blendMode; | 619 data->blendMode = blendMode; |
704 } | 620 } |
621 } | |
622 | |
623 static int | |
624 GLES_RenderPoint(SDL_Renderer * renderer, int x, int y) | |
625 { | |
626 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | |
627 | |
628 GLES_SetBlendMode(data, renderer->blendMode); | |
629 | |
630 data->glColor4f((GLfloat) renderer->r * inv255f, | |
631 (GLfloat) renderer->g * inv255f, | |
632 (GLfloat) renderer->b * inv255f, | |
633 (GLfloat) renderer->a * inv255f); | |
634 | |
635 /* FIXME: | |
636 data->glBegin(GL_POINTS); | |
637 data->glVertex2i(x, y); | |
638 data->glEnd(); | |
639 */ | |
640 return 0; | |
641 } | |
642 | |
643 static int | |
644 GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) | |
645 { | |
646 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | |
647 | |
648 GLES_SetBlendMode(data, renderer->blendMode); | |
649 | |
650 data->glColor4f((GLfloat) renderer->r * inv255f, | |
651 (GLfloat) renderer->g * inv255f, | |
652 (GLfloat) renderer->b * inv255f, | |
653 (GLfloat) renderer->a * inv255f); | |
654 | |
655 /* FIXME: | |
656 data->glBegin(GL_LINES); | |
657 data->glVertex2i(x1, y1); | |
658 data->glVertex2i(x2, y2); | |
659 data->glEnd(); | |
660 */ | |
661 return 0; | |
662 } | |
663 | |
664 static int | |
665 GLES_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) | |
666 { | |
667 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | |
668 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | |
669 | |
670 GLES_SetBlendMode(data, renderer->blendMode); | |
671 | |
672 data->glColor4f((GLfloat) renderer->r * inv255f, | |
673 (GLfloat) renderer->g * inv255f, | |
674 (GLfloat) renderer->b * inv255f, | |
675 (GLfloat) renderer->a * inv255f); | |
676 | |
677 /* FIXME: | |
678 data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h); | |
679 */ | |
680 return 0; | |
681 } | |
682 | |
683 static int | |
684 GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | |
685 const SDL_Rect * srcrect, const SDL_Rect * dstrect) | |
686 { | |
687 | |
688 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; | |
689 GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; | |
690 int minx, miny, maxx, maxy; | |
691 GLfloat minu, maxu, minv, maxv; | |
692 int i; | |
693 void *temp_buffer; /* used for reformatting dirty rect pixels */ | |
694 void *temp_ptr; | |
695 | |
696 if (texturedata->dirty.list) { | |
697 SDL_DirtyRect *dirty; | |
698 void *pixels; | |
699 int bpp = SDL_BYTESPERPIXEL(texture->format); | |
700 int pitch = texturedata->pitch; | |
701 | |
702 SetupTextureUpdate(data, texture, pitch); | |
703 | |
704 data->glBindTexture(texturedata->type, texturedata->texture); | |
705 for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) { | |
706 SDL_Rect *rect = &dirty->rect; | |
707 pixels = | |
708 (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch + | |
709 rect->x * bpp); | |
710 /* There is no GL_UNPACK_ROW_LENGTH in OpenGLES | |
711 we must do this reformatting ourselves(!) | |
712 | |
713 maybe it'd be a good idea to keep a temp buffer around | |
714 for this purpose rather than allocating it each time | |
715 */ | |
716 temp_buffer = SDL_malloc(rect->w * rect->h * bpp); | |
717 temp_ptr = temp_buffer; | |
718 for (i = 0; i < rect->h; i++) { | |
719 SDL_memcpy(temp_ptr, pixels, rect->w * bpp); | |
720 temp_ptr += rect->w * bpp; | |
721 pixels += pitch; | |
722 } | |
723 | |
724 data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y, | |
725 rect->w, rect->h, texturedata->format, | |
726 texturedata->formattype, temp_buffer); | |
727 | |
728 SDL_free(temp_buffer); | |
729 | |
730 } | |
731 SDL_ClearDirtyRects(&texturedata->dirty); | |
732 } | |
733 | |
734 data->glBindTexture(texturedata->type, texturedata->texture); | |
735 data->glEnable(GL_TEXTURE_2D); | |
736 | |
737 if (texture->modMode) { | |
738 data->glColor4f((GLfloat) texture->r * inv255f, | |
739 (GLfloat) texture->g * inv255f, | |
740 (GLfloat) texture->b * inv255f, | |
741 (GLfloat) texture->a * inv255f); | |
742 } else { | |
743 data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | |
744 } | |
745 | |
746 GLES_SetBlendMode(data, texture->blendMode); | |
705 | 747 |
706 switch (texture->scaleMode) { | 748 switch (texture->scaleMode) { |
707 case SDL_TEXTURESCALEMODE_NONE: | 749 case SDL_TEXTURESCALEMODE_NONE: |
708 case SDL_TEXTURESCALEMODE_FAST: | 750 case SDL_TEXTURESCALEMODE_FAST: |
709 data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, | 751 data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, |