123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- define([
- '../Core/defaultValue',
- '../Core/defineProperties',
- '../Core/DeveloperError',
- './PixelDatatype'
- ], function(
- defaultValue,
- defineProperties,
- DeveloperError,
- PixelDatatype) {
- "use strict";
-
- var CubeMapFace = function(gl, texture, textureTarget, targetFace, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY) {
- this._gl = gl;
- this._texture = texture;
- this._textureTarget = textureTarget;
- this._targetFace = targetFace;
- this._pixelFormat = pixelFormat;
- this._pixelDatatype = pixelDatatype;
- this._size = size;
- this._preMultiplyAlpha = preMultiplyAlpha;
- this._flipY = flipY;
- };
- defineProperties(CubeMapFace.prototype, {
- pixelFormat : {
- get : function() {
- return this._pixelFormat;
- }
- },
- pixelDatatype : {
- get : function() {
- return this._pixelDatatype;
- }
- },
- _target : {
- get : function() {
- return this._targetFace;
- }
- }
- });
-
- CubeMapFace.prototype.copyFrom = function(source, xOffset, yOffset) {
- xOffset = defaultValue(xOffset, 0);
- yOffset = defaultValue(yOffset, 0);
-
- if (!source) {
- throw new DeveloperError('source is required.');
- }
- if (xOffset < 0) {
- throw new DeveloperError('xOffset must be greater than or equal to zero.');
- }
- if (yOffset < 0) {
- throw new DeveloperError('yOffset must be greater than or equal to zero.');
- }
- if (xOffset + source.width > this._size) {
- throw new DeveloperError('xOffset + source.width must be less than or equal to width.');
- }
- if (yOffset + source.height > this._size) {
- throw new DeveloperError('yOffset + source.height must be less than or equal to height.');
- }
-
- var gl = this._gl;
- var target = this._textureTarget;
-
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha);
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY);
- gl.activeTexture(gl.TEXTURE0);
- gl.bindTexture(target, this._texture);
- if (source.arrayBufferView) {
- gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, source.width, source.height, this._pixelFormat, this._pixelDatatype, source.arrayBufferView);
- } else {
- gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, this._pixelFormat, this._pixelDatatype, source);
- }
- gl.bindTexture(target, null);
- };
-
- CubeMapFace.prototype.copyFromFramebuffer = function(xOffset, yOffset, framebufferXOffset, framebufferYOffset, width, height) {
- xOffset = defaultValue(xOffset, 0);
- yOffset = defaultValue(yOffset, 0);
- framebufferXOffset = defaultValue(framebufferXOffset, 0);
- framebufferYOffset = defaultValue(framebufferYOffset, 0);
- width = defaultValue(width, this._size);
- height = defaultValue(height, this._size);
-
- if (xOffset < 0) {
- throw new DeveloperError('xOffset must be greater than or equal to zero.');
- }
- if (yOffset < 0) {
- throw new DeveloperError('yOffset must be greater than or equal to zero.');
- }
- if (framebufferXOffset < 0) {
- throw new DeveloperError('framebufferXOffset must be greater than or equal to zero.');
- }
- if (framebufferYOffset < 0) {
- throw new DeveloperError('framebufferYOffset must be greater than or equal to zero.');
- }
- if (xOffset + width > this._size) {
- throw new DeveloperError('xOffset + source.width must be less than or equal to width.');
- }
- if (yOffset + height > this._size) {
- throw new DeveloperError('yOffset + source.height must be less than or equal to height.');
- }
- if (this._pixelDatatype === PixelDatatype.FLOAT) {
- throw new DeveloperError('Cannot call copyFromFramebuffer when the texture pixel data type is FLOAT.');
- }
-
- var gl = this._gl;
- var target = this._textureTarget;
- gl.activeTexture(gl.TEXTURE0);
- gl.bindTexture(target, this._texture);
- gl.copyTexSubImage2D(this._targetFace, 0, xOffset, yOffset, framebufferXOffset, framebufferYOffset, width, height);
- gl.bindTexture(target, null);
- };
- return CubeMapFace;
- });
|