protected static int create(final ByteBuffer program) { final IntBuffer buf = BufferUtils.createIntBuffer(1); ARBProgram.glGenProgramsARB(buf); ARBProgram.glBindProgramARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, buf.get(0)); ARBProgram.glProgramStringARB( ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, ARBProgram.GL_PROGRAM_FORMAT_ASCII_ARB, program); checkProgramError(); return buf.get(0); }
/** * Queries OpenGL for errors in the vertex program. Errors are logged as SEVERE, noting both the * line number and message. */ private static void checkProgramError() { if (GL11.glGetError() == GL11.GL_INVALID_OPERATION) { // retrieve the error position final IntBuffer errorloc = BufferUtils.createIntBuffer(16); GL11.glGetInteger(ARBProgram.GL_PROGRAM_ERROR_POSITION_ARB, errorloc); logger.severe( "Error " + GL11.glGetString(ARBProgram.GL_PROGRAM_ERROR_STRING_ARB) + " in vertex program on line " + errorloc.get(0)); } }
/** * Queries OpenGL for errors in the vertex program. Errors are logged as SEVERE, noting both the * line number and message. */ private static void checkProgramError() { final GL gl = GLU.getCurrentGL(); if (gl.glGetError() == GL.GL_INVALID_OPERATION) { // retrieve the error position final IntBuffer errorloc = BufferUtils.createIntBuffer(16); gl.glGetIntegerv(GL.GL_PROGRAM_ERROR_POSITION_ARB, errorloc); // TODO Check for integer logger.severe( "Error " + gl.glGetString(GL.GL_PROGRAM_ERROR_STRING_ARB) + " in vertex program on line " + errorloc.get(0)); } }
/** * <code>setupTexture</code> initializes a new Texture object for use with TextureRenderer. * Generates a valid gl texture id for this texture and inits the data type for the texture. */ public void setupTexture(final Texture tex) { if (tex.getType() != Type.TwoDimensional) { throw new IllegalArgumentException("Unsupported type: " + tex.getType()); } final RenderContext context = ContextManager.getCurrentContext(); final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(RenderState.StateType.Texture); // check if we are already setup... if so, throw error. if (tex.getTextureKey() == null) { tex.setTextureKey(TextureKey.getRTTKey(tex.getMinificationFilter())); } else if (tex.getTextureIdForContext(context.getGlContextRep()) != 0) { throw new Ardor3dException("Texture is already setup and has id."); } // Create the texture final IntBuffer ibuf = BufferUtils.createIntBuffer(1); GL11.glGenTextures(ibuf); final int textureId = ibuf.get(0); tex.setTextureIdForContext(context.getGlContextRep(), textureId); LwjglTextureStateUtil.doTextureBind(tex, 0, true); // Initialize our texture with some default data. final int internalFormat = LwjglTextureUtil.getGLInternalFormat(tex.getTextureStoreFormat()); final int dataFormat = LwjglTextureUtil.getGLPixelFormatFromStoreFormat(tex.getTextureStoreFormat()); final int pixelDataType = LwjglTextureUtil.getGLPixelDataType(tex.getRenderedTexturePixelDataType()); GL11.glTexImage2D( GL11.GL_TEXTURE_2D, 0, internalFormat, _width, _height, 0, dataFormat, pixelDataType, (ByteBuffer) null); // Setup filtering and wrap final TextureRecord texRecord = record.getTextureRecord(textureId, tex.getType()); LwjglTextureStateUtil.applyFilter(tex, texRecord, 0, record, context.getCapabilities()); LwjglTextureStateUtil.applyWrap(tex, texRecord, 0, record, context.getCapabilities()); logger.fine("setup pbuffer tex" + textureId + ": " + _width + "," + _height); }
private static int create(final ByteBuffer program) { final GL gl = GLU.getCurrentGL(); final IntBuffer buf = BufferUtils.createIntBuffer(1); gl.glGenProgramsARB(buf.limit(), buf); gl.glBindProgramARB(GL.GL_VERTEX_PROGRAM_ARB, buf.get(0)); final byte array[] = new byte[program.limit()]; program.rewind(); program.get(array); gl.glProgramStringARB( GL.GL_VERTEX_PROGRAM_ARB, GL.GL_PROGRAM_FORMAT_ASCII_ARB, array.length, new String(array)); checkProgramError(); return buf.get(0); }
private void recreateBuffers() { // determine vert quantity - first the sphere caps final int sampleLines = (2 * sphereSamples - 1 + axisSamples); final int verts = (radialSamples + 1) * sampleLines + 2; _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(_meshData.getVertexBuffer(), verts)); // allocate normals _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(_meshData.getNormalBuffer(), verts)); // allocate texture coordinates _meshData.setTextureCoords(new TexCoords(BufferUtils.createVector2Buffer(verts)), 0); // determine tri quantity final int tris = 2 * radialSamples * sampleLines; _meshData.setIndexBuffer(BufferUtils.createIntBuffer(_meshData.getIndexBuffer(), 3 * tris)); setGeometryData(); setIndexData(); }
/** * Constructor * * @param color */ public SimpleCrosshair(ReadOnlyColorRGBA color) { super("Crosshair"); ReadOnlyColorRGBA[] crosshairColor = {color, color, color, color}; getMeshData().setIndexMode(IndexMode.Lines); getMeshData().setVertexBuffer(BufferUtils.createFloatBuffer(crosshairVertex)); FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(crosshairColor); colorBuffer.rewind(); getMeshData().setColorBuffer(colorBuffer); getMeshData().setIndexBuffer(BufferUtils.createIntBuffer(crosshairIndex)); getMeshData().getIndexBuffer().limit(4); getMeshData().getIndexBuffer().rewind(); getSceneHints().setAllPickingHints(false); setModelBound(new BoundingBox()); updateModelBound(); MaterialState crosshairMaterialState = new MaterialState(); crosshairMaterialState.setColorMaterial(MaterialState.ColorMaterial.Emissive); crosshairMaterialState.setEnabled(true); getSceneHints().setLightCombineMode(LightCombineMode.Off); setRenderState(crosshairMaterialState); updateGeometricState(0, true); }
private Mesh createDegenerateStripMesh() { final Mesh mesh = new Mesh(); final MeshData meshData = mesh.getMeshData(); final FloatBuffer vertexBuffer = BufferUtils.createVector3Buffer(totalSize); final FloatBuffer normalBuffer = BufferUtils.createVector3Buffer(totalSize); final FloatBuffer textureBuffer = BufferUtils.createVector2Buffer(totalSize); final IntBuffer indexBuffer = BufferUtils.createIntBuffer((ySize - 1) * xSize * 2 + (ySize - 1) * 2); for (int y = 0; y < ySize; y++) { for (int x = 0; x < xSize; x++) { vertexBuffer.put(x).put(y).put(0); normalBuffer.put(0).put(0).put(1); textureBuffer.put(x).put(y); } } for (int y = 0; y < ySize - 1; y++) { for (int x = 0; x < xSize; x++) { final int index = y * xSize + x; indexBuffer.put(index); indexBuffer.put(index + xSize); } final int index = (y + 1) * xSize; indexBuffer.put(index + xSize - 1); indexBuffer.put(index); } meshData.setVertexBuffer(vertexBuffer); meshData.setNormalBuffer(normalBuffer); meshData.setTextureBuffer(textureBuffer, 0); meshData.setIndexBuffer(indexBuffer); meshData.setIndexMode(IndexMode.TriangleStrip); return mesh; }
/** * Check for program errors. If an error is detected, program exits. * * @param compiled the compiler state for a given shader * @param id shader's id */ private static void checkProgramError(final IntBuffer compiled, final int id) { final GL gl = GLU.getCurrentGL(); if (compiled.get(0) == GL.GL_FALSE) { final IntBuffer iVal = BufferUtils.createIntBuffer(1); gl.glGetObjectParameterivARB(id, GL.GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal); final int length = iVal.get(0); String out = null; if (length > 0) { final ByteBuffer infoLog = BufferUtils.createByteBuffer(length); gl.glGetInfoLogARB(id, infoLog.limit(), iVal, infoLog); final byte[] infoBytes = new byte[length]; infoLog.get(infoBytes); out = new String(infoBytes); } logger.severe(out); throw new Ardor3dException("Error compiling GLSL shader: " + out); } }
private static void checkLinkError(final int programId) { final GL gl = GLU.getCurrentGL(); final IntBuffer compiled = BufferUtils.createIntBuffer(1); gl.glGetObjectParameterivARB(programId, GL.GL_LINK_STATUS, compiled); if (compiled.get(0) == GL.GL_FALSE) { gl.glGetObjectParameterivARB(programId, GL.GL_INFO_LOG_LENGTH, compiled); final int length = compiled.get(0); String out = null; if (length > 0) { final ByteBuffer infoLog = BufferUtils.createByteBuffer(length); gl.glGetInfoLogARB(programId, infoLog.limit(), compiled, infoLog); final byte[] infoBytes = new byte[length]; infoLog.get(infoBytes); out = new String(infoBytes); } logger.severe(out); // throw new Ardor3dException("Error linking GLSL shader: " + out); } }
protected static void sendToGL(final GLSLShaderObjectsState state) { final GL gl = GLU.getCurrentGL(); if (state.getVertexShader() == null && state.getFragmentShader() == null) { logger.warning("Could not find shader resources!" + "(both inputbuffers are null)"); state._needSendShader = false; return; } if (state._programID == -1) { state._programID = gl.glCreateProgramObjectARB(); } if (state.getVertexShader() != null) { if (state._vertexShaderID != -1) { removeVertShader(state); } state._vertexShaderID = gl.glCreateShaderObjectARB(GL.GL_VERTEX_SHADER_ARB); // Create the sources final byte array[] = new byte[state.getVertexShader().limit()]; state.getVertexShader().rewind(); state.getVertexShader().get(array); gl.glShaderSourceARB( state._vertexShaderID, 1, new String[] {new String(array)}, new int[] {array.length}, 0); // Compile the vertex shader final IntBuffer compiled = BufferUtils.createIntBuffer(1); gl.glCompileShaderARB(state._vertexShaderID); gl.glGetObjectParameterivARB( state._vertexShaderID, GL.GL_OBJECT_COMPILE_STATUS_ARB, compiled); checkProgramError(compiled, state._vertexShaderID); // Attach the program gl.glAttachObjectARB(state._programID, state._vertexShaderID); } else if (state._vertexShaderID != -1) { removeVertShader(state); state._vertexShaderID = -1; } if (state.getFragmentShader() != null) { if (state._fragmentShaderID != -1) { removeFragShader(state); } state._fragmentShaderID = gl.glCreateShaderObjectARB(GL.GL_FRAGMENT_SHADER_ARB); // Create the sources final byte array[] = new byte[state.getFragmentShader().limit()]; state.getFragmentShader().rewind(); state.getFragmentShader().get(array); gl.glShaderSourceARB( state._fragmentShaderID, 1, new String[] {new String(array)}, new int[] {array.length}, 0); // Compile the fragment shader final IntBuffer compiled = BufferUtils.createIntBuffer(1); gl.glCompileShaderARB(state._fragmentShaderID); gl.glGetObjectParameterivARB( state._fragmentShaderID, GL.GL_OBJECT_COMPILE_STATUS_ARB, compiled); checkProgramError(compiled, state._fragmentShaderID); // Attach the program gl.glAttachObjectARB(state._programID, state._fragmentShaderID); } else if (state._fragmentShaderID != -1) { removeFragShader(state); state._fragmentShaderID = -1; } gl.glLinkProgramARB(state._programID); checkLinkError(state._programID); state.setNeedsRefresh(true); state._needSendShader = false; }
public LwjglContextCapabilities(final org.lwjgl.opengl.ContextCapabilities caps) { final IntBuffer buf = BufferUtils.createIntBuffer(16); _supportsVBO = caps.GL_ARB_vertex_buffer_object; _supportsGL1_2 = caps.OpenGL12; _supportsMultisample = caps.GL_ARB_multisample; _supportsConstantColor = _supportsEq = caps.GL_ARB_imaging; _supportsSeparateFunc = caps.GL_EXT_blend_func_separate; _supportsSeparateEq = caps.GL_EXT_blend_equation_separate; _supportsMinMax = caps.GL_EXT_blend_minmax; _supportsSubtract = caps.GL_EXT_blend_subtract; _supportsFogCoords = caps.GL_EXT_fog_coord; _supportsFragmentProgram = caps.GL_ARB_fragment_program; _supportsVertexProgram = caps.GL_ARB_vertex_program; _supportsTextureLodBias = caps.GL_EXT_texture_lod_bias; if (_supportsTextureLodBias) { GL11.glGetInteger(EXTTextureLODBias.GL_MAX_TEXTURE_LOD_BIAS_EXT, buf); _maxTextureLodBias = buf.get(0); } else { _maxTextureLodBias = 0f; } _glslSupported = caps.GL_ARB_shader_objects && caps.GL_ARB_fragment_shader && caps.GL_ARB_vertex_shader && caps.GL_ARB_shading_language_100; if (_glslSupported) { GL11.glGetInteger(ARBVertexShader.GL_MAX_VERTEX_ATTRIBS_ARB, buf); _maxGLSLVertexAttribs = buf.get(0); } // Pbuffer _pbufferSupported = caps.GL_ARB_pixel_buffer_object; // FBO _fboSupported = caps.GL_EXT_framebuffer_object; if (_fboSupported) { if (caps.GL_ARB_draw_buffers) { GL11.glGetInteger(EXTFramebufferObject.GL_MAX_COLOR_ATTACHMENTS_EXT, buf); _maxFBOColorAttachments = buf.get(0); } else { _maxFBOColorAttachments = 1; } // Max multisample samples. if (caps.GL_EXT_framebuffer_multisample && caps.GL_EXT_framebuffer_blit) { GL11.glGetInteger(EXTFramebufferMultisample.GL_MAX_SAMPLES_EXT, buf); _maxFBOSamples = buf.get(0); } else { _maxFBOSamples = 0; } } else { _maxFBOColorAttachments = 0; } _twoSidedStencilSupport = caps.GL_EXT_stencil_two_side; _stencilWrapSupport = caps.GL_EXT_stencil_wrap; // number of available auxiliary draw buffers GL11.glGetInteger(GL11.GL_AUX_BUFFERS, buf); _numAuxDrawBuffers = buf.get(0); // max texture size. GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE, buf); _maxTextureSize = buf.get(0); // Check for support of multitextures. _supportsMultiTexture = caps.GL_ARB_multitexture; // Check for support of fixed function dot3 environment settings _supportsEnvDot3 = caps.GL_ARB_texture_env_dot3; // Check for support of fixed function dot3 environment settings _supportsEnvCombine = caps.GL_ARB_texture_env_combine; // Check for support of automatic mipmap generation _automaticMipMaps = caps.GL_SGIS_generate_mipmap; _supportsDepthTexture = caps.GL_ARB_depth_texture; _supportsShadow = caps.GL_ARB_shadow; // If we do support multitexturing, find out how many textures we // can handle. if (_supportsMultiTexture) { GL11.glGetInteger(ARBMultitexture.GL_MAX_TEXTURE_UNITS_ARB, buf); _numFixedTexUnits = buf.get(0); } else { _numFixedTexUnits = 1; } // Go on to check number of texture units supported for vertex and // fragment shaders if (caps.GL_ARB_shader_objects && caps.GL_ARB_vertex_shader && caps.GL_ARB_fragment_shader) { GL11.glGetInteger(ARBVertexShader.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, buf); _numVertexTexUnits = buf.get(0); GL11.glGetInteger(ARBFragmentShader.GL_MAX_TEXTURE_IMAGE_UNITS_ARB, buf); _numFragmentTexUnits = buf.get(0); GL11.glGetInteger(ARBFragmentShader.GL_MAX_TEXTURE_COORDS_ARB, buf); _numFragmentTexCoordUnits = buf.get(0); } else { // based on nvidia dev doc: // http://developer.nvidia.com/object/General_FAQ.html#t6 // "For GPUs that do not support GL_ARB_fragment_program and // GL_NV_fragment_program, those two limits are set equal to // GL_MAX_TEXTURE_UNITS." _numFragmentTexCoordUnits = _numFixedTexUnits; _numFragmentTexUnits = _numFixedTexUnits; // We'll set this to 0 for now since we do not know: _numVertexTexUnits = 0; } // Now determine the maximum number of supported texture units _numTotalTexUnits = Math.max( _numFragmentTexCoordUnits, Math.max(_numFixedTexUnits, Math.max(_numFragmentTexUnits, _numVertexTexUnits))); // Check for S3 texture compression capability. _supportsS3TCCompression = caps.GL_EXT_texture_compression_s3tc; // Check for 3D texture capability. _supportsTexture3D = caps.OpenGL12; // Check for cubemap capability. _supportsTextureCubeMap = caps.GL_ARB_texture_cube_map; // See if we support anisotropic filtering _supportsAniso = caps.GL_EXT_texture_filter_anisotropic; if (_supportsAniso) { // Due to LWJGL buffer check, you can't use smaller sized // buffers (min_size = 16 for glGetFloat()). final FloatBuffer max_a = BufferUtils.createFloatBuffer(16); max_a.rewind(); // Grab the maximum anisotropic filter. GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, max_a); // set max. _maxAnisotropic = max_a.get(0); } // See if we support textures that are not power of 2 in size. _supportsNonPowerTwo = caps.GL_ARB_texture_non_power_of_two; // See if we support textures that do not have width == height. _supportsRectangular = caps.GL_ARB_texture_rectangle; _supportsMirroredRepeat = caps.GL_ARB_texture_mirrored_repeat; _supportsMirrorClamp = _supportsMirrorEdgeClamp = _supportsMirrorBorderClamp = caps.GL_EXT_texture_mirror_clamp; _supportsBorderClamp = caps.GL_ARB_texture_border_clamp; _supportsEdgeClamp = _supportsGL1_2; }