void update() { YUVBuffer yuv; // yuv_buffer_try_lock(...) returns false if the last read frame is // still up to date, in this case we can simply retender the // last frame without an update // We don't need to call unlock unless the lock operation was successfull if(!ogg.yuv_buffer_try_lock(&yuv)) return; // Create the textures if needed, at this point we // know how big the textures should be. // The sample plyer that comes with the official SDK // assummes uv_width=y_width/2 , uv_height=y_height/2 // but I'm not sure whether that is always true if(-1==y_tex){ y_tex = gen_texture(yuv.y_width,yuv.y_height); u_tex = gen_texture(yuv.uv_width,yuv.uv_height); v_tex = gen_texture(yuv.uv_width,yuv.uv_height); } int y_offset = ogg.offset_x() + yuv.y_stride * ogg.offset_y(); int uv_offset = ogg.offset_x()/(yuv.y_width/yuv.uv_width)+ yuv.uv_stride * ogg.offset_y()/(yuv.y_height/yuv.uv_height); update_texture(y_tex,yuv.y+y_offset,yuv.y_width,yuv.y_height,yuv.y_stride); update_texture(u_tex,yuv.u+uv_offset,yuv.uv_width,yuv.uv_height,yuv.uv_stride); update_texture(v_tex,yuv.v+uv_offset,yuv.uv_width,yuv.uv_height,yuv.uv_stride); ogg.yuv_buffer_unlock(); }
void GL_object::set_texture(const std::string& filename) { if (texture) Texture_manager::get().release_texture(texture); texture = Texture_manager::get().request_texture(filename); update_texture(); }
texture_ref * load_texture(outki::texture *texture) { LoadedTextures::iterator i = s_textures.find(texture->id); if (i != s_textures.end()) { i->second->refcount++; return i->second; } LIVE_UPDATE(&texture); if (!texture->output) { KOSMOS_WARNING("Trying to load a texture which has no generated output! [" << texture->id << "]"); return 0; } texture_ref *tex = new texture_ref(); tex->refcount = 1; tex->source = texture->id; tex->container = texture->output->data; tex->source_tex = texture; tex->dynamic = false; glGenTextures(1, &tex->handle); s_textures.insert(LoadedTextures::value_type(texture->id, tex)); update_texture(tex); return tex; }
void Cube::init_texture(textur arg_tx[]) { cur = 0; for (int i=0; i<3; i++) tx[i] = &arg_tx[i]; update_texture(); }
void show_frame(render_context_type *rc) { glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // очистка буферов glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); update_texture(rc); glBegin(GL_QUADS); glTexCoord2f(rc->tx0,rc->ty1); glVertex2f(0.0,0.0); glTexCoord2f(rc->tx1,rc->ty1); glVertex2f(1.0,0.0); glTexCoord2f(rc->tx1,rc->ty0); glVertex2f(1.0,1.0); glTexCoord2f(rc->tx0,rc->ty0); glVertex2f(0.0,1.0); glEnd(); glFlush(); SDL_GL_SwapBuffers(); }
static void vo_gl_display (AVPicture * pict) { vo_gl_vfmt2rgb (my_pic, pict); image = my_pic->data[0]; resize (100, 100); update_texture (); }
int main( int argc , char ** argv ) { printf( "Starting up VoidEye test.\n" ); init_test( "" ); update_texture(); remove_colours(); update_texture(); int b , d , a; b = find_brightest(); d = find_darkest(); a = find_avarage(); printf( "b: %d d: %d a: %d\n", b , d , a ); apply_contrast( 256 ); update_texture(); create_groups(); return 0; }
void begin(int width, int height, bool clearcolor, bool cleardepth, unsigned int clear_color) { // LoadedTextures::iterator i = s_textures.begin(); while (i != s_textures.end()) { bool upd = false; if (LIVE_UPDATE(&i->second->source_tex)) { if (i->second->source_tex->output) i->second->container = i->second->source_tex->output->data; else i->second->container = 0; upd = true; } if (i->second->container) { if (LIVE_UPDATE(&i->second->container)) upd = true; if (LIVE_UPDATE(&i->second->container->streaming)) upd = true; } if (upd) { KOSMOS_INFO("Texture live updated"); update_texture(i->second); } ++i; } glViewport(0, 0, width, height); glClearColor(1, 1, 1, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); }
void VideoStreamPlaybackGDNative::update(float p_delta) { if (!playing || paused) { return; } if (!file) { return; } time += p_delta; ERR_FAIL_COND(interface == NULL); interface->update(data_struct, p_delta); if (mix_callback) { if (pcm_write_idx >= 0) { // Previous remains int mixed = mix_callback(mix_udata, pcm, samples_decoded); if (mixed == samples_decoded) { pcm_write_idx = -1; } else { samples_decoded -= mixed; pcm_write_idx += mixed; } } if (pcm_write_idx < 0) { samples_decoded = interface->get_audioframe(data_struct, pcm, AUX_BUFFER_SIZE); pcm_write_idx = mix_callback(mix_udata, pcm, samples_decoded); if (pcm_write_idx == samples_decoded) { pcm_write_idx = -1; } else { samples_decoded -= pcm_write_idx; } } } while (interface->get_playback_position(data_struct) < time && playing) { update_texture(); } }
int main(int, char**) { GlCube gl_cube; unsigned int texture_width = 128; unsigned int texture_height = 128; /// Init the GlCube gl_cube.init("Sample of GlCube :p", 800, 800, texture_width, texture_height); /// Get the texture of GlCube (unsigned char* [NB_TEXTURES -> 6]) unsigned char** pp_texture = gl_cube.get_textures(); Uint32 last_ticks = SDL_GetTicks(); SDL_Event event; double oxz_angle = 0.0; double oyz_angle = 0.0; double scale = 1.0; bool quit = false; do { /// Compute the time elapsed since the last call of the next Uint32 current_ticks = SDL_GetTicks(); Uint32 time_elapsed_ms = current_ticks - last_ticks; /// Update the textures of the cube update_texture(pp_texture, texture_width, texture_height); /// Call next method of the GlCube gl_cube.next(scale, oxz_angle, oyz_angle); /// Event handle while(SDL_PollEvent(&event)) { if ((event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) || event.type == SDL_QUIT) { quit = true; } if (event.type == SDL_MOUSEWHEEL) { scale += event.wheel.y / 10.0; if (scale < 0.1) scale = 0.1; } if (event.type == SDL_MOUSEMOTION && SDL_GetMouseState(0, 0) & SDL_BUTTON(1)) { oxz_angle += (double)event.motion.xrel * time_elapsed_ms / 50.0; oyz_angle += (double)event.motion.yrel * time_elapsed_ms / 50.0; if (oyz_angle < -90.0) oyz_angle = -90.0; if (oyz_angle > 90.0) oyz_angle = 90.0; } } last_ticks = current_ticks; } while(!quit); /// Destroy the GlCube gl_cube.destroy(); return 0; }
void fs_emu_video_update_function() { update_texture(); }
int main (int argc, char *argv[]) { struct RISC *risc = risc_new(); risc_set_serial(risc, &pclink); risc_set_clipboard(risc, &sdl_clipboard); struct RISC_LED leds = { .write = show_leds }; bool fullscreen = false; double zoom = 0; SDL_Rect risc_rect = { .w = RISC_FRAMEBUFFER_WIDTH, .h = RISC_FRAMEBUFFER_HEIGHT }; bool size_option = false; int mem_option = 0; const char *serial_in = NULL; const char *serial_out = NULL; bool boot_from_serial = false; int opt; while ((opt = getopt_long(argc, argv, "z:fLm:s:I:O:S", long_options, NULL)) != -1) { switch (opt) { case 'z': { double x = strtod(optarg, 0); if (x > 0) { zoom = x; } break; } case 'f': { fullscreen = true; break; } case 'L': { risc_set_leds(risc, &leds); break; } case 'm': { if (sscanf(optarg, "%d", &mem_option) != 1) { usage(); } break; } case 's': { int w, h; if (sscanf(optarg, "%dx%d", &w, &h) != 2) { usage(); } risc_rect.w = clamp(w, 32, MAX_WIDTH) & ~31; risc_rect.h = clamp(h, 32, MAX_HEIGHT); size_option = true; break; } case 'I': { serial_in = optarg; break; } case 'O': { serial_out = optarg; break; } case 'S': { boot_from_serial = true; risc_set_switches(risc, 1); break; } default: { usage(); } } } if (mem_option || size_option) { risc_configure_memory(risc, mem_option, risc_rect.w, risc_rect.h); } if (optind == argc - 1) { risc_set_spi(risc, 1, disk_new(argv[optind])); } else if (optind == argc && boot_from_serial) { /* Allow diskless boot */ risc_set_spi(risc, 1, disk_new(NULL)); } else { usage(); } if (serial_in || serial_out) { if (!serial_in) { serial_in = "/dev/null"; } if (!serial_out) { serial_out = "/dev/null"; } risc_set_serial(risc, raw_serial_new(serial_in, serial_out)); } if (SDL_Init(SDL_INIT_VIDEO) != 0) { fail(1, "Unable to initialize SDL: %s", SDL_GetError()); } atexit(SDL_Quit); SDL_EnableScreenSaver(); SDL_ShowCursor(false); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best"); int window_flags = SDL_WINDOW_HIDDEN; int display = 0; if (fullscreen) { window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; display = best_display(&risc_rect); } if (zoom == 0) { SDL_Rect bounds; if (SDL_GetDisplayBounds(display, &bounds) == 0 && bounds.h >= risc_rect.h * 2 && bounds.w >= risc_rect.w * 2) { zoom = 2; } else { zoom = 1; } } SDL_Window *window = SDL_CreateWindow("Project Oberon", SDL_WINDOWPOS_UNDEFINED_DISPLAY(display), SDL_WINDOWPOS_UNDEFINED_DISPLAY(display), (int)(risc_rect.w * zoom), (int)(risc_rect.h * zoom), window_flags); if (window == NULL) { fail(1, "Could not create window: %s", SDL_GetError()); } SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0); if (renderer == NULL) { fail(1, "Could not create renderer: %s", SDL_GetError()); } SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, risc_rect.w, risc_rect.h); if (texture == NULL) { fail(1, "Could not create texture: %s", SDL_GetError()); } SDL_Rect display_rect; double display_scale = scale_display(window, &risc_rect, &display_rect); update_texture(risc, texture, &risc_rect); SDL_ShowWindow(window); SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, &risc_rect, &display_rect); SDL_RenderPresent(renderer); bool done = false; bool mouse_was_offscreen = false; while (!done) { uint32_t frame_start = SDL_GetTicks(); SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: { done = true; break; } case SDL_WINDOWEVENT: { if (event.window.event == SDL_WINDOWEVENT_RESIZED) { display_scale = scale_display(window, &risc_rect, &display_rect); } break; } case SDL_MOUSEMOTION: { int scaled_x = (int)round((event.motion.x - display_rect.x) / display_scale); int scaled_y = (int)round((event.motion.y - display_rect.y) / display_scale); int x = clamp(scaled_x, 0, risc_rect.w - 1); int y = clamp(scaled_y, 0, risc_rect.h - 1); bool mouse_is_offscreen = x != scaled_x || y != scaled_y; if (mouse_is_offscreen != mouse_was_offscreen) { SDL_ShowCursor(mouse_is_offscreen); mouse_was_offscreen = mouse_is_offscreen; } risc_mouse_moved(risc, x, risc_rect.h - y - 1); break; } case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { bool down = event.button.state == SDL_PRESSED; risc_mouse_button(risc, event.button.button, down); break; } case SDL_KEYDOWN: case SDL_KEYUP: { bool down = event.key.state == SDL_PRESSED; switch (map_keyboard_event(&event.key)) { case ACTION_RESET: { risc_reset(risc); break; } case ACTION_TOGGLE_FULLSCREEN: { fullscreen ^= true; if (fullscreen) { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } else { SDL_SetWindowFullscreen(window, 0); } break; } case ACTION_QUIT: { SDL_PushEvent(&(SDL_Event){ .type=SDL_QUIT }); break; } case ACTION_FAKE_MOUSE1: { risc_mouse_button(risc, 1, down); break; } case ACTION_FAKE_MOUSE2: { risc_mouse_button(risc, 2, down); break; } case ACTION_FAKE_MOUSE3: { risc_mouse_button(risc, 3, down); break; } case ACTION_OBERON_INPUT: { uint8_t ps2_bytes[MAX_PS2_CODE_LEN]; int len = ps2_encode(event.key.keysym.scancode, down, ps2_bytes); risc_keyboard_input(risc, ps2_bytes, len); break; } } } } } risc_set_time(risc, frame_start); risc_run(risc, CPU_HZ / FPS); update_texture(risc, texture, &risc_rect); SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, &risc_rect, &display_rect); SDL_RenderPresent(renderer); uint32_t frame_end = SDL_GetTicks(); int delay = frame_start + 1000/FPS - frame_end; if (delay > 0) { SDL_Delay(delay); } }
int main (int argc, char *argv[]) { struct RISC *risc = risc_new(); risc_set_serial(risc, &pclink); risc_set_clipboard(risc, &sdl_clipboard); bool fullscreen = false; SDL_Rect risc_rect = { .w = RISC_FRAMEBUFFER_WIDTH, .h = RISC_FRAMEBUFFER_HEIGHT }; int opt; while ((opt = getopt_long(argc, argv, "fS:F:", long_options, NULL)) != -1) { switch (opt) { case 'f': { fullscreen = true; break; } case 's': { int w, h; if (sscanf(optarg, "%dx%d", &w, &h) != 2) { usage(); } risc_rect.w = clamp(w, 32, MAX_WIDTH) & ~31; risc_rect.h = clamp(h, 32, MAX_HEIGHT); risc_screen_size_hack(risc, risc_rect.w, risc_rect.h); break; } case 'F': { risc_set_serial(risc, raw_serial_new(atoi(optarg), atoi(optarg) + 1)); break; } default: { usage(); } } } if (optind != argc - 1) { usage(); } risc_set_spi(risc, 1, disk_new(argv[optind])); sdl_error_if(SDL_Init(SDL_INIT_VIDEO) != 0, "Unable to initialize SDL"); atexit(SDL_Quit); SDL_EnableScreenSaver(); SDL_ShowCursor(false); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best"); int window_flags = SDL_WINDOW_HIDDEN; int window_pos = SDL_WINDOWPOS_UNDEFINED; if (fullscreen) { window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; window_pos = best_display(&risc_rect); } SDL_Window *window = SDL_CreateWindow("Project Oberon", window_pos, window_pos, risc_rect.w, risc_rect.h, window_flags); sdl_error_if(window == NULL, "Could not create window"); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0); sdl_error_if(renderer == NULL, "Could not create renderer"); SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, risc_rect.w, risc_rect.h); sdl_error_if(texture == NULL, "Could not create texture"); SDL_Rect display_rect; double display_scale = scale_display(window, &risc_rect, &display_rect); update_texture(risc, texture, &risc_rect); SDL_ShowWindow(window); SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, &risc_rect, &display_rect); SDL_RenderPresent(renderer); bool done = false; bool mouse_was_offscreen = false; while (!done) { uint32_t frame_start = SDL_GetTicks(); SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: { done = true; } case SDL_WINDOWEVENT: { if (event.window.event == SDL_WINDOWEVENT_RESIZED) { display_scale = scale_display(window, &risc_rect, &display_rect); } break; } case SDL_MOUSEMOTION: { int scaled_x = (int)round((event.motion.x - display_rect.x) / display_scale); int scaled_y = (int)round((event.motion.y - display_rect.y) / display_scale); int x = clamp(scaled_x, 0, risc_rect.w - 1); int y = clamp(scaled_y, 0, risc_rect.h - 1); bool mouse_is_offscreen = x != scaled_x || y != scaled_y; if (mouse_is_offscreen != mouse_was_offscreen) { SDL_ShowCursor(mouse_is_offscreen); mouse_was_offscreen = mouse_is_offscreen; } risc_mouse_moved(risc, x, risc_rect.h - y - 1); break; } case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { bool down = event.button.state == SDL_PRESSED; risc_mouse_button(risc, event.button.button, down); break; } case SDL_KEYDOWN: case SDL_KEYUP: { bool down = event.key.state == SDL_PRESSED; SDL_Keysym k = event.key.keysym; if (k.sym == SDLK_F12) { // F12 = Oberon reset if (down) { risc_reset(risc); } } else if (k.sym == SDLK_F11 || (k.sym == SDLK_f && (k.mod & KMOD_GUI) && (k.mod & KMOD_SHIFT))) { // F11 / Cmd-Shift-F = Toggle fullscreen if (down) { fullscreen ^= true; if (fullscreen) { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } else { SDL_SetWindowFullscreen(window, 0); } } } else if (k.sym == SDLK_F4 && (k.mod & KMOD_ALT)) { // Alt-F4 = quit (for when we're running without windowing system) if (down) { SDL_PushEvent(&(SDL_Event){ .type=SDL_QUIT }); } } else if (k.sym == SDLK_LALT) { // Emulate middle button risc_mouse_button(risc, 2, down); } else { // Pass other keys to Oberon uint8_t scancode[MAX_PS2_CODE_LEN]; int len = ps2_encode(k.scancode, down, scancode); risc_keyboard_input(risc, scancode, len); } break; } } }