123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- define([
- '../Core/Cartesian2',
- '../Core/Color',
- '../Core/defined',
- '../Core/destroyObject',
- '../Core/PixelFormat',
- '../Renderer/ClearCommand',
- '../Renderer/PixelDatatype',
- '../Renderer/RenderbufferFormat',
- '../Shaders/PostProcessFilters/FXAA'
- ], function(
- Cartesian2,
- Color,
- defined,
- destroyObject,
- PixelFormat,
- ClearCommand,
- PixelDatatype,
- RenderbufferFormat,
- FXAAFS) {
- "use strict";
-
- var FXAA = function(context) {
- this._texture = undefined;
- this._depthTexture = undefined;
- this._depthRenderbuffer = undefined;
- this._fbo = undefined;
- this._command = undefined;
- var clearCommand = new ClearCommand({
- color : new Color(0.0, 0.0, 0.0, 0.0),
- depth : 1.0,
- owner : this
- });
- this._clearCommand = clearCommand;
- };
- function destroyResources(fxaa) {
- fxaa._fbo = fxaa._fbo && fxaa._fbo.destroy();
- fxaa._texture = fxaa._texture && fxaa._texture.destroy();
- fxaa._depthTexture = fxaa._depthTexture && fxaa._depthTexture.destroy();
- fxaa._depthRenderbuffer = fxaa._depthRenderbuffer && fxaa._depthRenderbuffer.destroy();
- fxaa._fbo = undefined;
- fxaa._texture = undefined;
- fxaa._depthTexture = undefined;
- fxaa._depthRenderbuffer = undefined;
- if (defined(fxaa._command)) {
- fxaa._command.shaderProgram = fxaa._command.shaderProgram && fxaa._command.shaderProgram.destroy();
- fxaa._command = undefined;
- }
- }
- FXAA.prototype.update = function(context) {
- var width = context.drawingBufferWidth;
- var height = context.drawingBufferHeight;
- var fxaaTexture = this._texture;
- var textureChanged = !defined(fxaaTexture) || fxaaTexture.width !== width || fxaaTexture.height !== height;
- if (textureChanged) {
- this._texture = this._texture && this._texture.destroy();
- this._depthTexture = this._depthTexture && this._depthTexture.destroy();
- this._depthRenderbuffer = this._depthRenderbuffer && this._depthRenderbuffer.destroy();
- this._texture = context.createTexture2D({
- width : width,
- height : height,
- pixelFormat : PixelFormat.RGBA,
- pixelDatatype : PixelDatatype.UNSIGNED_BYTE
- });
- if (context.depthTexture) {
- this._depthTexture = context.createTexture2D({
- width : width,
- height : height,
- pixelFormat : PixelFormat.DEPTH_COMPONENT,
- pixelDatatype : PixelDatatype.UNSIGNED_SHORT
- });
- } else {
- this._depthRenderbuffer = context.createRenderbuffer({
- width : width,
- height : height,
- format : RenderbufferFormat.DEPTH_COMPONENT16
- });
- }
- }
- if (!defined(this._fbo) || textureChanged) {
- this._fbo = this._fbo && this._fbo.destroy();
- this._fbo = context.createFramebuffer({
- colorTextures : [this._texture],
- depthTexture : this._depthTexture,
- depthRenderbuffer : this._depthRenderbuffer,
- destroyAttachments : false
- });
- }
- if (!defined(this._command)) {
- this._command = context.createViewportQuadCommand(FXAAFS, {
- renderState : context.createRenderState(),
- owner : this
- });
- }
- if (textureChanged) {
- var that = this;
- var step = new Cartesian2(1.0 / this._texture.width, 1.0 / this._texture.height);
- this._command.uniformMap = {
- u_texture : function() {
- return that._texture;
- },
- u_step : function() {
- return step;
- }
- };
- }
- };
- FXAA.prototype.execute = function(context, passState) {
- this._command.execute(context, passState);
- };
- FXAA.prototype.clear = function(context, passState, clearColor) {
- var framebuffer = passState.framebuffer;
- passState.framebuffer = this._fbo;
- Color.clone(clearColor, this._clearCommand.color);
- this._clearCommand.execute(context, passState);
- passState.framebuffer = framebuffer;
- };
- FXAA.prototype.getColorFramebuffer = function() {
- return this._fbo;
- };
- FXAA.prototype.isDestroyed = function() {
- return false;
- };
- FXAA.prototype.destroy = function() {
- destroyResources(this);
- return destroyObject(this);
- };
- return FXAA;
- });
|