📄 joglrenderer.java
字号:
//===========================================================================//=-------------------------------------------------------------------------=//= Module history: =//= - July 25 2006 - Oscar Chavarro: Original base version =//= - December 28 2006 - Oscar Chavarro: Added Nvidia Cg support =//===========================================================================package vsdk.toolkit.render.jogl;// Java base classesimport java.io.InputStream;import java.io.FileInputStream;// JOGL clasesimport javax.media.opengl.GL;import com.sun.opengl.cg.CgGL;import com.sun.opengl.cg.CGcontext;import com.sun.opengl.cg.CGprogram;import com.sun.opengl.cg.CGparameter;// VitralSDK classesimport vsdk.toolkit.common.VSDK;import vsdk.toolkit.common.RendererConfiguration;import vsdk.toolkit.io.PersistenceElement;import vsdk.toolkit.render.RenderingElement;/**The JoglRenderer abstract class provides an interface for Jogl*Rendererstyle classes. This serves two purposes: - To help in design level organization of Jogl renderers (this eases the study of the class hierarchy) - To provide a place to locate operations common to all Jogl renderers classes and Jogl renderers' private utility/supporting classes. In this moment, this operations include the global framework for managing Nvidia Cg access and general JOGL initialization, as such verifying correct availavility of native OpenGL libraries.*/public abstract class JoglRenderer extends RenderingElement { /** Note that this static block is automatically called for the first instanciation or the first static call to any of current subclasses. This is used to check correct JOGL environment availability, and report if not. Check why it is good to have this here disabled *//* static { // What happens when this is executed from an applet? //verifyOpenGLAvailability(); }*/ // Nvidia Cg general management protected static boolean nvidiaCgErrorReported = false; private static boolean nvidiaCgAvailable = false; private static CGcontext nvidiaGpuContext = null; private static int nvidiaGpuVertexProfile = -1; private static int nvidiaGpuPixelProfile = -1; private static boolean renderingWithNvidiaGpuFlag = false; public static CGprogram currentVertexShader = null; public static CGprogram currentPixelShader = null; // Nvidia Cg automatic shader management public static boolean nvidiaCgAutomaticMode = false; public static CGprogram NvidiaGpuVertexProgramTexture; public static CGprogram NvidiaGpuPixelProgramTexture; public static CGprogram NvidiaGpuVertexProgramTextureBump; public static CGprogram NvidiaGpuPixelProgramTextureBump; public static CGprogram getCurrentVertexShader() { return currentVertexShader; } public static CGprogram getCurrentPixelShader() { return currentPixelShader; } public static void createDefaultAutomaticNvidiaCgShaders() { nvidiaCgAutomaticMode = true; FileInputStream fis; try { //----------------------------------------------------------------- if ( !tryToEnableNvidiaCg() ) { nvidiaCgAutomaticMode = false; return; } fis = new FileInputStream("./etc/PhongTextureVertexShader.cg"); NvidiaGpuVertexProgramTexture = JoglRenderer.loadNvidiaGpuVertexShader(fis); fis.close(); fis = new FileInputStream("./etc/PhongTexturePixelShader.cg"); NvidiaGpuPixelProgramTexture = JoglRenderer.loadNvidiaGpuPixelShader(fis); fis.close(); fis = new FileInputStream("./etc/PhongTextureBumpVertexShader.cg"); NvidiaGpuVertexProgramTextureBump = JoglRenderer.loadNvidiaGpuVertexShader(fis); fis.close(); fis = new FileInputStream("./etc/PhongTextureBumpPixelShader.cg"); NvidiaGpuPixelProgramTextureBump = JoglRenderer.loadNvidiaGpuPixelShader(fis); fis.close(); } catch ( Exception e ) { VSDK.reportMessage(null, VSDK.WARNING, "JoglRenderer.createDefaultAutomaticNvidiaCgShaders", "Cannot access Cg shaders (.cg files). Nvidia Cg shader deactivated."); nvidiaCgAutomaticMode = false; return; } } public static void setNvidiaCgAutomaticMode(boolean flag) { nvidiaCgAutomaticMode = flag; } public static boolean getNvidiaCgAutomaticMode() { return nvidiaCgAutomaticMode; } public static boolean renderingWithNvidiaGpu() { return renderingWithNvidiaGpuFlag; } public static boolean setRenderingWithNvidiaGpu(boolean requested) { if ( !getNvidiaCgAvailability() ) { renderingWithNvidiaGpuFlag = false; } else { renderingWithNvidiaGpuFlag = requested; } return renderingWithNvidiaGpuFlag; } public static void bindNvidiaGpuShaders(CGprogram vertexShader, CGprogram pixelShader) { currentVertexShader = vertexShader; currentPixelShader = pixelShader; if ( currentVertexShader != null ) { CgGL.cgGLBindProgram(currentVertexShader); } if ( currentPixelShader != null ) { CgGL.cgGLBindProgram(currentPixelShader); } } public static CGparameter accessNvidiaGpuVertexParameter(String name) { if ( currentVertexShader != null ) { return CgGL.cgGetNamedParameter(currentVertexShader, name); } return null; } public static CGparameter accessNvidiaGpuPixelParameter(String name) { if ( currentPixelShader != null ) { return CgGL.cgGetNamedParameter(currentPixelShader, name); } return null; } public static boolean verifyOpenGLAvailability() { if ( !PersistenceElement.verifyLibrary("jogl") ) { VSDK.reportMessage(null, VSDK.FATAL_ERROR, "JoglRenderer.verifyOpenGLAvailability", "JOGL Library not found. Check your installation."); return false; } if ( !PersistenceElement.verifyLibrary("jogl_awt") ) { VSDK.reportMessage(null, VSDK.FATAL_ERROR, "JoglRenderer.verifyOpenGLAvailability", "JOGL-AWT Library not found. Check your installation."); return false; } if ( !PersistenceElement.verifyLibrary("jogl_cg") ) { VSDK.reportMessage(null, VSDK.FATAL_ERROR, "JoglRenderer.verifyOpenGLAvailability", "JOGL-CG Library not found. Check your installation."); return false; } return true; } /** This method searches for the dinamic link library packed shared objects (.dll or .so.*) needed for Nvidia Cg to work. Returns true if libraries are found in standard system locations, false otherwise. Note that OpenGL doesn't need to be started before calling this method. */ public static boolean verifyNvidiaCgAvailability() { if ( !PersistenceElement.verifyLibrary("Cg") ) { if ( nvidiaCgErrorReported ) return false; nvidiaCgErrorReported = true; VSDK.reportMessage(null, VSDK.WARNING, "JoglRenderer.verifyNvidiaCgAvailability", "CG Library not found. Check your installation.\n" + "Check it is installed from http://developers.nvidia.com\n" + "Furter error reporting on this issue disabled"); return false; } return true; } public static boolean getNvidiaCgAvailability() { return nvidiaCgAvailable; } public static boolean tryToEnableNvidiaCg() { nvidiaCgAvailable = false; //----------------------------------------------------------------- if ( !verifyOpenGLAvailability() || !verifyNvidiaCgAvailability() ) { nvidiaCgAutomaticMode = false; return false; } //----------------------------------------------------------------- nvidiaGpuContext = CgGL.cgCreateContext();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -