axmol/core/3d/VertexAttribBinding.h

124 lines
4.1 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/**
Copyright 2013 BlackBerry Inc.
Copyright (c) 2015-2017 Chukong Technologies
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
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
*/
#pragma once
#include <unordered_map>
#include "base/Ref.h"
2019-11-23 20:27:39 +08:00
#include "renderer/backend/ProgramState.h"
#include "renderer/backend/Types.h"
#include "renderer/Pass.h"
#include "3d/3DProgramInfo.h"
2019-11-23 20:27:39 +08:00
NS_AX_BEGIN
2019-11-23 20:27:39 +08:00
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
2019-11-23 20:27:39 +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).
*/
2022-07-16 10:43:05 +08:00
class AX_DLL VertexAttribBinding : public Ref
2019-11-23 20:27:39 +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
*
2019-11-23 20:27:39 +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*);
2019-11-23 20:27:39 +08:00
/**
* Binds this vertex array object.
*/
2021-12-25 10:04:45 +08:00
// void bind(backend::VertexLayout &layout);
2019-11-23 20:27:39 +08:00
/**
* Unbinds this vertex array object.
*/
2021-12-25 10:04:45 +08:00
// void unbind();
2019-11-23 20:27:39 +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;
2019-11-23 20:27:39 +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*);
void setVertexAttribPointer(VertexLayout* vertexLayout, std::string_view name,
2021-12-25 10:04:45 +08:00
backend::VertexFormat type,
bool normalized,
int offset,
int flag);
const backend::AttributeBindInfo* getVertexAttribValue(std::string_view name);
2019-11-23 20:27:39 +08:00
void parseAttributes();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
MeshIndexData* _meshIndexData;
backend::ProgramState* _programState;
uint32_t _vertexAttribsFlags;
};
NS_AX_END