2001-12-28 23:33:32 +00:00
|
|
|
|
// newmat.hxx -- a material in the scene graph.
|
|
|
|
|
// TODO: this class needs to be renamed.
|
2000-06-23 02:59:03 +00:00
|
|
|
|
//
|
|
|
|
|
// Written by Curtis Olson, started May 1998.
|
2001-12-28 23:33:32 +00:00
|
|
|
|
// Overhauled by David Megginson, December 2001
|
2000-06-23 02:59:03 +00:00
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 1998 - 2000 Curtis L. Olson - curt@flightgear.org
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
//
|
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _NEWMAT_HXX
|
|
|
|
|
#define _NEWMAT_HXX
|
|
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
|
# error This library requires C++
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
|
# include <windows.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <plib/sg.h>
|
|
|
|
|
#include <plib/ssg.h>
|
|
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
2001-12-28 23:33:32 +00:00
|
|
|
|
#include <simgear/misc/props.hxx>
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
|
|
|
|
#include <GL/glut.h>
|
|
|
|
|
|
|
|
|
|
#include STL_STRING // Standard C++ string library
|
|
|
|
|
|
2001-03-23 22:59:18 +00:00
|
|
|
|
SG_USING_STD(string);
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* A material in the scene graph.
|
|
|
|
|
*
|
|
|
|
|
* A material represents information about a single surface type
|
|
|
|
|
* in the 3D scene graph, including texture, colour, lighting,
|
|
|
|
|
* tiling, and so on; most of the materials in FlightGear are
|
|
|
|
|
* defined in the $FG_ROOT/materials.xml file, and can be changed
|
|
|
|
|
* at runtime.
|
|
|
|
|
*/
|
2000-06-23 02:59:03 +00:00
|
|
|
|
class FGNewMat {
|
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
public:
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Public Constructors.
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Construct a material from a set of properties.
|
|
|
|
|
*
|
|
|
|
|
* @param props A property node containing subnodes with the
|
|
|
|
|
* state information for the material. This node is usually
|
|
|
|
|
* loaded from the $FG_ROOT/materials.xml file.
|
|
|
|
|
*/
|
|
|
|
|
FGNewMat (const SGPropertyNode * props);
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Construct a material from an absolute texture path.
|
|
|
|
|
*
|
|
|
|
|
* @param texture_path A string containing an absolute path
|
|
|
|
|
* to a texture file (usually RGB).
|
|
|
|
|
*/
|
2002-03-12 05:37:55 +00:00
|
|
|
|
FGNewMat (const string &texpath);
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2000-08-25 05:53:12 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Construct a material around an existing SSG state.
|
|
|
|
|
*
|
|
|
|
|
* This constructor allows the application to create a custom,
|
|
|
|
|
* low-level state for the scene graph and wrap a material around
|
|
|
|
|
* it. Note: the pointer ownership is transferred to the material.
|
|
|
|
|
*
|
|
|
|
|
* @param s The SSG state for this material.
|
|
|
|
|
*/
|
|
|
|
|
FGNewMat (ssgSimpleState * s);
|
2000-09-06 00:10:50 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Destructor.
|
|
|
|
|
*/
|
|
|
|
|
virtual ~FGNewMat ( void );
|
2000-12-05 20:53:14 +00:00
|
|
|
|
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Public methods.
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2001-04-11 02:47:15 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Force the texture to load if it hasn't already.
|
|
|
|
|
*
|
|
|
|
|
* @return true if the texture loaded, false if it was loaded
|
|
|
|
|
* already.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool load_texture ();
|
2001-07-13 05:15:29 +00:00
|
|
|
|
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the textured state.
|
|
|
|
|
*/
|
|
|
|
|
virtual inline ssgSimpleState *get_textured () { return textured; }
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the xsize of the texture, in meters.
|
|
|
|
|
*/
|
|
|
|
|
virtual inline double get_xsize() const { return xsize; }
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the ysize of the texture, in meters.
|
|
|
|
|
*/
|
|
|
|
|
virtual inline double get_ysize() const { return ysize; }
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the light coverage.
|
|
|
|
|
*
|
|
|
|
|
* A smaller number means more generated night lighting.
|
|
|
|
|
*
|
|
|
|
|
* @return The area (m^2?) covered by each light.
|
|
|
|
|
*/
|
|
|
|
|
virtual inline double get_light_coverage () const { return light_coverage; }
|
2001-05-15 00:01:04 +00:00
|
|
|
|
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the current state.
|
|
|
|
|
*/
|
2001-12-30 03:04:39 +00:00
|
|
|
|
virtual inline ssgStateSelector *get_state () const { return state; }
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-05-15 00:01:04 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
2001-12-30 03:04:39 +00:00
|
|
|
|
* Increment the reference count for this material.
|
|
|
|
|
*
|
|
|
|
|
* A material with 0 references may be deleted by the
|
|
|
|
|
* material library.
|
2001-12-28 23:33:32 +00:00
|
|
|
|
*/
|
2001-12-30 03:04:39 +00:00
|
|
|
|
virtual inline void ref () { refcount++; }
|
2000-12-05 20:53:14 +00:00
|
|
|
|
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
2001-12-30 03:04:39 +00:00
|
|
|
|
* Decrement the reference count for this material.
|
2001-12-28 23:33:32 +00:00
|
|
|
|
*/
|
2001-12-30 03:04:39 +00:00
|
|
|
|
virtual inline void deRef () { refcount--; }
|
2001-07-13 05:15:29 +00:00
|
|
|
|
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
/**
|
2001-12-30 03:04:39 +00:00
|
|
|
|
* Get the reference count for this material.
|
|
|
|
|
*
|
|
|
|
|
* @return The number of references (0 if none).
|
2001-12-28 23:33:32 +00:00
|
|
|
|
*/
|
2001-12-30 03:04:39 +00:00
|
|
|
|
virtual inline int getRef () const { return refcount; }
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-12-29 13:19:09 +00:00
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Protected methods.
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialization method, invoked by all public constructors.
|
|
|
|
|
*/
|
|
|
|
|
virtual void init();
|
|
|
|
|
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Internal state.
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// names
|
|
|
|
|
string texture_path;
|
|
|
|
|
|
|
|
|
|
// pointers to ssg states
|
|
|
|
|
ssgStateSelector *state;
|
|
|
|
|
ssgSimpleState *textured;
|
|
|
|
|
ssgSimpleState *nontextured;
|
|
|
|
|
|
|
|
|
|
// texture size
|
|
|
|
|
double xsize, ysize;
|
|
|
|
|
|
|
|
|
|
// wrap texture?
|
|
|
|
|
bool wrapu, wrapv;
|
2000-06-23 02:59:03 +00:00
|
|
|
|
|
2001-12-28 23:33:32 +00:00
|
|
|
|
// use mipmapping?
|
|
|
|
|
int mipmap;
|
|
|
|
|
|
|
|
|
|
// coverage of night lighting.
|
|
|
|
|
double light_coverage;
|
|
|
|
|
|
|
|
|
|
// material properties
|
|
|
|
|
sgVec4 ambient, diffuse, specular, emission;
|
|
|
|
|
|
|
|
|
|
// true if texture loading deferred, and not yet loaded
|
|
|
|
|
bool texture_loaded;
|
|
|
|
|
|
|
|
|
|
// ref count so we can properly delete if we have multiple
|
|
|
|
|
// pointers to this record
|
|
|
|
|
int refcount;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Internal constructors and methods.
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
FGNewMat (const FGNewMat &mat); // unimplemented
|
|
|
|
|
|
|
|
|
|
void read_properties (const SGPropertyNode * props);
|
|
|
|
|
void build_ssg_state(bool defer_tex_load = false);
|
|
|
|
|
void set_ssg_state( ssgSimpleState *s );
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // _NEWMAT_HXX
|