src/render/opengl/SDL_render_gl.c
changeset 13664 1c73cc1e4a3a
parent 13536 4ba421b1e88f
child 13696 ea20a7434b98
equal deleted inserted replaced
13663:37af808e6222 13664:1c73cc1e4a3a
   583         texture->format == SDL_PIXELFORMAT_IYUV) {
   583         texture->format == SDL_PIXELFORMAT_IYUV) {
   584         data->yuv = SDL_TRUE;
   584         data->yuv = SDL_TRUE;
   585 
   585 
   586         renderdata->glGenTextures(1, &data->utexture);
   586         renderdata->glGenTextures(1, &data->utexture);
   587         renderdata->glGenTextures(1, &data->vtexture);
   587         renderdata->glGenTextures(1, &data->vtexture);
   588         renderdata->glEnable(textype);
       
   589 
   588 
   590         renderdata->glBindTexture(textype, data->utexture);
   589         renderdata->glBindTexture(textype, data->utexture);
   591         renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER,
   590         renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER,
   592                                     scaleMode);
   591                                     scaleMode);
   593         renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER,
   592         renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER,
   608                                     GL_CLAMP_TO_EDGE);
   607                                     GL_CLAMP_TO_EDGE);
   609         renderdata->glTexParameteri(textype, GL_TEXTURE_WRAP_T,
   608         renderdata->glTexParameteri(textype, GL_TEXTURE_WRAP_T,
   610                                     GL_CLAMP_TO_EDGE);
   609                                     GL_CLAMP_TO_EDGE);
   611         renderdata->glTexImage2D(textype, 0, internalFormat, (texture_w+1)/2,
   610         renderdata->glTexImage2D(textype, 0, internalFormat, (texture_w+1)/2,
   612                                  (texture_h+1)/2, 0, format, type, NULL);
   611                                  (texture_h+1)/2, 0, format, type, NULL);
   613 
       
   614         renderdata->glDisable(textype);
       
   615     }
   612     }
   616 
   613 
   617     if (texture->format == SDL_PIXELFORMAT_NV12 ||
   614     if (texture->format == SDL_PIXELFORMAT_NV12 ||
   618         texture->format == SDL_PIXELFORMAT_NV21) {
   615         texture->format == SDL_PIXELFORMAT_NV21) {
   619         data->nv12 = SDL_TRUE;
   616         data->nv12 = SDL_TRUE;
   620 
   617 
   621         renderdata->glGenTextures(1, &data->utexture);
   618         renderdata->glGenTextures(1, &data->utexture);
   622         renderdata->glEnable(textype);
       
   623 
       
   624         renderdata->glBindTexture(textype, data->utexture);
   619         renderdata->glBindTexture(textype, data->utexture);
   625         renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER,
   620         renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER,
   626                                     scaleMode);
   621                                     scaleMode);
   627         renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER,
   622         renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER,
   628                                     scaleMode);
   623                                     scaleMode);
   630                                     GL_CLAMP_TO_EDGE);
   625                                     GL_CLAMP_TO_EDGE);
   631         renderdata->glTexParameteri(textype, GL_TEXTURE_WRAP_T,
   626         renderdata->glTexParameteri(textype, GL_TEXTURE_WRAP_T,
   632                                     GL_CLAMP_TO_EDGE);
   627                                     GL_CLAMP_TO_EDGE);
   633         renderdata->glTexImage2D(textype, 0, GL_LUMINANCE_ALPHA, (texture_w+1)/2,
   628         renderdata->glTexImage2D(textype, 0, GL_LUMINANCE_ALPHA, (texture_w+1)/2,
   634                                  (texture_h+1)/2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL);
   629                                  (texture_h+1)/2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL);
   635         renderdata->glDisable(textype);
       
   636     }
   630     }
   637 
   631 
   638     return GL_CheckError("", renderer);
   632     return GL_CheckError("", renderer);
   639 }
   633 }
   640 
   634 
   651 
   645 
   652     GL_ActivateRenderer(renderer);
   646     GL_ActivateRenderer(renderer);
   653 
   647 
   654     renderdata->drawstate.texture = NULL;  /* we trash this state. */
   648     renderdata->drawstate.texture = NULL;  /* we trash this state. */
   655 
   649 
   656     renderdata->glEnable(textype);
       
   657     renderdata->glBindTexture(textype, data->texture);
   650     renderdata->glBindTexture(textype, data->texture);
   658     renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   651     renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   659     renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / texturebpp));
   652     renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / texturebpp));
   660     renderdata->glTexSubImage2D(textype, 0, rect->x, rect->y, rect->w,
   653     renderdata->glTexSubImage2D(textype, 0, rect->x, rect->y, rect->w,
   661                                 rect->h, data->format, data->formattype,
   654                                 rect->h, data->format, data->formattype,
   694         renderdata->glBindTexture(textype, data->utexture);
   687         renderdata->glBindTexture(textype, data->utexture);
   695         renderdata->glTexSubImage2D(textype, 0, rect->x/2, rect->y/2,
   688         renderdata->glTexSubImage2D(textype, 0, rect->x/2, rect->y/2,
   696                                     (rect->w + 1)/2, (rect->h + 1)/2,
   689                                     (rect->w + 1)/2, (rect->h + 1)/2,
   697                                     GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pixels);
   690                                     GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pixels);
   698     }
   691     }
   699     renderdata->glDisable(textype);
       
   700 
   692 
   701     return GL_CheckError("glTexSubImage2D()", renderer);
   693     return GL_CheckError("glTexSubImage2D()", renderer);
   702 }
   694 }
   703 
   695 
   704 static int
   696 static int
   714 
   706 
   715     GL_ActivateRenderer(renderer);
   707     GL_ActivateRenderer(renderer);
   716 
   708 
   717     renderdata->drawstate.texture = NULL;  /* we trash this state. */
   709     renderdata->drawstate.texture = NULL;  /* we trash this state. */
   718 
   710 
   719     renderdata->glEnable(textype);
       
   720     renderdata->glBindTexture(textype, data->texture);
   711     renderdata->glBindTexture(textype, data->texture);
   721     renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   712     renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   722     renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Ypitch);
   713     renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Ypitch);
   723     renderdata->glTexSubImage2D(textype, 0, rect->x, rect->y, rect->w,
   714     renderdata->glTexSubImage2D(textype, 0, rect->x, rect->y, rect->w,
   724                                 rect->h, data->format, data->formattype,
   715                                 rect->h, data->format, data->formattype,
   733     renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Vpitch);
   724     renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Vpitch);
   734     renderdata->glBindTexture(textype, data->vtexture);
   725     renderdata->glBindTexture(textype, data->vtexture);
   735     renderdata->glTexSubImage2D(textype, 0, rect->x/2, rect->y/2,
   726     renderdata->glTexSubImage2D(textype, 0, rect->x/2, rect->y/2,
   736                                 (rect->w + 1)/2, (rect->h + 1)/2,
   727                                 (rect->w + 1)/2, (rect->h + 1)/2,
   737                                 data->format, data->formattype, Vplane);
   728                                 data->format, data->formattype, Vplane);
   738     renderdata->glDisable(textype);
       
   739 
   729 
   740     return GL_CheckError("glTexSubImage2D()", renderer);
   730     return GL_CheckError("glTexSubImage2D()", renderer);
   741 }
   731 }
   742 
   732 
   743 static int
   733 static int
   774     GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   764     GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
   775     const GLenum textype = renderdata->textype;
   765     const GLenum textype = renderdata->textype;
   776     GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   766     GL_TextureData *data = (GL_TextureData *) texture->driverdata;
   777     GLenum glScaleMode = (scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR;
   767     GLenum glScaleMode = (scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR;
   778 
   768 
   779     renderdata->glEnable(textype);
       
   780     renderdata->glBindTexture(textype, data->texture);
   769     renderdata->glBindTexture(textype, data->texture);
   781     renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
   770     renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
   782     renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
   771     renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
   783     renderdata->glDisable(textype);
       
   784 
   772 
   785     if (texture->format == SDL_PIXELFORMAT_YV12 ||
   773     if (texture->format == SDL_PIXELFORMAT_YV12 ||
   786         texture->format == SDL_PIXELFORMAT_IYUV) {
   774         texture->format == SDL_PIXELFORMAT_IYUV) {
   787         renderdata->glEnable(textype);
       
   788         renderdata->glBindTexture(textype, data->utexture);
   775         renderdata->glBindTexture(textype, data->utexture);
   789         renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
   776         renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
   790         renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
   777         renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
   791 
   778 
   792         renderdata->glBindTexture(textype, data->vtexture);
   779         renderdata->glBindTexture(textype, data->vtexture);
   793         renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
   780         renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
   794         renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
   781         renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
   795         renderdata->glDisable(textype);
       
   796     }
   782     }
   797 
   783 
   798     if (texture->format == SDL_PIXELFORMAT_NV12 ||
   784     if (texture->format == SDL_PIXELFORMAT_NV12 ||
   799         texture->format == SDL_PIXELFORMAT_NV21) {
   785         texture->format == SDL_PIXELFORMAT_NV21) {
   800         renderdata->glEnable(textype);
       
   801         renderdata->glBindTexture(textype, data->utexture);
   786         renderdata->glBindTexture(textype, data->utexture);
   802         renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
   787         renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
   803         renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
   788         renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
   804         renderdata->glDisable(textype);
       
   805     }
   789     }
   806 }
   790 }
   807 
   791 
   808 static int
   792 static int
   809 GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
   793 GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)