Panda3D
gpuCommandList.cxx
1 /**
2  *
3  * RenderPipeline
4  *
5  * Copyright (c) 2014-2016 tobspr <tobias.springer1@gmail.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  */
26 
27 #include "gpuCommandList.h"
28 
29 
30 /**
31  * @brief Constructs a new GPUCommandList
32  * @details This constructs a new GPUCommandList. By default, there are no commands
33  * in the list.
34  */
36 }
37 
38 /**
39  * @brief Pushes a GPUCommand to the command list.
40  * @details This adds a new GPUCommand to the list of commands to be processed.
41  *
42  * @param cmd The command to add
43  */
45  _commands.push(cmd);
46 }
47 
48 /**
49  * @brief Returns the number of commands in this list.
50  * @details This returns the amount of commands which are currently stored in this
51  * list, and are waiting to get processed.
52  * @return Amount of commands
53  */
54 size_t GPUCommandList::get_num_commands() {
55  return _commands.size();
56 }
57 
58 /**
59  * @brief Writes the first n-commands to a destination.
60  * @details This takes the first #limit commands, and writes them to the
61  * destination using GPUCommand::write_to. See GPUCommand::write_to for
62  * further information about #dest. The limit controls after how much
63  * commands the processing will be stopped. All commands which got processed
64  * will get removed from the list.
65  *
66  * @param dest Destination to write to, see GPUCommand::write_to
67  * @param limit Maximum amount of commands to process
68  *
69  * @return Amount of commands processed, between 0 and #limit.
70  */
71 size_t GPUCommandList::write_commands_to(const PTA_uchar &dest, size_t limit) {
72  size_t num_commands_written = 0;
73 
74  while (num_commands_written < limit && !_commands.empty()) {
75  // Write the first command to the stream, and delete it afterwards
76  _commands.front().write_to(dest, num_commands_written);
77  _commands.pop();
78  num_commands_written ++;
79  }
80 
81  return num_commands_written;
82 }
GPUCommandList()
RenderPipeline.
size_t write_commands_to(const PTA_uchar &dest, size_t limit=32)
Writes the first n-commands to a destination.
Class for storing data to be transferred to the GPU.
Definition: gpuCommand.h:47
void add_command(const GPUCommand &cmd)
Pushes a GPUCommand to the command list.