added a texgenattrib for spheremap

This commit is contained in:
Asad M. Zaman 2004-07-02 00:12:40 +00:00
parent 385876b74a
commit b05e24e913
6 changed files with 390 additions and 0 deletions

View File

@ -89,6 +89,7 @@
texMatrixAttrib.I texMatrixAttrib.h \
textureApplyAttrib.I textureApplyAttrib.h \
textureAttrib.I textureAttrib.h \
texGenAttrib.I texGenAttrib.h \
textureCollection.I textureCollection.h \
transformState.I transformState.h \
transparencyAttrib.I transparencyAttrib.h \
@ -177,6 +178,7 @@
texMatrixAttrib.cxx \
textureApplyAttrib.cxx \
textureAttrib.cxx \
texGenAttrib.cxx \
textureCollection.cxx \
transformState.cxx \
transparencyAttrib.cxx \
@ -262,6 +264,7 @@
texMatrixAttrib.I texMatrixAttrib.h \
textureApplyAttrib.I textureApplyAttrib.h \
textureAttrib.I textureAttrib.h \
texGenAttrib.I texGenAttrib.h \
textureCollection.I textureCollection.h \
transformState.I transformState.h \
transparencyAttrib.I transparencyAttrib.h \

View File

@ -80,6 +80,7 @@
#include "texMatrixAttrib.h"
#include "textureApplyAttrib.h"
#include "textureAttrib.h"
#include "texGenAttrib.h"
#include "transformState.h"
#include "transparencyAttrib.h"
#include "nodePathLerps.h"
@ -231,6 +232,7 @@ init_libpgraph() {
TexMatrixAttrib::init_type();
TextureApplyAttrib::init_type();
TextureAttrib::init_type();
TexGenAttrib::init_type();
TransformState::init_type();
TransparencyAttrib::init_type();
PosLerpFunctor::init_type();
@ -282,6 +284,7 @@ init_libpgraph() {
TexMatrixAttrib::register_with_read_factory();
TextureApplyAttrib::register_with_read_factory();
TextureAttrib::register_with_read_factory();
TexGenAttrib::register_with_read_factory();
TransformState::register_with_read_factory();
TransparencyAttrib::register_with_read_factory();

View File

@ -38,6 +38,7 @@
#include "texMatrixAttrib.cxx"
#include "textureApplyAttrib.cxx"
#include "textureAttrib.cxx"
#include "texGenAttrib.cxx"
#include "textureCollection.cxx"
#include "transformState.cxx"
#include "transparencyAttrib.cxx"

66
panda/src/pgraph/texGenAttrib.I Executable file
View File

@ -0,0 +1,66 @@
// Filename: texGenAttrib.I
// Created by: masad (21Jun04)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::Constructor
// Access: Private
// Description: Use TexGenAttrib::make() to construct a new
// TexGenAttrib object.
////////////////////////////////////////////////////////////////////
INLINE TexGenAttrib::
TexGenAttrib(TexGenAttrib::Mode mode) :
_mode(mode)
{
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::is_off
// Access: Published
// Description: Returns true if the TexGenAttrib is an 'off'
// TexGenAttrib, indicating that it should disable
// texturing.
////////////////////////////////////////////////////////////////////
INLINE bool TexGenAttrib::
is_off() const {
return _mode == M_nothing;
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::get_texture
// Access: Published
// Description: If the TexGenAttrib is not an 'off' TexGenAttrib,
// returns the texture that is associated. Otherwise,
// return NULL.
////////////////////////////////////////////////////////////////////
INLINE TexGenAttrib::Mode TexGenAttrib::
get_mode() const {
return _mode;
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::get_texture
// Access: Published
// Description: If the TexGenAttrib is not an 'off' TexGenAttrib,
// returns the texture that is associated. Otherwise,
// return NULL.
////////////////////////////////////////////////////////////////////
INLINE Texture *TexGenAttrib::
get_texture() const {
return _texture;
}

222
panda/src/pgraph/texGenAttrib.cxx Executable file
View File

@ -0,0 +1,222 @@
// Filename: texGenAttrib.cxx
// Created by: masad (21Jun04)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "texGenAttrib.h"
#include "texturePool.h"
#include "graphicsStateGuardianBase.h"
#include "bamReader.h"
#include "bamWriter.h"
#include "datagram.h"
#include "datagramIterator.h"
TypeHandle TexGenAttrib::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::make
// Access: Published, Static
// Description: Constructs a new TexGenAttrib object suitable for
// rendering the indicated texture onto geometry.
////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) TexGenAttrib::
make(Mode mode) {
TexGenAttrib *attrib = new TexGenAttrib(mode);
attrib->_texture = TexturePool::load_texture("/usr/masad/player/pmockup/maps/moon-card.rgb", 1);
if (attrib->_texture)
pgraph_cat.debug() << *(attrib->_texture) << endl;
else
return (TexGenAttrib *)NULL;
return return_new(attrib);
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::make_off
// Access: Published, Static
// Description: Constructs a new TexGenAttrib object suitable for
// rendering untextured geometry.
////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) TexGenAttrib::
make_off() {
TexGenAttrib *attrib = new TexGenAttrib;
return return_new(attrib);
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::issue
// Access: Public, Virtual
// Description: Calls the appropriate method on the indicated GSG
// to issue the graphics commands appropriate to the
// given attribute. This is normally called
// (indirectly) only from
// GraphicsStateGuardian::set_state() or modify_state().
////////////////////////////////////////////////////////////////////
void TexGenAttrib::
issue(GraphicsStateGuardianBase *gsg) const {
gsg->issue_tex_gen(this);
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::output
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void TexGenAttrib::
output(ostream &out) const {
out << get_type() << ":";
if (is_off()) {
out << "(off)";
} else {
switch (get_mode()) {
case M_spherical:
out << "spherical";
break;
case M_cubic:
out << "cubic";
break;
}
//out << _texture->get_name();
}
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::compare_to_impl
// Access: Protected, Virtual
// Description: Intended to be overridden by derived TexGenAttrib
// types to return a unique number indicating whether
// this TexGenAttrib is equivalent to the other one.
//
// This should return 0 if the two TexGenAttrib objects
// are equivalent, a number less than zero if this one
// should be sorted before the other one, and a number
// greater than zero otherwise.
//
// This will only be called with two TexGenAttrib
// objects whose get_type() functions return the same.
////////////////////////////////////////////////////////////////////
int TexGenAttrib::
compare_to_impl(const RenderAttrib *other) const {
const TexGenAttrib *ta;
DCAST_INTO_R(ta, other, 0);
// Comparing pointers by subtraction is problematic. Instead of
// doing this, we'll just depend on the built-in != and < operators
// for comparing pointers.
return (int)_mode - (int)ta->_mode;
/*
if (_texture != ta->_texture) {
return _texture < ta->_texture ? -1 : 1;
}
return 0;
*/
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::make_default_impl
// Access: Protected, Virtual
// Description: Intended to be overridden by derived TexGenAttrib
// types to specify what the default property for a
// TexGenAttrib of this type should be.
//
// This should return a newly-allocated TexGenAttrib of
// the same type that corresponds to whatever the
// standard default for this kind of TexGenAttrib is.
////////////////////////////////////////////////////////////////////
RenderAttrib *TexGenAttrib::
make_default_impl() const {
return new TexGenAttrib;
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::register_with_read_factory
// Access: Public, Static
// Description: Tells the BamReader how to create objects of type
// TexGenAttrib.
////////////////////////////////////////////////////////////////////
void TexGenAttrib::
register_with_read_factory() {
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::write_datagram
// Access: Public, Virtual
// Description: Writes the contents of this object to the datagram
// for shipping out to a Bam file.
////////////////////////////////////////////////////////////////////
void TexGenAttrib::
write_datagram(BamWriter *manager, Datagram &dg) {
RenderAttrib::write_datagram(manager, dg);
dg.add_int8(_mode);
//manager->write_pointer(dg, _texture);
}
/*
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::complete_pointers
// Access: Public, Virtual
// Description: Receives an array of pointers, one for each time
// manager->read_pointer() was called in fillin().
// Returns the number of pointers processed.
////////////////////////////////////////////////////////////////////
int TexGenAttrib::
complete_pointers(TypedWritable **p_list, BamReader *manager) {
int pi = RenderAttrib::complete_pointers(p_list, manager);
TypedWritable *texture = p_list[pi++];
if (texture != (TypedWritable *)NULL) {
_texture = DCAST(Texture, texture);
}
return pi;
}
*/
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::make_from_bam
// Access: Protected, Static
// Description: This function is called by the BamReader's factory
// when a new object of type TexGenAttrib is encountered
// in the Bam file. It should create the TexGenAttrib
// and extract its information from the file.
////////////////////////////////////////////////////////////////////
TypedWritable *TexGenAttrib::
make_from_bam(const FactoryParams &params) {
TexGenAttrib *attrib = new TexGenAttrib;
DatagramIterator scan;
BamReader *manager;
parse_params(params, scan, manager);
attrib->fillin(scan, manager);
return attrib;
}
////////////////////////////////////////////////////////////////////
// Function: TexGenAttrib::fillin
// Access: Protected
// Description: This internal function is called by make_from_bam to
// read in all of the relevant data from the BamFile for
// the new TexGenAttrib.
////////////////////////////////////////////////////////////////////
void TexGenAttrib::
fillin(DatagramIterator &scan, BamReader *manager) {
RenderAttrib::fillin(scan, manager);
_mode = (Mode)scan.get_int8();
// Read the _texture pointer.
//manager->read_pointer(scan);
}

95
panda/src/pgraph/texGenAttrib.h Executable file
View File

@ -0,0 +1,95 @@
// Filename: texGenAttrib.h
// Created by: masad (21Jun04)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef TEXGENATTRIB_H
#define TEXGENATTRIB_H
#include "pandabase.h"
#include "renderAttrib.h"
#include "texture.h"
////////////////////////////////////////////////////////////////////
// Class : TexGenAttrib
// Description : Calculates new texture coordinates for reflection
// and refraction maps. This attrib is used to get a
// water like surface.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA TexGenAttrib : public RenderAttrib {
private:
PUBLISHED:
enum Mode {
M_spherical,
M_cubic,
M_nothing
};
private:
INLINE TexGenAttrib(Mode mode = M_nothing);
PUBLISHED:
static CPT(RenderAttrib) make(Mode mode);
static CPT(RenderAttrib) make_off();
INLINE bool is_off() const;
INLINE Mode get_mode() const;
INLINE Texture *get_texture() const;
public:
virtual void issue(GraphicsStateGuardianBase *gsg) const;
virtual void output(ostream &out) const;
protected:
virtual int compare_to_impl(const RenderAttrib *other) const;
virtual RenderAttrib *make_default_impl() const;
private:
Mode _mode;
PT(Texture) _texture;
public:
static void register_with_read_factory();
virtual void write_datagram(BamWriter *manager, Datagram &dg);
//virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
protected:
static TypedWritable *make_from_bam(const FactoryParams &params);
void fillin(DatagramIterator &scan, BamReader *manager);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
RenderAttrib::init_type();
register_type(_type_handle, "TexGenAttrib",
RenderAttrib::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#include "texGenAttrib.I"
#endif