2015-05-13 10:58:09 +08:00
|
|
|
/**
|
|
|
|
Copyright 2013 BlackBerry Inc.
|
2017-02-14 14:36:57 +08:00
|
|
|
Copyright (c) 2015-2017 Chukong Technologies
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2015-05-13 10:58:09 +08:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
Original file from GamePlay3D: http://gameplay3d.org
|
|
|
|
|
|
|
|
This file was modified to fit the cocos2d-x project
|
|
|
|
*/
|
|
|
|
|
2019-02-15 14:30:10 +08:00
|
|
|
#pragma once
|
2015-05-13 10:58:09 +08:00
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "base/CCRef.h"
|
2019-01-30 09:35:17 +08:00
|
|
|
#include "renderer/backend/ProgramState.h"
|
|
|
|
#include "renderer/backend/Types.h"
|
|
|
|
#include "renderer/CCPass.h"
|
2019-02-15 14:30:10 +08:00
|
|
|
#include "3d/CC3DProgramInfo.h"
|
2015-05-13 10:58:09 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
class MeshIndexData;
|
|
|
|
class VertexAttribValue;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines a binding between the vertex layout of a Mesh and the vertex
|
|
|
|
* input attributes of a vertex shader (Effect).
|
|
|
|
*
|
|
|
|
* In a perfect world, this class would always be a binding directly between
|
|
|
|
* a unique VertexFormat and an Effect, where the VertexFormat is simply the
|
|
|
|
* definition of the layout of any anonymous vertex buffer. However, the OpenGL
|
|
|
|
* mechanism for setting up these bindings is Vertex Array Objects (VAOs).
|
|
|
|
* OpenGL requires a separate VAO per vertex buffer object (VBO), rather than per
|
|
|
|
* vertex layout definition. Therefore, although we would like to define this
|
|
|
|
* binding between a VertexFormat and Effect, we are specifying the binding
|
|
|
|
* between a Mesh and Effect to satisfy the OpenGL requirement of one VAO per VBO.
|
|
|
|
*
|
|
|
|
* Note that this class still does provide a binding between a VertexFormat
|
2021-12-25 10:04:45 +08:00
|
|
|
* and an Effect, however this binding is actually a client-side binding and
|
2015-05-13 10:58:09 +08:00
|
|
|
* should only be used when writing custom code that use client-side vertex
|
|
|
|
* arrays, since it is slower than the server-side VAOs used by OpenGL
|
|
|
|
* (when creating a VertexAttribBinding between a Mesh and Effect).
|
|
|
|
*/
|
2015-11-27 14:58:18 +08:00
|
|
|
class CC_DLL VertexAttribBinding : public Ref
|
2015-05-13 10:58:09 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a new VertexAttribBinding between the given MeshVertexData and GLProgramState.
|
|
|
|
*
|
|
|
|
* If a VertexAttribBinding matching the specified MeshVertexData and GLProgramState already
|
|
|
|
* exists, it will be returned. Otherwise, a new VertexAttribBinding will
|
|
|
|
* be returned. If OpenGL VAOs are enabled, the a new VAO will be created and
|
|
|
|
* stored in the returned VertexAttribBinding, otherwise a client-side
|
|
|
|
* array of vertex attribute bindings will be stored.
|
|
|
|
*
|
|
|
|
* @param mesh The mesh.
|
|
|
|
* @param effect The effect.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2015-05-13 10:58:09 +08:00
|
|
|
* @return A VertexAttribBinding for the requested parameters.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static VertexAttribBinding* create(MeshIndexData* meshIndexData, Pass* pass, MeshCommand*);
|
2015-05-13 10:58:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds this vertex array object.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
// void bind(backend::VertexLayout &layout);
|
2015-05-13 10:58:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbinds this vertex array object.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
// void unbind();
|
2015-05-13 10:58:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the vertex attrib flags
|
|
|
|
*/
|
|
|
|
uint32_t getVertexAttribsFlags() const;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool hasAttribute(const shaderinfos::VertexKey& key) const;
|
2015-05-13 10:58:09 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
VertexAttribBinding();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
~VertexAttribBinding();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hidden copy assignment operator.
|
|
|
|
*/
|
|
|
|
VertexAttribBinding& operator=(const VertexAttribBinding&);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
bool init(MeshIndexData* meshIndexData, Pass* pass, MeshCommand*);
|
2021-12-26 23:26:34 +08:00
|
|
|
void setVertexAttribPointer(std::string_view name,
|
2021-12-25 10:04:45 +08:00
|
|
|
backend::VertexFormat type,
|
|
|
|
bool normalized,
|
|
|
|
int offset,
|
|
|
|
int flag);
|
2021-12-26 23:26:34 +08:00
|
|
|
backend::AttributeBindInfo* getVertexAttribValue(std::string_view name);
|
2015-05-13 10:58:09 +08:00
|
|
|
void parseAttributes();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-13 10:58:09 +08:00
|
|
|
MeshIndexData* _meshIndexData;
|
2019-01-30 09:35:17 +08:00
|
|
|
backend::ProgramState* _programState;
|
2019-08-15 16:51:49 +08:00
|
|
|
std::shared_ptr<backend::VertexLayout> _vertexLayout = std::make_shared<backend::VertexLayout>();
|
2021-12-26 23:26:34 +08:00
|
|
|
hlookup::string_map<backend::AttributeBindInfo> _attributes;
|
2015-05-13 10:58:09 +08:00
|
|
|
uint32_t _vertexAttribsFlags;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|