axmol/core/renderer/CCQuadCommand.h

88 lines
2.8 KiB
C
Raw Normal View History

2013-12-18 10:12:15 +08:00
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2013-12-18 10:12:15 +08:00
2022-01-04 12:36:20 +08:00
https://adxeproject.github.io/
2013-12-18 10:12:15 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef _CC_QUADCOMMAND_H_
#define _CC_QUADCOMMAND_H_
#include <vector>
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
#include "renderer/CCTrianglesCommand.h"
/**
* @addtogroup renderer
* @{
*/
NS_CC_BEGIN
2021-12-25 10:04:45 +08:00
/**
Command used to render one or more Quads, similar to TrianglesCommand.
Every QuadCommand will have generate material ID by give textureID, glProgramState, Blend function
if the material id is the same, these QuadCommands could be batched to save draw call.
*/
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
class CC_DLL QuadCommand : public TrianglesCommand
{
public:
/**Constructor.*/
QuadCommand();
/**Destructor.*/
~QuadCommand();
2021-12-25 10:04:45 +08:00
/** Initializes the command.
@param globalOrder GlobalZOrder of the command.
2019-03-13 14:11:40 +08:00
@param texture The texture used in the command.
@param blendType Blend function for the command.
@param quads Rendered quads for the command.
@param quadCount The number of quads when rendering.
@param mv ModelView matrix for the command.
@param flags to indicate that the command is using 3D rendering or not.
*/
2021-12-25 10:04:45 +08:00
void init(float globalOrder,
Texture2D* texture,
const BlendFunc& blendType,
V3F_C4B_T2F_Quad* quads,
ssize_t quadCount,
const Mat4& mv,
uint32_t flags);
protected:
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
void reIndex(int indices);
int _indexSize;
2019-06-05 17:58:33 +08:00
std::vector<uint16_t*> _ownedIndices;
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
// shared across all instances
static int __indexCapacity;
2019-06-05 17:58:33 +08:00
static uint16_t* __indices;
2014-06-24 11:04:17 +08:00
};
NS_CC_END
/**
end of support group
@}
*/
2021-12-25 10:04:45 +08:00
#endif //_CC_QUADCOMMAND_H_