mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 11:31:59 +08:00
fix compressed texture creation bug
This commit is contained in:
@@ -281,7 +281,7 @@ export class Mesh extends Asset {
|
||||
|
||||
srcOffset = bundle.view.offset;
|
||||
dstOffset = dstBundle.view.offset;
|
||||
vertStride = bundle.view.stride;
|
||||
vertStride = bundle.view.stride + 4;
|
||||
vertCount = bundle.view.count + dstBundle.view.count;
|
||||
|
||||
vb = new ArrayBuffer(vertCount * vertStride);
|
||||
|
||||
@@ -23,16 +23,16 @@
|
||||
****************************************************************************/
|
||||
|
||||
import { Texture2D } from '../../assets';
|
||||
import { Filter, PixelFormat } from '../../assets/asset-enum';
|
||||
import { Rect } from '../../core';
|
||||
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator';
|
||||
import { GFXBufferTextureCopy } from '../../gfx/define';
|
||||
import { GFXDevice } from '../../gfx/device';
|
||||
import { Mesh } from '../assets';
|
||||
import { SkinningModelComponent } from './skinning-model-component';
|
||||
import { GFXTextureCopy } from '../../gfx/define';
|
||||
import { Filter, PixelFormat } from '../../assets/asset-enum';
|
||||
|
||||
export interface IAvatarUnit {
|
||||
mesh: Mesh;
|
||||
mesh: Mesh | null;
|
||||
region: Rect;
|
||||
albedoMap: Texture2D | null;
|
||||
alphaMap: Texture2D | null;
|
||||
@@ -71,6 +71,8 @@ export class AvatarModelComponent extends SkinningModelComponent {
|
||||
public onLoad () {
|
||||
super.onLoad();
|
||||
|
||||
this._mesh = new Mesh();
|
||||
|
||||
this._combinedTex = new Texture2D();
|
||||
this._combinedTex.setFilters(Filter.LINEAR, Filter.LINEAR);
|
||||
this.resizeCombiendTexture();
|
||||
@@ -90,20 +92,33 @@ export class AvatarModelComponent extends SkinningModelComponent {
|
||||
public combine () {
|
||||
|
||||
const texImages: TexImageSource[] = [];
|
||||
const texImageRegions: GFXTextureCopy[] = [];
|
||||
const texImageRegions: GFXBufferTextureCopy[] = [];
|
||||
const texBuffers: ArrayBuffer[] = [];
|
||||
const texBufferRegions: GFXTextureCopy[] = [];
|
||||
const texBufferRegions: GFXBufferTextureCopy[] = [];
|
||||
|
||||
this._mesh
|
||||
|
||||
for (const unit of this._units) {
|
||||
if (unit) {
|
||||
|
||||
// merge mesh
|
||||
if (unit.mesh) {
|
||||
for (let i = 0; i < unit.mesh.subMeshCount; ++i) {
|
||||
const subMesh = unit.mesh.getSubMesh(i);
|
||||
}
|
||||
}
|
||||
|
||||
// merge textures
|
||||
const isValid = (unit.region.x > 0 && unit.region.y > 0) &&
|
||||
(unit.region.width > 0 && unit.region.height > 0) &&
|
||||
(unit.region.x + unit.region.width) <= this._combinedTexSize &&
|
||||
(unit.region.y + unit.region.height) <= this._combinedTexSize;
|
||||
|
||||
if (isValid && unit.albedoMap && unit.albedoMap.image && unit.albedoMap.image.data) {
|
||||
|
||||
const region = new GFXTextureCopy();
|
||||
const region = new GFXBufferTextureCopy();
|
||||
region.texOffset.x = unit.region.x;
|
||||
region.texOffset.y = unit.region.y;
|
||||
region.texExtent.width = unit.region.width;
|
||||
region.texExtent.height = unit.region.height;
|
||||
|
||||
const data = unit.albedoMap.image.data;
|
||||
if (data instanceof HTMLCanvasElement || data instanceof HTMLImageElement) {
|
||||
@@ -119,10 +134,14 @@ export class AvatarModelComponent extends SkinningModelComponent {
|
||||
|
||||
const gfxTex = this._combinedTex!.getGFXTexture();
|
||||
const device: GFXDevice = cc.director.root.device;
|
||||
for (const buff of texBuffers) {
|
||||
// device.copyBuffersToTexture(texBuffers, gfxTex!, );
|
||||
|
||||
if (texBuffers.length > 0) {
|
||||
device.copyTexImagesToTexture(texImages, gfxTex!, texImageRegions);
|
||||
}
|
||||
|
||||
if (texBuffers.length > 0) {
|
||||
device.copyBuffersToTexture(texBuffers, gfxTex!, texBufferRegions);
|
||||
}
|
||||
// device.copyTexImagesToTexture();
|
||||
}
|
||||
|
||||
private resizeCombiendTexture () {
|
||||
|
||||
@@ -309,11 +309,13 @@ export class LetterAtlas {
|
||||
|
||||
this._letterDefinitions.set(letterTexture.hash, letterDefinition);
|
||||
|
||||
/*
|
||||
const region = new GFXBufferTextureCopy();
|
||||
region.texOffset.x = letterDefinition.offsetX;
|
||||
region.texOffset.y = letterDefinition.offsetY;
|
||||
region.texExtent.width = letterDefinition.w;
|
||||
region.texExtent.height = letterDefinition.h;
|
||||
*/
|
||||
|
||||
return letterDefinition;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
IGFXFormatInfo,
|
||||
IGFXRect,
|
||||
IGFXViewport,
|
||||
GFXFormatSize,
|
||||
} from '../define';
|
||||
import { WebGLGFXCommandAllocator } from './webgl-command-allocator';
|
||||
import {
|
||||
@@ -794,8 +795,9 @@ export function WebGLCmdFuncCreateTexture (device: WebGLGFXDevice, gpuTexture: W
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
} else {
|
||||
const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 };
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1);
|
||||
const view: ArrayBufferView = { buffer: new ArrayBuffer(imgSize), byteLength: imgSize, byteOffset: 0 };
|
||||
gl.compressedTexImage2D(WebGLRenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, view);
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
@@ -847,12 +849,12 @@ export function WebGLCmdFuncCreateTexture (device: WebGLGFXDevice, gpuTexture: W
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 };
|
||||
|
||||
for (let f = 0; f < 6; ++f) {
|
||||
let w = gpuTexture.width;
|
||||
let h = gpuTexture.height;
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1);
|
||||
const view: ArrayBufferView = { buffer: new ArrayBuffer(imgSize), byteLength: imgSize, byteOffset: 0 };
|
||||
gl.compressedTexImage2D(WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, view);
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
@@ -929,8 +931,9 @@ export function WebGLCmdFuncResizeTexture (device: WebGLGFXDevice, gpuTexture: W
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
} else {
|
||||
const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 };
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1);
|
||||
const view: ArrayBufferView = { buffer: new ArrayBuffer(imgSize), byteLength: imgSize, byteOffset: 0 };
|
||||
gl.compressedTexImage2D(gl.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, view);
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
@@ -961,12 +964,12 @@ export function WebGLCmdFuncResizeTexture (device: WebGLGFXDevice, gpuTexture: W
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 };
|
||||
|
||||
for (let f = 0; f < 6; ++f) {
|
||||
let w = gpuTexture.width;
|
||||
let h = gpuTexture.height;
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1);
|
||||
const view: ArrayBufferView = { buffer: new ArrayBuffer(imgSize), byteLength: imgSize, byteOffset: 0 };
|
||||
gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, view);
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
IGFXRect,
|
||||
IGFXViewport,
|
||||
GFXFormatType,
|
||||
GFXFormatSize,
|
||||
} from '../define';
|
||||
import { WebGL2GFXCommandAllocator } from './webgl2-command-allocator';
|
||||
import {
|
||||
@@ -972,7 +973,8 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2GFXDevice, gpuTexture:
|
||||
} else {
|
||||
const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 };
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, view);
|
||||
const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1);
|
||||
gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, imgSize, 0);
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
@@ -1038,7 +1040,8 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2GFXDevice, gpuTexture:
|
||||
let w = gpuTexture.width;
|
||||
let h = gpuTexture.height;
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, view);
|
||||
const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1);
|
||||
gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, imgSize, 0);
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
@@ -1117,7 +1120,8 @@ export function WebGL2CmdFuncResizeTexture (device: WebGL2GFXDevice, gpuTexture:
|
||||
} else {
|
||||
const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 };
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, view);
|
||||
const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1);
|
||||
gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, imgSize, 0);
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
@@ -1164,7 +1168,8 @@ export function WebGL2CmdFuncResizeTexture (device: WebGL2GFXDevice, gpuTexture:
|
||||
let w = gpuTexture.width;
|
||||
let h = gpuTexture.height;
|
||||
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
|
||||
gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, view);
|
||||
const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1);
|
||||
gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, imgSize, 0);
|
||||
w = Math.max(1, w >> 1);
|
||||
h = Math.max(1, h >> 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user