static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; GL_TextureData *data = (GL_TextureData *) texture->driverdata; GLenum result; GL_ActivateRenderer(renderer); renderdata->glGetError(); renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / SDL_BYTESPERPIXEL(texture->format))); renderdata->glEnable(data->type); renderdata->glBindTexture(data->type, data->texture); renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, rect->h, data->format, data->formattype, pixels); if (data->yuv) { const void *top; renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / 2)); /* Skip to the top of the next texture */ top = (const void*)((const Uint8*)pixels + (texture->h-rect->y) * pitch - rect->x); /* Skip to the correct offset into the next texture */ pixels = (const void*)((const Uint8*)top + (rect->y / 2) * pitch + rect->x / 2); if (texture->format == SDL_PIXELFORMAT_YV12) { renderdata->glBindTexture(data->type, data->vtexture); } else { renderdata->glBindTexture(data->type, data->utexture); } renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2, rect->w/2, rect->h/2, data->format, data->formattype, pixels); /* Skip to the top of the next texture */ top = (const void*)((const Uint8*)top + (texture->h * pitch)/4); /* Skip to the correct offset into the next texture */ pixels = (const void*)((const Uint8*)top + (rect->y / 2) * pitch + rect->x / 2); if (texture->format == SDL_PIXELFORMAT_YV12) { renderdata->glBindTexture(data->type, data->utexture); } else { renderdata->glBindTexture(data->type, data->vtexture); } renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2, rect->w/2, rect->h/2, data->format, data->formattype, pixels); } renderdata->glDisable(data->type); result = renderdata->glGetError(); if (result != GL_NO_ERROR) { GL_SetError("glTexSubImage2D()", result); return -1; } return 0; }