make texture streaming actually work
This commit is contained in:
parent
316871523d
commit
887705969f
@ -4,6 +4,8 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
SDLRendererTextureUploader::SDLRendererTextureUploader(SDL_Renderer* renderer_) :
|
SDLRendererTextureUploader::SDLRendererTextureUploader(SDL_Renderer* renderer_) :
|
||||||
renderer(renderer_)
|
renderer(renderer_)
|
||||||
{
|
{
|
||||||
@ -19,16 +21,15 @@ uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t wi
|
|||||||
);
|
);
|
||||||
assert(surf); // TODO: add error reporting
|
assert(surf); // TODO: add error reporting
|
||||||
|
|
||||||
// hacky hint usage
|
SDL_Texture* tex = SDL_CreateTexture(
|
||||||
if (access == Access::STREAMING) {
|
renderer,
|
||||||
SDL_SetHint("SDL_TextureAccess", "SDL_TEXTUREACCESS_STREAMING");
|
surf->format->format,
|
||||||
} else {
|
access == Access::STREAMING ? SDL_TEXTUREACCESS_STREAMING : SDL_TEXTUREACCESS_STATIC,
|
||||||
SDL_SetHint("SDL_TextureAccess", "SDL_TEXTUREACCESS_STATIC");
|
surf->w, surf->h
|
||||||
}
|
);
|
||||||
// TODO: cleanup hints after
|
|
||||||
|
|
||||||
SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, surf);
|
|
||||||
assert(tex); // TODO: add error reporting
|
assert(tex); // TODO: add error reporting
|
||||||
|
// TODO: error reporting
|
||||||
|
SDL_UpdateTexture(tex, nullptr, surf->pixels, surf->pitch);
|
||||||
|
|
||||||
if (filter == NEAREST) {
|
if (filter == NEAREST) {
|
||||||
SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_NEAREST);
|
SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_NEAREST);
|
||||||
@ -51,7 +52,7 @@ bool SDLRendererTextureUploader::updateRGBA(uint64_t tex_id, const uint8_t* data
|
|||||||
int pitch = 0;
|
int pitch = 0;
|
||||||
|
|
||||||
if (SDL_LockTexture(texture, nullptr, (void**)&pixels, &pitch) != 0) {
|
if (SDL_LockTexture(texture, nullptr, (void**)&pixels, &pitch) != 0) {
|
||||||
// TODO: error
|
std::cerr << "SDLRTU error: failed locking texture '" << SDL_GetError() << "'\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user