|
| 1 | +/** |
| 2 | + * @author Richard Davey <rich@photonstorm.com> |
| 3 | + * @copyright 2020 Photon Storm Ltd. |
| 4 | + * @license {@link https://opensource.org/licenses/MIT|MIT License} |
| 5 | + */ |
| 6 | + |
| 7 | +var BindBuffer = require('./BindBuffer'); |
| 8 | +var BindTexture = require('./BindTexture'); |
| 9 | +var Class = require('../../utils/Class'); |
| 10 | +var ColorBuffer = require('./ColorBuffer'); |
| 11 | +var CONST = require('../const'); |
| 12 | +var CreateTexture = require('./CreateTexture'); |
| 13 | +var DepthBuffer = require('./DepthBuffer'); |
| 14 | +var SetActiveTexture = require('./SetActiveTexture'); |
| 15 | +var SetBlendMode = require('./SetBlendMode'); |
| 16 | +var SetCullFace = require('./SetCullFace'); |
| 17 | +var SetFlipSided = require('./SetFlipSided'); |
| 18 | +var SetLineWidth = require('./SetLineWidth'); |
| 19 | +var SetPolygonOffset = require('./SetPolygonOffset'); |
| 20 | +var SetProgram = require('./SetProgram'); |
| 21 | +var SetViewport = require('./SetViewport'); |
| 22 | +var StencilBuffer = require('./StencilBuffer'); |
| 23 | + |
| 24 | +var RenderState = new Class({ |
| 25 | + |
| 26 | + initialize: |
| 27 | + |
| 28 | + function RenderState (renderer) |
| 29 | + { |
| 30 | + var gl = renderer.gl; |
| 31 | + |
| 32 | + this.gl = gl; |
| 33 | + this.renderer = renderer; |
| 34 | + |
| 35 | + this.maxTextures = renderer.coreRenderer.maxTextures; |
| 36 | + this.lineWidthRange = gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE); |
| 37 | + |
| 38 | + this.colorBuffer = new ColorBuffer(this); |
| 39 | + this.depthBuffer = new DepthBuffer(this); |
| 40 | + this.stencilBuffer = new StencilBuffer(this); |
| 41 | + |
| 42 | + this.emptyTextures = {}; |
| 43 | + this.emptyTextures[gl.TEXTURE_2D] = CreateTexture(gl, gl.TEXTURE_2D, gl.TEXTURE_2D, 1); |
| 44 | + this.emptyTextures[gl.TEXTURE_CUBE_MAP] = CreateTexture(gl, gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6); |
| 45 | + |
| 46 | + this.currentRenderTarget = null; |
| 47 | + |
| 48 | + this.colorBuffer.setClear(0, 0, 0, 1); |
| 49 | + this.depthBuffer.setClear(1); |
| 50 | + this.stencilBuffer.setClear(0); |
| 51 | + |
| 52 | + this.depthBuffer.setTest(true); |
| 53 | + this.depthBuffer.setFunc(CONST.WEBGL_COMPARE_FUNC.LEQUAL); |
| 54 | + |
| 55 | + SetCullFace(this, CONST.CULL_FACE_TYPE.BACK); |
| 56 | + SetFlipSided(this, false); |
| 57 | + }, |
| 58 | + |
| 59 | + setBlend: function (blend, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) |
| 60 | + { |
| 61 | + SetBlendMode(this, blend, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha); |
| 62 | + }, |
| 63 | + |
| 64 | + setFlipSided: function (flipSided) |
| 65 | + { |
| 66 | + SetFlipSided(this, flipSided); |
| 67 | + }, |
| 68 | + |
| 69 | + setCullFace: function (cullFace) |
| 70 | + { |
| 71 | + SetCullFace(this, cullFace); |
| 72 | + }, |
| 73 | + |
| 74 | + viewport: function (x, y, width, height) |
| 75 | + { |
| 76 | + SetViewport(this, x, y, width, height); |
| 77 | + }, |
| 78 | + |
| 79 | + activeTexture: function (textureUnit) |
| 80 | + { |
| 81 | + SetActiveTexture(this, textureUnit); |
| 82 | + }, |
| 83 | + |
| 84 | + bindTexture: function (type, texture) |
| 85 | + { |
| 86 | + BindTexture(this, type, texture); |
| 87 | + }, |
| 88 | + |
| 89 | + bindBuffer: function (type, buffer) |
| 90 | + { |
| 91 | + BindBuffer(this, type, buffer); |
| 92 | + }, |
| 93 | + |
| 94 | + setLineWidth: function (width) |
| 95 | + { |
| 96 | + SetLineWidth(this, width); |
| 97 | + }, |
| 98 | + |
| 99 | + setPolygonOffset: function (polygonOffset, factor, units) |
| 100 | + { |
| 101 | + SetPolygonOffset(this, polygonOffset, factor, units); |
| 102 | + }, |
| 103 | + |
| 104 | + setProgram: function (program) |
| 105 | + { |
| 106 | + SetProgram(this, program); |
| 107 | + } |
| 108 | + |
| 109 | +}); |
| 110 | + |
| 111 | +module.exports = RenderState; |
0 commit comments