Experiment with streamable texture

This commit is contained in:
Stefan Arentz 2017-10-01 16:38:33 -04:00
parent 7fa17909f6
commit 6797eeaf9e
3 changed files with 19 additions and 7 deletions

View File

@ -35,6 +35,8 @@ struct ewm_tty_t *ewm_tty_create(SDL_Renderer *renderer) {
EWM_ONE_TTY_ROWS * ewm_chr_height(tty->chr), 32, 4 * EWM_ONE_TTY_COLUMNS * ewm_chr_width(tty->chr),
ewm_sdl_pixel_format(renderer));
tty->texture = SDL_CreateTexture(renderer, ewm_sdl_pixel_format(renderer), SDL_TEXTUREACCESS_STREAMING, 280, 192);
ewm_tty_reset(tty);
return tty;
}
@ -115,6 +117,21 @@ void ewm_tty_reset(struct ewm_tty_t *tty) {
}
void ewm_tty_refresh(struct ewm_tty_t *tty, uint32_t phase, uint32_t fps) {
uint32_t *pixels;
int pitch;
if (SDL_LockTexture(tty->texture, NULL, (void**) &pixels, &pitch) != 0) {
printf("Cannot lock texture: %s\n", SDL_GetError());
exit(1);
}
uint32_t green = tty->chr->green;
for (int i = 0; i < 192 * 280; i++) {
*pixels++ = green;
}
SDL_UnlockTexture(tty->texture);
for (int row = 0; row < 24; row++) {
for (int column = 0; column < 40; column++) {
ewm_tty_render_character(tty, row, column, tty->screen_buffer[(row * EWM_ONE_TTY_COLUMNS) + column]);

View File

@ -46,6 +46,7 @@ struct ewm_tty_t {
uint32_t *pixels;
SDL_Surface *surface;
SDL_Texture *texture;
};
struct ewm_tty_t *ewm_tty_create(SDL_Renderer *renderer);

View File

@ -18,13 +18,7 @@ void test(struct ewm_tty_t *tty) {
SDL_RenderClear(tty->renderer);
ewm_tty_refresh(tty, 1, EWM_ONE_FPS);
SDL_Texture *texture = SDL_CreateTextureFromSurface(tty->renderer, tty->surface);
if (texture != NULL) {
SDL_RenderCopy(tty->renderer, texture, NULL, NULL);
SDL_DestroyTexture(texture);
}
SDL_RenderCopy(tty->renderer, tty->texture, NULL, NULL);
SDL_RenderPresent(tty->renderer);
}
Uint64 now = SDL_GetPerformanceCounter();