热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

033局部纹理刷新texSubImage2D

参考:在线体验代码出处更新原理:texSubImage2D参考教程UpdatableTexture.jsimport*asTHREEfrom.libthree.module.j

参考:
在线体验
代码出处
更新原理: texSubImage2D
参考教程

UpdatableTexture.js

import * as THREE from './lib/three.module.js'export default class UpdatableTexture extends THREE.Texture {isUpdatableTexture = trueconstructor(format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {super(null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding)var canvas = document.createElement('canvas');canvas.width = 1;canvas.height = 1;var ctx = canvas.getContext('2d');var imageData = ctx.createImageData(1, 1);this.image = imageData;this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;this.generateMipmaps = true;this.flipY = true;this.unpackAlignment = 1;this.needsUpdate = true;}setRenderer(renderer) {this.renderer = renderer;this.gl = this.renderer.getContext()this.utils = THREE.WebGLUtils(this.gl, this.renderer.extensions, { isWebGL2: false })}setSize(width, height) {if (width === this.width && height === this.height) return;var textureProperties = this.renderer.properties.get(this);if (!textureProperties.__webglTexture) return;this.width = width;this.height = height;var activeTexture = this.gl.getParameter(this.gl.TEXTURE_BINDING_2D);this.gl.bindTexture(this.gl.TEXTURE_2D, textureProperties.__webglTexture);if (!textureProperties.__webglTexture) this.width = null;this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.utils.convert(this.format),width,height,0,this.utils.convert(this.format),this.utils.convert(this.type),null);this.gl.bindTexture(this.gl.TEXTURE_2D, activeTexture);}update(src, x, y) {var textureProperties = this.renderer.properties.get(this);if (!textureProperties.__webglTexture) return;var activeTexture = this.gl.getParameter(this.gl.TEXTURE_BINDING_2D);this.gl.bindTexture(this.gl.TEXTURE_2D, textureProperties.__webglTexture);this.gl.texSubImage2D(this.gl.TEXTURE_2D,0,x,this.height - y - src.height,this.utils.convert(this.format),this.utils.convert(this.type),src);this.gl.generateMipmap(this.gl.TEXTURE_2D);this.gl.bindTexture(this.gl.TEXTURE_2D, activeTexture);}
}

推荐阅读
author-avatar
刘莉长
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有