Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c311bb5c95 | |||
887705969f | |||
316871523d | |||
a3d193516c |
2
external/solanaceae_toxcore
vendored
2
external/solanaceae_toxcore
vendored
Submodule external/solanaceae_toxcore updated: 49ab40a1ba...3b75a1c5d3
8
flake.lock
generated
8
flake.lock
generated
@ -20,16 +20,16 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1694553957,
|
||||
"narHash": "sha256-8o15HEax53lBJjjcr5VHMpuuT6vBcrzSNB6y2iGlPaU=",
|
||||
"lastModified": 1709953752,
|
||||
"narHash": "sha256-LW84B4vM1cn7E6cDNQn2LndT9iJXI1dRE5fwbNFbQa8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "e7fe745d22df5fa282b321e577fe18d4f62e0f0b",
|
||||
"rev": "fcaa81ed3c273237217330cf342ef1873b77c80a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "release-23.05",
|
||||
"ref": "release-23.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
# append '.?submodules=1' to the nix commands.
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/release-23.11";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
|
@ -1,13 +1,17 @@
|
||||
#include "./sdlrenderer_texture_uploader.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
SDLRendererTextureUploader::SDLRendererTextureUploader(SDL_Renderer* renderer_) :
|
||||
renderer(renderer_)
|
||||
{
|
||||
}
|
||||
|
||||
uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter) {
|
||||
uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter, Access access) {
|
||||
// TODO: test if pitch is 4 or 4*width
|
||||
SDL_Surface* surf = SDL_CreateSurfaceFrom(
|
||||
(void*)data,
|
||||
@ -17,8 +21,15 @@ uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t wi
|
||||
);
|
||||
assert(surf); // TODO: add error reporting
|
||||
|
||||
SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, surf);
|
||||
SDL_Texture* tex = SDL_CreateTexture(
|
||||
renderer,
|
||||
surf->format->format,
|
||||
access == Access::STREAMING ? SDL_TEXTUREACCESS_STREAMING : SDL_TEXTUREACCESS_STATIC,
|
||||
surf->w, surf->h
|
||||
);
|
||||
assert(tex); // TODO: add error reporting
|
||||
// TODO: error reporting
|
||||
SDL_UpdateTexture(tex, nullptr, surf->pixels, surf->pitch);
|
||||
|
||||
if (filter == NEAREST) {
|
||||
SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_NEAREST);
|
||||
@ -31,6 +42,27 @@ uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t wi
|
||||
return reinterpret_cast<uint64_t>(tex);
|
||||
}
|
||||
|
||||
bool SDLRendererTextureUploader::updateRGBA(uint64_t tex_id, const uint8_t* data, size_t size) {
|
||||
auto* texture = static_cast<SDL_Texture*>(reinterpret_cast<void*>(tex_id));
|
||||
if (texture == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* pixels = nullptr;
|
||||
int pitch = 0;
|
||||
|
||||
if (SDL_LockTexture(texture, nullptr, (void**)&pixels, &pitch) != 0) {
|
||||
std::cerr << "SDLRTU error: failed locking texture '" << SDL_GetError() << "'\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::memcpy(pixels, data, size);
|
||||
|
||||
SDL_UnlockTexture(texture);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SDLRendererTextureUploader::destroy(uint64_t tex_id) {
|
||||
SDL_DestroyTexture(static_cast<SDL_Texture*>(reinterpret_cast<void*>(tex_id)));
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ struct SDLRendererTextureUploader : public TextureUploaderI {
|
||||
SDLRendererTextureUploader(SDL_Renderer* renderer_);
|
||||
~SDLRendererTextureUploader(void) = default;
|
||||
|
||||
uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter) override;
|
||||
uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter, Access access) override;
|
||||
bool updateRGBA(uint64_t tex_id, const uint8_t* data, size_t size) override;
|
||||
void destroy(uint64_t tex_id) override;
|
||||
};
|
||||
|
||||
|
@ -1,18 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
struct TextureUploaderI {
|
||||
static constexpr const char* version {"1"};
|
||||
static constexpr const char* version {"2"};
|
||||
|
||||
enum Filter {
|
||||
NEAREST,
|
||||
LINEAR,
|
||||
};
|
||||
|
||||
enum Access {
|
||||
STATIC,
|
||||
STREAMING,
|
||||
// target?
|
||||
};
|
||||
|
||||
virtual ~TextureUploaderI(void) {}
|
||||
|
||||
virtual uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter = LINEAR) = 0;
|
||||
virtual uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter = LINEAR, Access access = STATIC) = 0;
|
||||
|
||||
// keeps width height filter
|
||||
// TODO: wh instead of size?
|
||||
virtual bool updateRGBA(uint64_t tex_id, const uint8_t* data, size_t size) = 0;
|
||||
|
||||
virtual void destroy(uint64_t tex_id) = 0;
|
||||
};
|
||||
|
Reference in New Issue
Block a user