WebGLCapabilities.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. THREE.WebGLCapabilities = function( gl, extensions, parameters ) {
  2. this.getMaxPrecision = function ( precision ) {
  3. if ( precision === 'highp' ) {
  4. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  5. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  6. return 'highp';
  7. }
  8. precision = 'mediump';
  9. }
  10. if ( precision === 'mediump' ) {
  11. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  12. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  13. return 'mediump';
  14. }
  15. }
  16. return 'lowp';
  17. };
  18. // GPU capabilities
  19. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  20. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  21. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  22. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  23. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  24. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  25. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  26. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  27. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  28. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  29. this.vertexTextures = this.maxVertexTextures > 0;
  30. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  31. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  32. var _maxPrecision = this.getMaxPrecision( this.precision );
  33. if ( _maxPrecision !== this.precision ) {
  34. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  35. this.precision = _maxPrecision;
  36. }
  37. if ( this.logarithmicDepthBuffer ) {
  38. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  39. }
  40. };