Panda3D
Loading...
Searching...
No Matches
gpuCommand.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 "gpuCommand.h"
28
29#include <iostream>
30#include <iomanip>
31#include <stdlib.h>
32
33
34NotifyCategoryDef(gpucommand, "");
35
36/**
37 * @brief Constructs a new GPUCommand with the given command type.
38 * @details This will construct a new GPUCommand of the given command type.
39 * The command type should be of GPUCommand::CommandType, and determines
40 * what data the GPUCommand contains, and how it will be handled.
41 *
42 * @param command_type The type of the GPUCommand
43 */
45 _command_type = command_type;
46 _current_index = 0;
47 memset(_data, 0x0, sizeof(float) * GPU_COMMAND_ENTRIES);
48
49 // Store the command type as the first entry
50 push_int(command_type);
51}
52
53/**
54 * @brief Prints out the GPUCommand to the console
55 * @details This method prints the type, size, and data of the GPUCommand to the
56 * console. This helps for debugging the contents of the GPUCommand. Keep
57 * in mind that integers might be shown in their binary float representation,
58 * depending on the setting in the GPUCommand::convert_int_to_float method.
59 */
60void GPUCommand::write(std::ostream &out) const {
61 out << "GPUCommand(type=" << _command_type << ", size=" << _current_index << ", data = {" << std::endl;
62 for (size_t k = 0; k < GPU_COMMAND_ENTRIES; ++k) {
63 out << std::setw(12) << std::fixed << std::setprecision(5) << _data[k] << " ";
64 if (k % 6 == 5 || k == GPU_COMMAND_ENTRIES - 1) out << std::endl;
65 }
66 out << "})" << std::endl;
67}
68
69/**
70 * @brief Writes the GPU command to a given target.
71 * @details This method writes all the data of the GPU command to a given target.
72 * The target should be a pointer to memory being big enough to hold the
73 * data. Presumably #dest will be a handle to texture memory.
74 * The command_index controls the offset where the data will be written
75 * to.
76 *
77 * @param dest Handle to the memory to write the command to
78 * @param command_index Offset to write the command to. The command will write
79 * its data to command_index * GPU_COMMAND_ENTRIES. When writing
80 * the GPUCommand in a GPUCommandList, the command_index will
81 * most likely be the index of the command in the list.
82 */
83void GPUCommand::write_to(const PTA_uchar &dest, size_t command_index) {
84 size_t command_size = GPU_COMMAND_ENTRIES * sizeof(float);
85 size_t offset = command_index * command_size;
86 memcpy(dest.p() + offset, &_data, command_size);
87}
GPUCommand(CommandType command_type)
Constructs a new GPUCommand with the given command type.
void write(std::ostream &out) const
Prints out the GPUCommand to the console.
void write_to(const PTA_uchar &dest, size_t command_index)
Writes the GPU command to a given target.
CommandType
The different types of GPUCommands.
Definition gpuCommand.h:54
void push_int(int v)
RenderPipeline.
Definition gpuCommand.I:37