src/sdl/hardware_renderer.cc
/*
 * Renders the pixel buffer to the screen using hardware accelaration.
 *
 * Assumes that the window provided during initialization was valid.
 */
Renders the pixel buffer to the screen using hardware accelaration.
Assumes that the window provided during initialization was valid.
Renders the pixel buffer to the screen using hardware accelaration . Assumes that the window provided during initialization was valid .
void HardwareRenderer::DrawFrame(void) {
  if (!window_size_valid_) {
    GetWindowRect();
    window_size_valid_ = true;
    SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
    SDL_RenderClear(renderer_);
  }
  void *texture_pixels;
  int pitch;
  SDL_LockTexture(frame_texture_, NULL, &texture_pixels, &pitch);
  for (int i = 0; i < (NES_WIDTH * NES_HEIGHT); i++) {
    (static_cast<uint32_t*>(texture_pixels))[i] = pixel_buffer_[i];
  }
  SDL_UnlockTexture(frame_texture_);
  SDL_RenderCopy(renderer_, frame_texture_, &kFrameRect_, &window_rect_);
  SDL_RenderPresent(renderer_);
  return;
}
void HardwareRenderer :: DrawFrame ( void ) { if ( ! window_size_valid_ ) { GetWindowRect ( ) ; window_size_valid_ = true ; SDL_SetRenderDrawColor ( renderer_ , 0 , 0 , 0 , 0 ) ; SDL_RenderClear ( renderer_ ) ; } void * texture_pixels ; int pitch ; SDL_LockTexture ( frame_texture_ , NULL , & texture_pixels , & pitch ) ; for ( int i = 0 ; i < ( NES_WIDTH * NES_HEIGHT ) ; i ++ ) { ( static_cast < uint32_t * > ( texture_pixels ) ) [ i ] = pixel_buffer_ [ i ] ; } SDL_UnlockTexture ( frame_texture_ ) ; SDL_RenderCopy ( renderer_ , frame_texture_ , & kFrameRect_ , & window_rect_ ) ; SDL_RenderPresent ( renderer_ ) ; return ; }
Renders the pixel buffer to the screen using hardware accelaration.
Renders the pixel buffer to the screen using hardware accelaration .
// Recalculate the window rect if the window has been resized. // Clear the window on resize. // Update the texture with the latest pixel data. // Copy the render surface to the window surface. // Update the window.