@@ -173,7 +173,7 @@ struct GLNVGtexture {
173173 int width , height ;
174174 int type ;
175175 int flags ;
176- #if defined NANOVG_GLES2
176+ #if defined( NANOVG_GLES2 ) || defined( NANOVG_GLES3 )
177177 unsigned char * data ;
178178#endif
179179};
@@ -813,8 +813,8 @@ static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int im
813813 switch (type )
814814 {
815815 case NVG_TEXTURE_BGR :
816- #if NANOVG_GLES2
817- // GLES2 cannot handle GL_BGR, do local conversion to GL_RGB
816+ #if defined( NANOVG_GLES2 ) || defined( NANOVG_GLES3 )
817+ // GLES cannot handle GL_BGR, do local conversion to GL_RGB
818818 tex -> data = (uint8_t * )malloc (sizeof (uint8_t ) * 3 * w * h );
819819 for (int i = 0 ; i < w * h ; ++ i )
820820 {
@@ -829,8 +829,8 @@ static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int im
829829#endif
830830 break ;
831831 case NVG_TEXTURE_BGRA :
832- #if NANOVG_GLES2
833- // GLES2 cannot handle GL_BGRA, do local conversion to GL_RGBA
832+ #if defined( NANOVG_GLES2 ) || defined( NANOVG_GLES3 )
833+ // GLES cannot handle GL_BGRA, do local conversion to GL_RGBA
834834 tex -> data = (uint8_t * )malloc (sizeof (uint8_t ) * 4 * w * h );
835835 for (int i = 0 ; i < w * h ; ++ i )
836836 {
@@ -840,7 +840,7 @@ static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int im
840840 tex -> data [i * 3 + 3 ] = data [i * 3 + 0 ];
841841 }
842842 data = tex -> data ;
843- glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA , w , h , 0 , GL_BGRA , GL_UNSIGNED_BYTE , data );
843+ glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA , w , h , 0 , GL_RGBA , GL_UNSIGNED_BYTE , data );
844844#else
845845 glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA , w , h , 0 , GL_BGRA , GL_UNSIGNED_BYTE , data );
846846#endif
@@ -852,11 +852,11 @@ static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int im
852852 glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA , w , h , 0 , GL_RGBA , GL_UNSIGNED_BYTE , data );
853853 break ;
854854 default :
855- #if defined (NANOVG_GL2 )
855+ #if defined(NANOVG_GL2 ) || defined( NANOVG_GLES2 )
856856 glTexImage2D (GL_TEXTURE_2D , 0 , GL_LUMINANCE , w , h , 0 , GL_LUMINANCE , GL_UNSIGNED_BYTE , data );
857- #elif defined(NANOVG_GLES2 ) || defined(NANOVG_GLES3 )
858- glTexImage2D (GL_TEXTURE_2D , 0 , GL_R8 , w , h , 0 , GL_RED , GL_UNSIGNED_BYTE , data );
859857#else
858+ glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_SWIZZLE_G , GL_RED );
859+ glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_SWIZZLE_B , GL_RED );
860860 glTexImage2D (GL_TEXTURE_2D , 0 , GL_RED , w , h , 0 , GL_RED , GL_UNSIGNED_BYTE , data );
861861#endif
862862 break ;
@@ -960,19 +960,23 @@ static int glnvg__renderUpdateTexture(void* uptr, int image, int x, int y, int w
960960 switch (tex -> type )
961961 {
962962 case NVG_TEXTURE_BGR :
963+ #if !(defined(NANOVG_GLES2 ) || defined(NANOVG_GLES3 ))
963964 glTexSubImage2D (GL_TEXTURE_2D , 0 , x ,y , w ,h , GL_BGR , GL_UNSIGNED_BYTE , data );
964965 break ;
965- case NVG_TEXTURE_BGRA :
966- glTexSubImage2D (GL_TEXTURE_2D , 0 , x ,y , w ,h , GL_BGRA , GL_UNSIGNED_BYTE , data );
967- break ;
966+ #endif
968967 case NVG_TEXTURE_RGB :
969968 glTexSubImage2D (GL_TEXTURE_2D , 0 , x ,y , w ,h , GL_RGB , GL_UNSIGNED_BYTE , data );
970969 break ;
970+ case NVG_TEXTURE_BGRA :
971+ #if !(defined(NANOVG_GLES2 ) || defined(NANOVG_GLES3 ))
972+ glTexSubImage2D (GL_TEXTURE_2D , 0 , x ,y , w ,h , GL_BGRA , GL_UNSIGNED_BYTE , data );
973+ break ;
974+ #endif
971975 case NVG_TEXTURE_RGBA :
972976 glTexSubImage2D (GL_TEXTURE_2D , 0 , x ,y , w ,h , GL_RGBA , GL_UNSIGNED_BYTE , data );
973977 break ;
974978 default :
975- #if defined(NANOVG_GL2 )
979+ #if defined(NANOVG_GL2 ) || defined( NANOVG_GLES2 )
976980 glTexSubImage2D (GL_TEXTURE_2D , 0 , x ,y , w ,h , GL_LUMINANCE , GL_UNSIGNED_BYTE , data );
977981#else
978982 glTexSubImage2D (GL_TEXTURE_2D , 0 , x ,y , w ,h , GL_RED , GL_UNSIGNED_BYTE , data );
0 commit comments