/* Time the blend area function */ void bench_blend(int n) { epx_pixmap_t* a; epx_pixmap_t* b; int i, j; double tfsum = 0.0; /* Bench mark blending function */ a = epx_pixmap_create(640, 480, EPX_FORMAT_ARGB); b = epx_pixmap_create(640, 480, EPX_FORMAT_ARGB); for (j = 0; j < n; j++) { struct timeval t, t0, t1; double tf; gettimeofday(&t0, NULL); for (i = 0; i < 100; i++) { epx_pixmap_copy_area(a, b, 0, 0, 0, 0, 640, 480, EPX_FLAG_BLEND); } gettimeofday(&t1, NULL); timersub(&t1, &t0, &t); tf = 100.0/(t.tv_sec+(t.tv_usec/1000000.0)); // printf("BLEND: %f/s\n", tf); tfsum += tf; } printf("BLEND Avg: %f/s\n", tfsum/n); }
void bench_line(int n) { epx_pixmap_t* a; epx_gc_t* gc; int x0 = 0, x1 = 639; int y0, y1; int i; double tfsum = 0.0; gc = epx_gc_create(); a = epx_pixmap_create(640, 480, EPX_FORMAT_ARGB); epx_gc_set_line_style(gc, EPX_FILL_STYLE_BLEND); epx_gc_set_foreground_color(gc, epx_pixel_argb(127,100,200,150)); for (i = 0; i < n; i++) { struct timeval t, t0, t1; double tf; gettimeofday(&t0, NULL); for (y0 = 0; y0 < 480; y0++) { y1 = 439-y0; epx_pixmap_draw_line(a, gc, x0, y0, x1, y1); } gettimeofday(&t1, NULL); timersub(&t1, &t0, &t); tf = 480.0/(t.tv_sec+(t.tv_usec/1000000.0)); tfsum += tf; } printf("LINE Avg: %f/s\n", tfsum/n); }
/* Time the blend fill area function */ void bench_blend_fill(int n) { epx_pixmap_t* a; epx_gc_t* gc; int i, j; double tfsum = 0.0; /* Bench mark blending function */ gc = epx_gc_create(); a = epx_pixmap_create(640, 480, EPX_FORMAT_ARGB); epx_gc_set_fill_style(gc, EPX_FILL_STYLE_BLEND); epx_gc_set_border_width(gc, 0); epx_gc_set_fill_color(gc, epx_pixel_argb(127,100,200,150)); for (j = 0; j < n; j++) { struct timeval t, t0, t1; double tf; gettimeofday(&t0, NULL); for (i = 0; i < 100; i++) { epx_pixmap_draw_rectangle(a, gc, 0, 0, 640, 480); } gettimeofday(&t1, NULL); timersub(&t1, &t0, &t); tf = 100.0/(t.tv_sec+(t.tv_usec/1000000.0)); tfsum += tf; } printf("BFILL: Avg: %f/s\n", tfsum/n); }
void bench_plot1(int n, epx_pixel_t (*src_unpack)(u_int8_t*), void (*dst_pack)(epx_pixel_t, u_int8_t*)) { epx_pixmap_t* a; epx_gc_t* gc; int j; double tfsum = 0.0; u_int8_t* src_ptr; unsigned int bytesPerRow; unsigned int bytesPerPixel; int x, y; /* Bench mark fill function */ gc = epx_gc_create(); a = epx_pixmap_create(640, 480, EPX_FORMAT_ARGB); epx_gc_set_fill_style(gc, EPX_FILL_STYLE_SOLID); epx_gc_set_border_width(gc, 0); epx_gc_set_fill_color(gc, epx_pixel_red); bytesPerRow = a->bytes_per_row; bytesPerPixel = a->bytes_per_pixel; for (j = 0; j < n; j++) { struct timeval t, t0, t1; double tf; gettimeofday(&t0, NULL); src_ptr = EPX_PIXEL_ADDR(a, 0, 0); for (y = 0; y < 480; y++) { u_int8_t* src1 = src_ptr; for (x = 0; x < 640; x++) { epx_pixel_t p; p = src_unpack(src1); p.a = 100; p.r = 1; p.g = 1; p.b = 1; dst_pack(p, src1); src1 += bytesPerPixel; } src_ptr += bytesPerRow; } gettimeofday(&t1, NULL); timersub(&t1, &t0, &t); tf = 100.0/(t.tv_sec+(t.tv_usec/1000000.0)); tfsum += tf; } printf("PLOT1 Avg: %f/s\n", tfsum/n); }
// // useAlpha=false make alpha channel opaque // useAlpha=true use alpha value as is // useClient=true make use of client stored data, assume texture data // survive the rendering phase. // wrap=GL_CLAMP, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, // GL_REPEAT or GL_MIRRORED_REPEAT // // Load textures formats: // 1 - ARB_texture_non_power_of_two // 2 - ARB_texture_rectangle (used if non normalized is request) // 3 - GL_TEXTURE_2D (possibly scaled otherwise) // // int epx_gl_load_texture(epx_pixmap_t* pic, GLuint* textureName, int useAlpha, int useClient, GLuint wrap, int src_x, int src_y, unsigned int width,unsigned int height) { GLint tx_iformat; GLenum tx_format; GLenum tx_type; float saveScale; float saveBias; GLenum target; int normalized = 1; epx_pixmap_t* pic2 = NULL; switch(pic->pixel_format) { case EPX_FORMAT_R8G8B8: tx_iformat = GL_RGB8; tx_format = GL_RGB; tx_type = GL_UNSIGNED_BYTE; break; case EPX_FORMAT_565_BE: tx_iformat = GL_RGB5; tx_format = GL_RGB; #if BYTE_ORDER == BIG_ENDIAN tx_type = GL_UNSIGNED_SHORT_5_6_5; #else tx_type = GL_UNSIGNED_SHORT_5_6_5_REV; #endif break; case EPX_FORMAT_565_LE: tx_iformat = GL_RGB5; tx_format = GL_RGB; #if BYTE_ORDER == BIG_ENDIAN tx_type = GL_UNSIGNED_SHORT_5_6_5_REV; #else tx_type = GL_UNSIGNED_SHORT_5_6_5; #endif break; case EPX_FORMAT_B8G8R8: tx_iformat = GL_RGB8; tx_format = GL_BGR; tx_type = GL_UNSIGNED_BYTE; break; case EPX_FORMAT_A8R8G8B8: tx_iformat = GL_RGBA8; tx_format = GL_BGRA_EXT; #if BYTE_ORDER == BIG_ENDIAN tx_type = GL_UNSIGNED_INT_8_8_8_8_REV; #else tx_type = GL_UNSIGNED_INT_8_8_8_8; #endif break; case EPX_FORMAT_R8G8B8A8: tx_iformat = GL_RGBA8; tx_format = GL_RGBA; #if BYTE_ORDER == BIG_ENDIAN tx_type = GL_UNSIGNED_INT_8_8_8_8; #else tx_type = GL_UNSIGNED_INT_8_8_8_8_REV; #endif break; case EPX_FORMAT_B8G8R8A8: tx_iformat = GL_RGBA8; tx_format = GL_BGRA; #if BYTE_ORDER == BIG_ENDIAN tx_type = GL_UNSIGNED_INT_8_8_8_8; #else tx_type = GL_UNSIGNED_INT_8_8_8_8_REV; #endif break; default: return -1; // Better error code? } if (*textureName == 0) glGenTextures(1, textureName); /* FIXME check extensions better */ if (normalized) { #ifndef GL_ARB_texture_non_power_of_two unsigned int width2 = nearest_pow2(width); unsigned int height2 = nearest_pow2(height); printf("POT: width2=%d, height2=%d\n", width2, height2); if ((width2==0) || (height2==0)) return -1; if ((width2 != width) || (height2 != height)) { epx_pixmap_t* pic2 = epx_pixmap_create(width2, height2, pic->pixel_format); printf("POT: scale image\n"); gluScaleImage(tx_format, width, height, tx_type, EPX_PIXEL_ADDR(pic,src_x,src_y), width2, height2, tx_type, EPX_PIXEL_ADDR(pic2,0,0)); width = width2; height = height2; pic = pic2; } #endif target = GL_TEXTURE_2D; } else { #ifdef GL_ARB_texture_rectangle target = GL_TEXTURE_RECTANGLE_ARB; #endif } glBindTexture (target, *textureName); glTexParameteri(target,GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(target,GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(target,GL_TEXTURE_WRAP_S, wrap); glTexParameteri(target,GL_TEXTURE_WRAP_T, wrap); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glPixelStorei (GL_UNPACK_ROW_LENGTH, pic->bytes_per_row/pic->bytes_per_pixel); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); #ifdef GL_UNPACK_CLIENT_STORAGE_APPLE if (useClient) // This speeds processing up from 40-50 => 50-60 fps :-) // BUT WE MUST PRESERVE THE PIXELS until next reload!!!!!! // this is what useClient is for glPixelStorei (GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); #endif if (!useAlpha) { // Do not use possibly bad alpha value glGetFloatv(GL_ALPHA_SCALE, &saveScale); glGetFloatv(GL_ALPHA_BIAS, &saveBias); glPixelTransferf(GL_ALPHA_SCALE, 0.0); glPixelTransferf(GL_ALPHA_BIAS, 1.0); } // FIXME Update with: // glTexSubImage2D(target, 0, 0, 0, width, height, tx_format, tx_type, // EPIXEL_ADDR(pic, src_x, src_y)) // but only if width & height is same as original texture glTexImage2D (target, 0, tx_iformat, width, height, 0, tx_format, tx_type, EPX_PIXEL_ADDR(pic, src_x, src_y)); if (!useAlpha) { // Reset saved values glPixelTransferf(GL_ALPHA_SCALE, saveScale); glPixelTransferf(GL_ALPHA_BIAS, saveBias); } if (pic2) epx_pixmap_destroy(pic2); return 0; }