Panda3D
Loading...
Searching...
No Matches
gpuCommand.h
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#ifndef GPUCOMMAND_H
28#define GPUCOMMAND_H
29
30#include "pandabase.h"
31#include "luse.h"
32
33NotifyCategoryDecl(gpucommand, EXPORT_CLASS, EXPORT_TEMPL);
34
35#define GPU_COMMAND_ENTRIES 32
36
37// Packs integers by storing their binary representation in floats
38// This only works if the command and light buffer is 32bit floating point.
39#define PACK_INT_AS_FLOAT 0
40
41/**
42 * @brief Class for storing data to be transferred to the GPU.
43 * @details This class can be seen like a packet, to be transferred to the GPU.
44 * It has a command type, which tells the GPU what to do once it recieved this
45 * "packet". It stores a limited amount of floating point components.
46 */
48PUBLISHED:
49 /**
50 * The different types of GPUCommands. Each type has a special case in
51 * the command queue processor. When adding new types, those need to
52 * be handled in the command target, too.
53 */
55 CMD_invalid = 0,
56 CMD_store_light = 1,
57 CMD_remove_light = 2,
58 CMD_store_source = 3,
59 CMD_remove_sources = 4,
60 };
61
62 GPUCommand(CommandType command_type);
63
64 inline void push_int(int v);
65 inline void push_float(float v);
66 inline void push_vec3(const LVecBase3 &v);
67 inline void push_vec3(const LVecBase3i &v);
68 inline void push_vec4(const LVecBase4 &v);
69 inline void push_vec4(const LVecBase4i &v);
70 inline void push_mat3(const LMatrix3 &v);
71 inline void push_mat4(const LMatrix4 &v);
72
73 inline static bool get_uses_integer_packing();
74
75 void write_to(const PTA_uchar &dest, size_t command_index);
76 void write(std::ostream &out) const;
77
78private:
79
80 inline float convert_int_to_float(int v) const;
81
82 CommandType _command_type;
83 size_t _current_index;
84 float _data[GPU_COMMAND_ENTRIES];
85};
86
87#include "gpuCommand.I"
88
89#endif // GPUCOMMAND_H
Class for storing data to be transferred to the GPU.
Definition gpuCommand.h:47
void push_vec4(const LVecBase4 &v)
Appends a 4-component floating point vector to the GPUCommand.
Definition gpuCommand.I:120
GPUCommand(CommandType command_type)
Constructs a new GPUCommand with the given command type.
void push_mat4(const LMatrix4 &v)
Appends a floating point 4x4 matrix to the GPUCommand.
Definition gpuCommand.I:166
void push_float(float v)
Appends a float to the GPUCommand.
Definition gpuCommand.I:75
void write(std::ostream &out) const
Prints out the GPUCommand to the console.
void push_vec3(const LVecBase3 &v)
Appends a 3-component floating point vector to the GPUCommand.
Definition gpuCommand.I:91
void push_mat3(const LMatrix3 &v)
Appends a floating point 3x3 matrix to the GPUCommand.
Definition gpuCommand.I:150
static bool get_uses_integer_packing()
Returns whether integers are packed as floats.
Definition gpuCommand.I:183
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.