Panda3D

Loading...
Searching...
No Matches
depthWriteAttrib.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file depthWriteAttrib.cxx
10 * @author drose
11 * @date 2002-03-04
12 */
13
14#include "depthWriteAttrib.h"
15#include "graphicsStateGuardianBase.h"
16#include "dcast.h"
17#include "bamReader.h"
18#include "bamWriter.h"
19#include "datagram.h"
20#include "datagramIterator.h"
21
22 TypeHandle DepthWriteAttrib::_type_handle;
23 int DepthWriteAttrib::_attrib_slot;
24
25/**
26 * Constructs a new DepthWriteAttrib object.
27 */
28CPT(RenderAttrib) DepthWriteAttrib::
29 make(DepthWriteAttrib::Mode mode) {
30 DepthWriteAttrib *attrib = new DepthWriteAttrib(mode);
31 return return_new(attrib);
32}
33
34/**
35 * Returns a RenderAttrib that corresponds to whatever the standard default
36 * properties for render attributes of this type ought to be.
37 */
38CPT(RenderAttrib) DepthWriteAttrib::
39 make_default() {
40 return return_new(new DepthWriteAttrib);
41}
42
43/**
44 *
45 */
46 void DepthWriteAttrib::
47output(std::ostream &out) const {
48 out << get_type() << ":";
49 switch (get_mode()) {
50 case M_off:
51 out << "off";
52 break;
53 case M_on:
54 out << "on";
55 break;
56 }
57}
58
59/**
60 * Intended to be overridden by derived DepthWriteAttrib types to return a
61 * unique number indicating whether this DepthWriteAttrib is equivalent to the
62 * other one.
63 *
64 * This should return 0 if the two DepthWriteAttrib objects are equivalent, a
65 * number less than zero if this one should be sorted before the other one,
66 * and a number greater than zero otherwise.
67 *
68 * This will only be called with two DepthWriteAttrib objects whose get_type()
69 * functions return the same.
70 */
71 int DepthWriteAttrib::
72compare_to_impl(const RenderAttrib *other) const {
73 const DepthWriteAttrib *ta = (const DepthWriteAttrib *)other;
74
75 return (int)_mode - (int)ta->_mode;
76}
77
78/**
79 * Intended to be overridden by derived RenderAttrib types to return a unique
80 * hash for these particular properties. RenderAttribs that compare the same
81 * with compare_to_impl(), above, should return the same hash; RenderAttribs
82 * that compare differently should return a different hash.
83 */
84 size_t DepthWriteAttrib::
85get_hash_impl() const {
86 size_t hash = 0;
87 hash = int_hash::add_hash(hash, (int)_mode);
88 return hash;
89}
90
91/**
92 * Tells the BamReader how to create objects of type DepthWriteAttrib.
93 */
94 void DepthWriteAttrib::
95 register_with_read_factory() {
96 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
97}
98
99/**
100 * Writes the contents of this object to the datagram for shipping out to a
101 * Bam file.
102 */
103 void DepthWriteAttrib::
104 write_datagram(BamWriter *manager, Datagram &dg) {
105 RenderAttrib::write_datagram(manager, dg);
106
107 dg.add_int8(_mode);
108}
109
110/**
111 * This function is called by the BamReader's factory when a new object of
112 * type DepthWriteAttrib is encountered in the Bam file. It should create the
113 * DepthWriteAttrib and extract its information from the file.
114 */
115 TypedWritable *DepthWriteAttrib::
116make_from_bam(const FactoryParams &params) {
117 DepthWriteAttrib *attrib = new DepthWriteAttrib;
118 DatagramIterator scan;
119 BamReader *manager;
120
121 parse_params(params, scan, manager);
122 attrib->fillin(scan, manager);
123
124 return attrib;
125}
126
127/**
128 * This internal function is called by make_from_bam to read in all of the
129 * relevant data from the BamFile for the new DepthWriteAttrib.
130 */
131 void DepthWriteAttrib::
132fillin(DatagramIterator &scan, BamReader *manager) {
133 RenderAttrib::fillin(scan, manager);
134
135 _mode = (Mode)scan.get_int8();
136}
bamReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
parse_params
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition bamReader.I:275
bamWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
BamReader::get_factory
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
DatagramIterator::get_int8
int8_t get_int8()
Extracts a signed 8-bit integer.
Definition datagramIterator.I:56
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
Datagram::add_int8
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
Definition datagram.I:42
DepthWriteAttrib
Enables or disables writing to the depth buffer.
Definition depthWriteAttrib.h:26
DepthWriteAttrib::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type DepthWriteAttrib.
Definition depthWriteAttrib.cxx:95
DepthWriteAttrib::make
static ConstPointerTo< RenderAttrib > make(Mode mode)
Constructs a new DepthWriteAttrib object.
Definition depthWriteAttrib.cxx:29
DepthWriteAttrib::make_default
static ConstPointerTo< RenderAttrib > make_default()
Returns a RenderAttrib that corresponds to whatever the standard default properties for render attrib...
Definition depthWriteAttrib.cxx:39
DepthWriteAttrib::get_mode
get_mode
Returns the depth write mode.
Definition depthWriteAttrib.h:43
DepthWriteAttrib::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition depthWriteAttrib.cxx:104
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition factoryParams.h:36
Factory::register_factory
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition factory.I:73
RenderAttrib
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition renderAttrib.h:51
RenderAttrib::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition renderAttrib.cxx:527
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition typedWritable.h:35
integer_hash< int >::add_hash
static size_t add_hash(size_t start, const int &key)
datagramIterator.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
datagram.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
dcast.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
depthWriteAttrib.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
graphicsStateGuardianBase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.