From 9ec52a9ddaf7bb85a5757efcd8a673082ffc7b21 Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Wed, 2 Jan 2019 18:03:51 +0800 Subject: [PATCH] remove GFXVertexSemantic --- cocos/gfx/gfx-define.ts | 82 ++++++++++++---------------- cocos/gfx/input-assembler.ts | 4 +- cocos/gfx/webgl/webgl-commands.ts | 65 +++------------------- cocos/gfx/webgl/webgl-gpu-objects.ts | 3 +- cocos/pipeline/index.ts | 1 + cocos/pipeline/render-pipeline.ts | 8 +-- 6 files changed, 51 insertions(+), 112 deletions(-) create mode 100644 cocos/pipeline/index.ts diff --git a/cocos/gfx/gfx-define.ts b/cocos/gfx/gfx-define.ts index 0c986970ef..61c41f70c6 100644 --- a/cocos/gfx/gfx-define.ts +++ b/cocos/gfx/gfx-define.ts @@ -22,27 +22,16 @@ export const GFX_MAX_VERTEX_ATTRIBUTES: number = 8; export const GFX_MAX_TEXTURE_UNITS: number = 16; export const GFX_MAX_ATTACHMENTS: number = 4; -export const GFX_ATTRIBUTE_POSITION = "a_position"; -export const GFX_ATTRIBUTE_POSITION1 = "a_position1"; -export const GFX_ATTRIBUTE_POSITION2 = "a_position2"; -export const GFX_ATTRIBUTE_POSITION3 = "a_position3"; -export const GFX_ATTRIBUTE_COLOR = "a_color"; -export const GFX_ATTRIBUTE_COLOR1 = "a_color1"; -export const GFX_ATTRIBUTE_COLOR2 = "a_color2"; -export const GFX_ATTRIBUTE_COLOR3 = "a_color3"; -export const GFX_ATTRIBUTE_NORMAL = "a_normal"; -export const GFX_ATTRIBUTE_NORMAL1 = "a_normal1"; -export const GFX_ATTRIBUTE_NORMAL2 = "a_normal2"; -export const GFX_ATTRIBUTE_NORMAL3 = "a_normal3"; -export const GFX_ATTRIBUTE_TANGENT = "a_tangent"; -export const GFX_ATTRIBUTE_BINORMAL = "a_binormal"; -export const GFX_ATTRIBUTE_TEXCOORD = "a_texCoord"; -export const GFX_ATTRIBUTE_TEXCOORD1 = "a_texCoord1"; -export const GFX_ATTRIBUTE_TEXCOORD2 = "a_texCoord2"; -export const GFX_ATTRIBUTE_TEXCOORD3 = "a_texCoord3"; -export const GFX_ATTRIBUTE_JOINTS = "a_joints"; -export const GFX_ATTRIBUTE_WEIGHTS = "a_weights"; -export const GFX_ATTRIBUTE_SV_INSTANCE_ID = "sv_instanceID"; +export const GFX_ATTRIBUTE_POSITION = "a_position"; // 0 +export const GFX_ATTRIBUTE_COLOR = "a_color"; // 1 +export const GFX_ATTRIBUTE_COLOR1 = "a_color1"; // 2 +export const GFX_ATTRIBUTE_NORMAL = "a_normal"; // 3 +export const GFX_ATTRIBUTE_TANGENT = "a_tangent"; // 4 +export const GFX_ATTRIBUTE_BINORMAL = "a_binormal"; // 5 +export const GFX_ATTRIBUTE_TEXCOORD = "a_texCoord"; // 6 +export const GFX_ATTRIBUTE_TEXCOORD1 = "a_texCoord1"; // 7 +export const GFX_ATTRIBUTE_JOINTS = "a_joints"; // 8 +export const GFX_ATTRIBUTE_WEIGHTS = "a_weights"; // 9 export enum GFXType { UNKNOWN, @@ -202,31 +191,6 @@ export enum GFXFormat { PVRTC2_4BPP, }; -export enum GFXVertexSemantic { - UNKNOWN, - POSITION, - POSITION1, - POSITION2, - POSITION3, - COLOR, - COLOR1, - COLOR2, - COLOR3, - NORMAL, - NORMAL1, - NORMAL2, - NORMAL3, - TANGENT, - BINORMAL, - TEXCOORD, - TEXCOORD1, - TEXCOORD2, - TEXCOORD3, - JOINTS, - WEIGHTS, - SV_INSTANCE_ID, -}; - export enum GFXBufferUsageBit { NONE = 0, TRANSFER_SRC = 0x1, @@ -730,3 +694,29 @@ export function GFXGetTypeSize(type: GFXType): number { } } } + +export function GFXGetAttributeBinding(name: string) : number { + if (name === GFX_ATTRIBUTE_POSITION) { + return 20; + } else if (name === GFX_ATTRIBUTE_COLOR) { + return 21; + } else if (name === GFX_ATTRIBUTE_COLOR1) { + return 22; + } else if (name === GFX_ATTRIBUTE_NORMAL) { + return 23; + } else if (name === GFX_ATTRIBUTE_TANGENT) { + return 24; + } else if (name === GFX_ATTRIBUTE_BINORMAL) { + return 25; + } else if (name === GFX_ATTRIBUTE_TEXCOORD) { + return 26; + } else if (name === GFX_ATTRIBUTE_TEXCOORD1) { + return 27; + } else if (name === GFX_ATTRIBUTE_JOINTS) { + return 28; + } else if (name === GFX_ATTRIBUTE_WEIGHTS) { + return 29; + } else { + return -1; + } +} diff --git a/cocos/gfx/input-assembler.ts b/cocos/gfx/input-assembler.ts index 7ad9707570..9d54ee9ace 100644 --- a/cocos/gfx/input-assembler.ts +++ b/cocos/gfx/input-assembler.ts @@ -1,10 +1,10 @@ import { GFXDevice } from './device'; -import { GFXFormat, GFXVertexSemantic } from './gfx-define'; +import { GFXFormat } from './gfx-define'; import { GFXBuffer } from './buffer'; export interface GFXInputAttribute { + binding?: number; name: string; - semantic: GFXVertexSemantic; format: GFXFormat; stream?: number; isInstanced?: boolean; diff --git a/cocos/gfx/webgl/webgl-commands.ts b/cocos/gfx/webgl/webgl-commands.ts index bc0fa08fc1..f9b2826577 100644 --- a/cocos/gfx/webgl/webgl-commands.ts +++ b/cocos/gfx/webgl/webgl-commands.ts @@ -1,6 +1,6 @@ import { WebGLGPUBuffer, WebGLGPUTexture, WebGLGPUInputAssembler, WebGLGPUFramebuffer, WebGLGPUShader, WebGLGPUInput, WebGLAttrib, WebGLGPUPipelineState, WebGLGPUUniformBlock, WebGLGPUBindingLayout, WebGLGPUUniform, WebGLGPUUniformSampler } from "./webgl-gpu-objects"; import { WebGLGFXDevice } from "./webgl-device"; -import { GFXFormatInfos, GFXFormat, WebGLEXT, GFXType, GFX_MAX_VERTEX_ATTRIBUTES, GFXFormatSize, GFXColor, GFXViewport, GFXRect, GFXBindingType, GFXBufferTextureCopy, GFXColorMask, GFXCullMode, GFXShaderType, GFXTextureViewType, GFXTextureLayout, GFXLoadOp, GFXTextureFlagBit, GFXMemoryUsageBit, GFXBufferUsageBit, GFX_ATTRIBUTE_POSITION, GFXVertexSemantic, GFX_ATTRIBUTE_POSITION1, GFX_ATTRIBUTE_POSITION2, GFX_ATTRIBUTE_POSITION3, GFX_ATTRIBUTE_COLOR, GFX_ATTRIBUTE_COLOR1, GFX_ATTRIBUTE_COLOR2, GFX_ATTRIBUTE_COLOR3, GFX_ATTRIBUTE_NORMAL, GFX_ATTRIBUTE_NORMAL1, GFX_ATTRIBUTE_NORMAL2, GFX_ATTRIBUTE_NORMAL3, GFX_ATTRIBUTE_TEXCOORD, GFX_ATTRIBUTE_TEXCOORD1, GFX_ATTRIBUTE_TEXCOORD2, GFX_ATTRIBUTE_TEXCOORD3, GFX_ATTRIBUTE_JOINTS, GFX_ATTRIBUTE_WEIGHTS, GFX_ATTRIBUTE_SV_INSTANCE_ID, GFX_ATTRIBUTE_TANGENT, GFX_ATTRIBUTE_BINORMAL } from "../gfx-define"; +import { GFXFormatInfos, GFXFormat, WebGLEXT, GFXType, GFX_MAX_VERTEX_ATTRIBUTES, GFXFormatSize, GFXColor, GFXRect, GFXBindingType, GFXBufferTextureCopy, GFXColorMask, GFXCullMode, GFXShaderType, GFXTextureViewType, GFXTextureLayout, GFXLoadOp, GFXTextureFlagBit, GFXMemoryUsageBit, GFXBufferUsageBit, GFXGetAttributeBinding } from "../gfx-define"; import { WebGLGFXCommandAllocator } from "./webgl-command-allocator"; import { WebGLTexUnit } from "./webgl-state-cache"; @@ -818,75 +818,24 @@ export function WebGLCmdFuncCreateShader(device: WebGLGFXDevice, gpuShader: WebG varName = info.name; } - let semantic = GFXVertexSemantic.UNKNOWN; - let glLoc = -1; + let glLoc = GFXGetAttributeBinding(varName); - if (varName === GFX_ATTRIBUTE_POSITION) { - semantic = GFXVertexSemantic.POSITION; - } else if (varName === GFX_ATTRIBUTE_POSITION1) { - semantic = GFXVertexSemantic.POSITION1; - } else if (varName === GFX_ATTRIBUTE_POSITION2) { - semantic = GFXVertexSemantic.POSITION2; - } else if (varName === GFX_ATTRIBUTE_POSITION3) { - semantic = GFXVertexSemantic.POSITION3; - } else if (varName === GFX_ATTRIBUTE_COLOR) { - semantic = GFXVertexSemantic.COLOR; - } else if (varName === GFX_ATTRIBUTE_COLOR1) { - semantic = GFXVertexSemantic.COLOR1; - } else if (varName === GFX_ATTRIBUTE_COLOR2) { - semantic = GFXVertexSemantic.COLOR2; - } else if (varName === GFX_ATTRIBUTE_COLOR3) { - semantic = GFXVertexSemantic.COLOR3; - } else if (varName === GFX_ATTRIBUTE_NORMAL) { - semantic = GFXVertexSemantic.NORMAL; - } else if (varName === GFX_ATTRIBUTE_NORMAL1) { - semantic = GFXVertexSemantic.NORMAL1; - } else if (varName === GFX_ATTRIBUTE_NORMAL2) { - semantic = GFXVertexSemantic.NORMAL2; - } else if (varName === GFX_ATTRIBUTE_NORMAL3) { - semantic = GFXVertexSemantic.NORMAL3; - } else if (varName === GFX_ATTRIBUTE_TANGENT) { - semantic = GFXVertexSemantic.TANGENT; - } else if (varName === GFX_ATTRIBUTE_BINORMAL) { - semantic = GFXVertexSemantic.BINORMAL; - } else if (varName === GFX_ATTRIBUTE_TEXCOORD) { - semantic = GFXVertexSemantic.TEXCOORD; - } else if (varName === GFX_ATTRIBUTE_TEXCOORD1) { - semantic = GFXVertexSemantic.TEXCOORD1; - } else if (varName === GFX_ATTRIBUTE_TEXCOORD2) { - semantic = GFXVertexSemantic.TEXCOORD2; - } else if (varName === GFX_ATTRIBUTE_TEXCOORD3) { - semantic = GFXVertexSemantic.TEXCOORD3; - } else if (varName === GFX_ATTRIBUTE_JOINTS) { - semantic = GFXVertexSemantic.JOINTS; - } else if (varName === GFX_ATTRIBUTE_WEIGHTS) { - semantic = GFXVertexSemantic.WEIGHTS; - } else if (varName === GFX_ATTRIBUTE_SV_INSTANCE_ID) { - semantic = GFXVertexSemantic.SV_INSTANCE_ID; - } else { - console.error("Unsupported vertex attribute semantic."); - } - - if(semantic !== GFXVertexSemantic.UNKNOWN) { - glLoc = semantic; + if(glLoc >= 0) { gl.bindAttribLocation(gpuShader.glProgram, glLoc, varName); - - } else { - glLoc = -1; + }/* else { //glLoc = gl.getAttribLocation(gpuShader.glProgram, info.name); - } + }*/ let type = WebGLTypeToGFXType(info.type); let stride = WebGLGetTypeSize(info.type); gpuShader.glInputs[i] = { - binding: -1, + binding: glLoc, name: varName, type: type, stride: stride, count: info.size, size: stride * info.size, - semantic: semantic, glType: info.type, glLoc: glLoc, @@ -1063,7 +1012,7 @@ export function WebGLCmdFuncCreateInputAssember(device: WebGLGFXDevice, gpuInput gpuInputAssembler.glAttribs[i] = { glBuffer: gpuBuffer.glBuffer, - glLoc: attrib.semantic, + glLoc: attrib.binding? attrib.binding : -1, glType: glType, size: size, count: GFXFormatInfos[attrib.format].count, diff --git a/cocos/gfx/webgl/webgl-gpu-objects.ts b/cocos/gfx/webgl/webgl-gpu-objects.ts index 9c3258c502..dc33439b9b 100644 --- a/cocos/gfx/webgl/webgl-gpu-objects.ts +++ b/cocos/gfx/webgl/webgl-gpu-objects.ts @@ -1,4 +1,4 @@ -import { GFXFormat, GFXType, GFXTextureType, GFXTextureUsage, GFXTextureUsageBit, GFXTextureFlags, GFXTextureFlagBit, GFXShaderType, GFXBindingType, GFXTextureViewType, GFXBufferUsageBit, GFXMemoryUsageBit, GFXMemoryUsage, GFXBufferUsage, GFXVertexSemantic } from "../gfx-define"; +import { GFXFormat, GFXType, GFXTextureType, GFXTextureUsage, GFXTextureUsageBit, GFXTextureFlags, GFXTextureFlagBit, GFXShaderType, GFXBindingType, GFXTextureViewType, GFXBufferUsageBit, GFXMemoryUsageBit, GFXMemoryUsage, GFXBufferUsage } from "../gfx-define"; import { GFXColorAttachment, GFXDepthStencilAttachment } from "../render-pass"; import { GFXRasterizerState, GFXDepthStencilState, GFXBlendState } from "../pipeline-state"; import { GFXInputAttribute } from "../input-assembler"; @@ -126,7 +126,6 @@ export class WebGLGPUInput { stride: number = 0; count: number = 0; size: number = 0; - semantic: GFXVertexSemantic = GFXVertexSemantic.UNKNOWN; glType: GLenum = 0; glLoc: GLint = 0; diff --git a/cocos/pipeline/index.ts b/cocos/pipeline/index.ts new file mode 100644 index 0000000000..3bdeba37ab --- /dev/null +++ b/cocos/pipeline/index.ts @@ -0,0 +1 @@ +import "./render-view"; diff --git a/cocos/pipeline/render-pipeline.ts b/cocos/pipeline/render-pipeline.ts index fb09846e29..64c8fcbc69 100644 --- a/cocos/pipeline/render-pipeline.ts +++ b/cocos/pipeline/render-pipeline.ts @@ -1,11 +1,11 @@ import { RenderView } from "./render-view"; import { RenderFlow, RenderFlowInfo } from "./render-flow"; import { Root } from "../core/root"; -import { GFXRenderPass, GFXRenderPassInfo } from "../gfx/render-pass"; +import { GFXRenderPass } from "../gfx/render-pass"; import { GFXDevice } from "../gfx/device"; import { GFXBuffer } from "../gfx/buffer"; import { GFXInputAssembler, GFXInputAttribute } from "../gfx/input-assembler"; -import { GFXBufferUsageBit, GFXMemoryUsageBit, GFXVertexSemantic, GFXFormat } from "../gfx/gfx-define"; +import { GFXBufferUsageBit, GFXMemoryUsageBit, GFXFormat } from "../gfx/gfx-define"; export enum RenderPassStage { FORWARD = 0, @@ -147,8 +147,8 @@ export abstract class RenderPipeline { // create input assembler let attributes: GFXInputAttribute[] = [ - {name: "a_position", semantic: GFXVertexSemantic.POSITION, format: GFXFormat.RG32F}, - {name: "a_texCoord", semantic: GFXVertexSemantic.TEXCOORD, format: GFXFormat.RG32F}, + {name: "a_position", format: GFXFormat.RG32F}, + {name: "a_texCoord", format: GFXFormat.RG32F}, ]; this._quadIA = this._device.createInputAssembler({