I am looking for some sample program which can render and dispaly "2k x 2k 2D image " in less then 25 msec .
If any one has idea let me know
Hey,
I presume that what you want to display is a 32-bit image (RGBA or BGRA), and that you can spend all of those 25ms on actually displaying the image i.e. the image data is ready to be submitted to the gfx card.
I have used PBOs (Pixel Buffer Objects) to stream textures of 1024x1024 to the gfx card which on my system takes around 4…5ms. Please have a look at my post, http://www.java-gaming.org/forums/index.php?topic=11873.0. From there you can get to the source code. The timings should scale linearly with the number of pixels to send, i.e. I expect around 16…20ms for your problem size. You may also want to read http://oss.sgi.com/projects/ogl-sample/registry/ARB/pixel_buffer_object.txt.
FYI, my system specs: AMD Athlon 4200X2, Asus A8N SLI Premium, PixelView GeForce 7800GT, 2GB DDR.
Hope this helps,
Matt.
PS: Unless you really need to go OpenGL, you can nowadays get equally fast image updates using java2d…
- You said “Unless you really need to go OpenGL, you can nowadays get equally fast image updates using java2d…”
Pls can you tell me how to achive this using only java2d no openGL ?
- I am new to this jogl .How to give input bufferedImage to your program GLEventHandler.java ?Do you have any main program using GLEventHandler.java which will load the given BufferedImag
On 1.5.0_06 I can draw a 1024x1024 BufferedImage with a simple Graphics.drawImage() in just about 3ms. Admittedly, the image is TYPE_BYTE_INDEXED
and not RGBA
. It may be worth you timing the latter before you look any further into OpenGL. Speaking from my own experience, java2d is really slow at doing alpha blending though, so if you need that then you do want to use OpenGL instead.
This depends on how you have your BufferedImage set up. Ideal under Win32 is a BufferedImage of type TYPE_INT_BGR
(because this is also the native surface format). Assuming this is your image format, here’s what you might want to do inside your display() method:
// the image you want to show on the screen
BufferedImage image = getImage();
// access the image data...
Raster raster = image.getRaster();
DataBufferInt imageDataBuffer = (DataBufferInt) raster.getDataBuffer(); // safe cast as we know what type of image we're dealing with!
int[] imageDataArray = imageDataBuffer.getData();
final int width = image.getWidth();
final int height = image.getHeight();
// assuming you have created a texture with a given textureID (and bound that texture), the next line of code updates its image data
gl.glTexSubImage2D( GL.GL_TEXTURE_2D, 0, 0, 0, width, height, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, IntBuffer.wrap( imageDataArray ) );
// TODO add some OpenGL to draw a textured GL_QUAD...
Note: This is probably not the most efficient way of doing things. In particular, I’m not certain how well the buffer wrapping the int[] would perform. Also, instead of specifying a buffer as the last argument to glTexSubImage2D(), you could use the Pixel Buffer Object extension (GL_ARB_pixel_buffer_object, or maybe GL_EXT_pixel_buffer_object) which achieves better performance. Look at the code example I attached to my other post, or the link I posted above.
Ok Thx Lot .
I am looking for some main Java progarm which will use GLEventHandler.java and show the image do you have any main program ?pls can you send me the link or code .
Hey,
Please find attached a Java source file ‘GLEventHandler.java’ which demonstrates exactly what you’re after (I hope). It looks a bit involved maybe, but that’s only because I didn’t care to clean it up a bit. Anyway things to look out for:
- lines 27-28 define the (static) texture dimensions; these must be a power of two each; if your image dimension is not a power of two then you need to do some tiling
- line 64 establishes whether the Pixel Buffer Extension is available
- line 140 sets up a BufferedImage of the texture dimensions, of type TYPE_4BYTE_ABGR. Note there is a problem with this (and the subsequent code) in that the colour channels are the wrong way round, and what you really want is TYPE_4BYTE_BGRA to match the texture format; unfortunately there is no such BI format so you’d have to do some byte swapping which is going to add some 5ms in native code
- lines 141-172 initialises the BI with some random content
- line 213 is where your BI is streamed into texture memory, using the PBO extension
- line 236 is the (slower) alternative where your BI image content is wrapped in a buffer and copied into texture memory
- lines 248-257 draws a simple quad, mapping your texture appropriately
I have also attached the other classes you need (Messages, StreamingTextures; the latter contains your main() method). Hope this gives you a starting point.
Oh before I forget, the code does some timing for you. On my system I get around 18…19ms for PBO-streaming a 2048x2048 BufferedImage! Even with the traditional non-PBO approach I get a respectable 28ms. (Ken: in case you were following this conversation, this example is running on a single screen; if I enable the second display then the PBO performance really sucks!).
Thx Lot. But i am facing one problem
In Java 2d I created following BufferedImage …
BufferedImage[] bi = BufferedImage.TYPE_4BYTE_ABGR;
DataBufferByte dbb = (DataBufferByte ) bi[i].getRaster().getDataBuffer();
byte[] data = dbb.getData();
// TYPE_4BYTE_ABGR
byte max = (byte) 0xff;
for (int i = 0; i < w; i++)
for (int j = 0; j < h; j++)
if (j % 40 < 20)
{
int basePixel = (i * w + j) * 4;
d[basePixel] = (byte)0xff;
d[basePixel + 1] = max;
d[basePixel + 2] = max;
d[basePixel + 2] =max;
}
It shows the vertical bars with alternate one black .Attached Doc.
Same thing I added in your GLEventHandler.java program
byte max = (byte) 0xff;
for (int i = 0; i < w; i++)
for (int j = 0; j < h; j++)
if (j % 40 < 20)
{
int basePixel = (i * w + j) * 4;
//OpenGL
d[basePixel] = max ;
d[basePixel + 1] = max;
d[basePixel + 2] = max;
d[basePixel + 2] =(byte)0xff;
}
It shows some bad pattern image(it is not same as in java) , Can u suggest what’s wrong.
I am excepting the same pattern as in JAVA 2D.
Can you send us the display you get with OpenGL please, a simple screen capture should work.
Attached is the OpenGL pattern
Hey, I’m not sure what the problem is with your code. Having just added your image initialisation to my code, it shows the vertical stripes just fine (except they are b/w not coloured as in your first screenshot). I assume there is a problem with the way you set up and update the texture.
Have you actually tried running my code as-is?
Attached is the modified GLEventHandler.txt file .
Pls can you tell me what i am doing wrong .
grep for images=genImages(5,2022) in attached file .
Also pls can you send me the screen capture of your display .
Thx
OK I haven’t tried to run your code but there is an obvious problem in that your image dimensions don’t match the texture dimensions. Texture dimensions are specified as 2048x2048 whereas your image is set to 2022x2022 (line 166):
images=genImages(5,2022);
image=images[0];
This means that row 2 of your image starts on row 1 of the texture, around 26 pixels from the end, row 3 starts on row 2 of the texture 52 pixels from the end and so on, leading to the rendered image you’ve shown. You have two options, either change your image dimensions to match the texture dimensions, or specify the unpack row length parameter [1] via gl.glPixelStore( GL.GL_UNPACK_ROW_LENGTH, 2022 )
(although I’m not actually certain this will work; it definitely works for images that are larger than your texture). If you change this parameter in your display() method then be sure to reset it to its original value when you’re done, otherwise you might crash the JVM.
Hope this helps!
Matt.
[1] http://www.rush3d.com/reference/opengl-bluebook-1.0/ch05.html#id5514324
Thx Lot ! It is working fine .
When run it on my Linux Machine it show following out put …
The Output shows
width 2048
hiegth 2048
GLEventHandler.init(): GL_VERSION = 1.5.2 NVIDIA 66.34
GLEventHandler.init(): GL_VENDOR = NVIDIA Corporation
GLEventHandler.init(): GL_RENDERER = Quadro NVS/AGP/SSE2
GLEventHandler.init(): streaming texture image using PBO
GLEventHandler.12725.5GLEventHandler.2
GLEventHandler.14159.0GLEventHandler.2
GLEventHandler.13535.0GLEventHandler.2
GLEventHandler.12135.0GLEventHandler.2
These are in msec right?
Just want to know any thing extra I have to do so that I will get 25 ms second to render and display the 2048 x 2048 Buffered image?
My Machine glxInfo :
name of display: :0.0
display: :0 screen: 0
direct rendering: Yes
server glx vendor string: NVIDIA Corporation
server glx version string: 1.3
server glx extensions:
GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_SGIX_fbconfig,
GLX_SGIX_pbuffer, GLX_SGI_video_sync, GLX_SGI_swap_control
client glx vendor string: NVIDIA Corporation
client glx version string: 1.3
client glx extensions:
GLX_ARB_get_proc_address, GLX_ARB_multisample, GLX_EXT_visual_info,
GLX_EXT_visual_rating, GLX_EXT_import_context, GLX_SGI_video_sync,
GLX_NV_swap_group, GLX_NV_video_out, GLX_SGIX_fbconfig, GLX_SGIX_pbuffer,
GLX_SGI_swap_control, GLX_NV_float_buffer
GLX extensions:
GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_SGIX_fbconfig,
GLX_SGIX_pbuffer, GLX_SGI_video_sync, GLX_SGI_swap_control,
GLX_ARB_get_proc_address
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: Quadro NVS/AGP/SSE2
OpenGL version string: 1.5.2 NVIDIA 66.34
OpenGL extensions:
GL_ARB_imaging, GL_ARB_multitexture, GL_ARB_point_parameters,
GL_ARB_point_sprite, GL_ARB_shader_objects, GL_ARB_shading_language_100,
GL_ARB_texture_compression, GL_ARB_texture_cube_map,
GL_ARB_texture_env_add, GL_ARB_texture_env_combine,
GL_ARB_texture_env_dot3, GL_ARB_texture_mirrored_repeat,
GL_ARB_texture_rectangle, GL_ARB_transpose_matrix,
GL_ARB_vertex_buffer_object, GL_ARB_vertex_program, GL_ARB_vertex_shader,
GL_ARB_window_pos, GL_S3_s3tc, GL_EXT_texture_env_add, GL_EXT_abgr,
GL_EXT_bgra, GL_EXT_blend_color, GL_EXT_blend_minmax,
GL_EXT_blend_subtract, GL_EXT_clip_volume_hint,
GL_EXT_compiled_vertex_array, GL_EXT_Cg_shader,
GL_EXT_draw_range_elements, GL_EXT_fog_coord, GL_EXT_multi_draw_arrays,
GL_EXT_packed_pixels, GL_EXT_paletted_texture, GL_EXT_pixel_buffer_object,
GL_EXT_point_parameters, GL_EXT_rescale_normal, GL_EXT_secondary_color,
GL_EXT_separate_specular_color, GL_EXT_shared_texture_palette,
GL_EXT_stencil_wrap, GL_EXT_texture_compression_s3tc,
GL_EXT_texture_cube_map, GL_EXT_texture_edge_clamp,
GL_EXT_texture_env_combine, GL_EXT_texture_env_dot3,
GL_EXT_texture_filter_anisotropic, GL_EXT_texture_lod,
GL_EXT_texture_lod_bias, GL_EXT_texture_object, GL_EXT_vertex_array,
GL_IBM_rasterpos_clip, GL_IBM_texture_mirrored_repeat,
GL_KTX_buffer_region, GL_NV_blend_square, GL_NV_fence,
GL_NV_fog_distance, GL_NV_light_max_exponent, GL_NV_packed_depth_stencil,
GL_NV_pixel_data_range, GL_NV_point_sprite, GL_NV_register_combiners,
GL_NV_texgen_reflection, GL_NV_texture_env_combine4,
GL_NV_texture_rectangle, GL_NV_vertex_array_range,
GL_NV_vertex_array_range2, GL_NV_vertex_program, GL_NV_vertex_program1_1,
GL_SGIS_generate_mipmap, GL_SGIS_multitexture, GL_SGIS_texture_lod,
GL_SUN_slice_accum
glu version: 1.3
glu extensions:
GLU_EXT_nurbs_tessellator, GLU_EXT_object_space_tess
visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav
id dep cl sp sz l ci b ro r g b a bf th cl r g b a ns b eat
0x21 24 tc 0 32 0 r y . 8 8 8 0 4 24 8 16 16 16 16 0 0 None
0x22 24 dc 0 32 0 r y . 8 8 8 0 4 24 8 16 16 16 16 0 0 None
0x23 24 tc 0 32 0 r y . 8 8 8 8 4 24 8 16 16 16 16 0 0 None
0x24 24 tc 0 32 0 r . . 8 8 8 0 4 24 8 16 16 16 16 0 0 None
0x25 24 tc 0 32 0 r . . 8 8 8 8 4 24 8 16 16 16 16 0 0 None
0x26 24 tc 0 32 0 r y . 8 8 8 0 4 16 0 16 16 16 16 0 0 None
0x27 24 tc 0 32 0 r y . 8 8 8 8 4 16 0 16 16 16 16 0 0 None
0x28 24 tc 0 32 0 r . . 8 8 8 0 4 16 0 16 16 16 16 0 0 None
0x29 24 tc 0 32 0 r . . 8 8 8 8 4 16 0 16 16 16 16 0 0 None
0x2a 24 tc 0 32 0 r y . 8 8 8 0 4 0 0 16 16 16 16 0 0 None
0x2b 24 tc 0 32 0 r y . 8 8 8 8 4 0 0 16 16 16 16 0 0 None
0x2c 24 tc 0 32 0 r . . 8 8 8 0 4 0 0 16 16 16 16 0 0 None
0x2d 24 tc 0 32 0 r . . 8 8 8 8 4 0 0 16 16 16 16 0 0 None
0x2e 24 dc 0 32 0 r y . 8 8 8 8 4 24 8 16 16 16 16 0 0 None
0x2f 24 dc 0 32 0 r . . 8 8 8 0 4 24 8 16 16 16 16 0 0 None
0x30 24 dc 0 32 0 r . . 8 8 8 8 4 24 8 16 16 16 16 0 0 None
0x31 24 dc 0 32 0 r y . 8 8 8 0 4 16 0 16 16 16 16 0 0 None
0x32 24 dc 0 32 0 r y . 8 8 8 8 4 16 0 16 16 16 16 0 0 None
0x33 24 dc 0 32 0 r . . 8 8 8 0 4 16 0 16 16 16 16 0 0 None
0x34 24 dc 0 32 0 r . . 8 8 8 8 4 16 0 16 16 16 16 0 0 None
0x35 24 dc 0 32 0 r y . 8 8 8 0 4 0 0 16 16 16 16 0 0 None
0x36 24 dc 0 32 0 r y . 8 8 8 8 4 0 0 16 16 16 16 0 0 None
0x37 24 dc 0 32 0 r . . 8 8 8 0 4 0 0 16 16 16 16 0 0 None
0x38 24 dc 0 32 0 r . . 8 8 8 8 4 0 0 16 16 16 16 0 0 None
You should have said you’re running on Linux. In this case your texture format probably wants to be GL_RGBA
instead of GL_BGRA
, you need to play with it. Also I notice your Linux driver is quite old (66.34) I recommend you upgrade to the latest WHQL driver for Quadro boards which I think is 81.56 or something (check out at their web site). In any case you will need a pretty recent Quadro to achieve 25ms. I tried it under Windows on a 980XGL (ca 3 years old) and I get around 32ms. Also before I had upgraded the drivers, I was running some 71.x drivers and the performance was a lot worse. Another thing to check is what performance you get with non-PBO texture updates.
Hi
Planing to buy following card on Linux .
Quadro FX 4500 Memory Size
Memory Interface
Graphics Memory Bandwidth
Graphics Bus 512MB
256-bit
33.6GB/sec.
PCI Express
Pls let me know if some one already using this card ,which will enable to get good performance for PBO .
Hi Mabraham /Ken
OS: LINUX
With PBO and GL_BGRA_
width 2048
hiegth 2048
GLEventHandler.init(): GL_VERSION = 1.5.2 NVIDIA 66.34
GLEventHandler.init(): GL_VENDOR = NVIDIA Corporation
GLEventHandler.init(): GL_RENDERER = Quadro NVS/AGP/SSE2
usePBO true
GLEventHandler.init(): streaming texture image using PBO
GLEventHandler.159.64706GLEventHandler.2
GLEventHandler.161.588234GLEventHandler.2
GLEventHandler.161.764706GLEventHandler.2
GLEventHandler.161.82353GLEventHandler.2
GLEventHandler.162.117645GLEventHandler.2
GLEventHandler.162.117645GLEventHandler.2
GLEventHandler.162.35294GLEventHandler.2
GLEventHandler.162.8125GLEventHandler.2
NO PBO and GL_BGRA_
width 2048
hiegth 2048
GLEventHandler.init(): GL_VERSION = 1.5.2 NVIDIA 66.34
GLEventHandler.init(): GL_VENDOR = NVIDIA Corporation
GLEventHandler.init(): GL_RENDERER = Quadro NVS/AGP/SSE2
usePBO false
GLEventHandler.init(): updating texture image using glTexSubImage2D()
GLEventHandler.154.94737GLEventHandler.2
GLEventHandler.151.6GLEventHandler.2
GLEventHandler.151.7GLEventHandler.2
GLEventHandler.153.473682GLEventHandler.2
GLEventHandler.157.72222GLEventHandler.2
GLEventHandler.158.11111GLEventHandler.2
WITH PBO and GL_RGBA
width 2048
hiegth 2048
GLEventHandler.init(): GL_VERSION = 1.5.2 NVIDIA 66.34
GLEventHandler.init(): GL_VENDOR = NVIDIA Corporation
GLEventHandler.init(): GL_RENDERER = Quadro NVS/AGP/SSE2
usePBO true
GLEventHandler.init(): streaming texture image using PBO
GLEventHandler.1506.0GLEventHandler.2
GLEventHandler.1884.0GLEventHandler.2
GLEventHandler.1882.5GLEventHandler.2
GLEventHandler.1887.5GLEventHandler.2
GLEventHandler.1877.5GLEventHandler.2
GLEventHandler.1885.0GLEventHandler.2
NO PBO and GL_RGBA
width 2048
hiegth 2048
GLEventHandler.init(): GL_VERSION = 1.5.2 NVIDIA 66.34
GLEventHandler.init(): GL_VENDOR = NVIDIA Corporation
GLEventHandler.init(): GL_RENDERER = Quadro NVS/AGP/SSE2
usePBO false
GLEventHandler.init(): updating texture image using glTexSubImage2D()
GLEventHandler.155.31579GLEventHandler.2
GLEventHandler.151.5GLEventHandler.2
GLEventHandler.151.25GLEventHandler.2
GLEventHandler.151.25GLEventHandler.2
GLEventHandler.151.85GLEventHandler.2
GLEventHandler.152.05GLEventHandler.2
GLEventHandler.151.95GLEventHandler.2
One more thing is On my LINUX machine gl.isExtensionAvailable( “GL_ARB_pixel_buffer_object” ) false
And gl.isExtensionAvailable( “GL_EXT_pixel_buffer_object” ) true
Is this makes any difference in performance
Or only option left move to new GPU card.
pls let me know .
Thanks
Hi,
That card should be very fast. I obviously can’t promise anything as I don’t own such an expensive thing. I reckon my 7800GT is somewhat slower than the Quadro 4500, and it manages to stream 2048x2048 textures at 16ms. It all depends on your setup however, as Ken and I have pointed out please do update your drivers. The latest Quadro WHQL drivers are 81.67 and they boost PBO performance a lot, compared to any older drivers.
On a side note, GL_EXT_pixel_buffer_object or GL_ARB_pixel_buffer_object should make no difference (I believe the code checks for the presence of either).
One more thing regarding performance: obviously streaming textures involves a read from system memory. That may be the bottleneck, what RAM subsystem do you use. Maybe you could post details of your system spec here…
Hi Mabraham /Ken
I upgraded my driver to NVIDIA 81.78.But still i performance are in 3 digit .
Here the Linux Machine Details and new readings on 81.78
Machine Info :
Linux 2.6.9-1.667smp #1 SMP Tue Nov 2 14:59:52 EST 2004 i686 i686 i386 G NU/Linux
2GB RAM
4GB SWAP
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: Quadro4 980 XGL/AGP/SSE2
OpenGL version string: 1.5.5 NVIDIA 81.78
MemoryInfo :
MemTotal: 2072312 kB
MemFree: 159148 kB
Buffers: 215724 kB
Cached: 1095700 kB
SwapCached: 16 kB
Active: 673636 kB
Inactive: 759548 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 2072312 kB
LowFree: 159148 kB
SwapTotal: 4152792 kB
SwapFree: 4152652 kB
Dirty: 4 kB
Writeback: 0 kB
Mapped: 161044 kB
Slab: 456672 kB
Committed_AS: 421160 kB
PageTables: 3824 kB
VmallocTotal: 2039800 kB
VmallocUsed: 26804 kB
VmallocChunk: 2008052 kB
HugePages_Total: 0
HugePages_Free: 0
Hugepagesize: 2048 kB
CPU INFO :
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel® Xeon™ CPU 2.66GHz
stepping : 9
cpu MHz : 2659.140
cache size : 512 KB
physical id : 0
siblings : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid xtpr
bogomips : 5242.88
processor : 1
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel® Xeon™ CPU 2.66GHz
stepping : 9
cpu MHz : 2659.140
cache size : 512 KB
physical id : 0
siblings : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid xtpr
WITH PBO :
width 2048
hiegth 2048
GLEventHandler.init(): GL_VERSION = 1.5.5 NVIDIA 81.78
GLEventHandler.init(): GL_VENDOR = NVIDIA Corporation
GLEventHandler.init(): GL_RENDERER = Quadro4 980 XGL/AGP/SSE2
ARB true
EXT true
usePBO true
GLEventHandler.init(): streaming texture image using PBO
GLEventHandler.135.75GLEventHandler.2
GLEventHandler.125.375GLEventHandler.2
GLEventHandler.125.425GLEventHandler.2
GLEventHandler.126.02564GLEventHandler.2
GLEventHandler.125.425GLEventHandler.2
GLEventHandler.125.375GLEventHandler.2
NO PBO:
width 2048
hiegth 2048
GLEventHandler.init(): GL_VERSION = 1.5.5 NVIDIA 81.78
GLEventHandler.init(): GL_VENDOR = NVIDIA Corporation
GLEventHandler.init(): GL_RENDERER = Quadro4 980 XGL/AGP/SSE2
ARB true
EXT true
usePBO false
GLEventHandler.init(): updating texture image using glTexSubImage2D()
GLEventHandler.159.411766GLEventHandler.2
GLEventHandler.145.260868GLEventHandler.2
GLEventHandler.145.04348GLEventHandler.2
GLEventHandler.145.086956GLEventHandler.2
GLEventHandler.145.391304GLEventHandler.2
GLEventHandler.145.954544GLEventHandler.2
and java version jdk-1_5_0_06-linux-i586 --Xmx512m and do i have to pass any extra VM parameters ?
Pls Can you suggest what else i can do to get good peformance .