This discussion is archived
3 Replies Latest reply: Aug 31, 2010 5:14 AM by gimbal2 RSS

Do you have any ideas how to optimize this JOGL code with drawPixels func?

843853 Newbie
Currently Being Moderated
I'm writing a video player. My video engine uses OpenGL to renderer frames with glDrawPixels function. As I don't have a lot of experience with OpenGL I'd like you to list me your ideas how to improve performance of code attached below. The process function is invoked when video rendering is required.

ps. I've heard that it's the best to avoid using gdDrawPixels and use textures instead. But in my case, is it possible to use textures with frequently changing textures?
@Override
    public int process(Buffer buffer) {
        if(buffer.getLength() <=0  || !videoCanvas.isShowing())
            return BUFFER_PROCESSED_OK;

        RGBFormat f= (RGBFormat) buffer.getFormat();

        data= buffer;
        dataFormat= (RGBFormat)buffer.getFormat();

        paintDelay= new Date().getTime();



        videoThreadPool.submit(new Runnable(){

            @Override
            public void run() {
                ((GLCanvas)videoCanvas).display();
            }


        });

        return BUFFER_PROCESSED_OK;
    }


    @Override
    public void init(GLAutoDrawable drawable) {
         GL gl = drawable.getGL();

         gl.glDisable(GL.GL_ALPHA_TEST | GL.GL_BLEND | GL.GL_DEPTH_TEST | GL.GL_FOG | GL.GL_LIGHTING |GL.GL_STENCIL_TEST | GL.GL_SCISSOR_TEST | GL.GL_DITHER);

    }

    @Override
    public void display(GLAutoDrawable drawable) {

        if(data== null)
            return;


        int ih= (int)dataFormat.getSize().getHeight();
        int iw= (int)dataFormat.getSize().getWidth();


        GL gl = drawable.getGL();

        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        
        gl.glRasterPos2d(0, vpBounds.height-1);
        gl.glDrawPixels(iw, ih, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, IntBuffer.wrap((int[])data.getData()));

      
        //gl.glFlush();
        drawable.swapBuffers();

    }

 @Override
    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        float scaleRate= (float)width/(float)formatDim.getWidth();
        int iheight= (int)(formatDim.getHeight() * scaleRate);

        int iy= (height - iheight)/2;

        if(iy<0)
            iy=0;

        vpBounds= new Rectangle(0, iy, width, iheight);

         GL gl = drawable.getGL();
         GLU glu= new GLU();
         gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
         gl.glMatrixMode(GL.GL_PROJECTION);
         gl.glLoadIdentity();
         gl.glViewport(0, 0, (int)vpBounds.getWidth(), (int)vpBounds.getHeight());
         glu.gluOrtho2D(0.0f, vpBounds.getWidth(), 0.0f, (int)vpBounds.getHeight());
         gl.glPixelStorei(GL.GL_PACK_SWAP_BYTES, 4);

         gl.glPixelZoom((float)((float)vpBounds.getWidth()/formatDim.getWidth()),(float)((float)-vpBounds.getHeight()/formatDim.getHeight()));
    }
  • 1. Re: Do you have any ideas how to optimize this JOGL code with drawPixels func?
    gimbal2 Guru
    Currently Being Moderated
    There are two mistakes in your post.

    1) you want to improve performance. Why? Is the application not working properly? You don't make any mention of that.
    2) You list your main problem as having not enough experience and you use that as an excuse to make other people do the work for you.

    The latter is just the biggest mistake you can make and you are risking taking two of the biggest joys away from yourself: the learning process and that "yeehaw!" moment when you fix it all by yourself.

    Go figure it out dude! And have fun doing it!
  • 2. Re: Do you have any ideas how to optimize this JOGL code with drawPixels func?
    843853 Newbie
    Currently Being Moderated
    ohhh man. You are wasting your time writing posts like that.

    The code I showed above works, but its performance is not sufficient for me. I'm fighting with this issue about one month. Some day I've come up with an idea to ask society of this forum if they can see sth in my code that could be written in a better way. That's all. I'm not asking: "hey guys . Please write me ready application." Your post made me angry.

    PLEASE don't write anything if you have nothing to say in the topic of my first post. It's not a chat !!!!!!

    Edited by: cartoon_20 on Aug 30, 2010 10:58 AM
    Sorry maybe I took your post too emotionally. With the second read I figured out that you haven't had any bad intention. I've stopped with my application at this point. I've written video renderer. It's time to write sound renderer. Here are details:
    link
  • 3. Re: Do you have any ideas how to optimize this JOGL code with drawPixels func?
    gimbal2 Guru
    Currently Being Moderated
    emotions are never appropriate in forums or any other kind of medium where you cannot see facial expressions and you cannot hear voice intonation. It just doesn't make sense to ever go down that path when all you have is text.
    Some day I've come up with an idea to ask society of this forum if they can see sth in my code that could be written in a better way.
    Yeah but that is just not a smart question to which the answer is simply "yes" - not much of a help is it? What you want to have are options. And that is something you can figure out for yourself through some simple research. That is the effort you should do yourself, it is not only in the programming part.

    If after your research you have three options and don't know which one to pursue first, by all means pose the question here.