OpenGL应用程序中的Java线程 [英] Java threads in OpenGL application

查看:72
本文介绍了OpenGL应用程序中的Java线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在Java中执行以下操作.我正在使用 LWJGL开发基于Java的OpenGL应用程序包装器.在每个帧渲染完成的渲染循环中,我将GL帧中的像素保存到图像文件中.问题是帧的大小有时会很大,并且在这段时间内会产生明显的开销将像素写入文件直到渲染循环的下一个开始的过程.我想做的是:

I want to know if it is possible to do the following in Java.I am working on a Java based OpenGL app using LWJGL wrapper.In the render loop on each frame render finish I am saving the pixels from the GL frame into image file.The problem is that the size of the frame sometimes is pretty large and it creates a noticeable overhead during the time of writing the pixels into file till the next start of the render loop.What I think to do is the following:

  1. 在帧渲染完成时,从帧"缓冲区读取像素.
  2. 在处理图像文件的类上启动新线程 写作.
  1. On the frame render finish read the pixels from the Frame buffer.
  2. Start a new thread on a class which takes care of image file writing.

我想知道这样的技术是否会有所帮助?如果下一个渲染循环是否在单独的线程上完成,是否会在不等待图像文件保存的情况下启动下一个渲染循环?使用线程完全可行吗?我要实现的是GL渲染循环不应该等待文件写入,而是在每个渲染循环结束时将新的像素数据提取到文件写入对象中时继续进行渲染.

I wonder if such a technique will be of any help?Will the next render loop start without waiting to the image file save if it is done on a separate thread? Is it feasible at all with threads? What I want to achieve is that the GL render loop shouldn't wait for the file write but proceed with the rendering while fetching new pixel data at the end of each render loop into the file writing object.

推荐答案

编写如下所示的线程类以运行单个正在运行的线程.

Write a thread class as below to run individual running thread.

public class WritePixelsToImageThread extends Thread { 

    public void run(){
        // place your code here for
        // read pixels from Frame and write that image.
        // this is an individual process
    }
}

new WritePixelsToImageThread().start();

这篇关于OpenGL应用程序中的Java线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆