This commit is contained in:
David Rose 2005-09-06 18:30:26 +00:00
parent dd28bafc68
commit a9a9f280bb
16 changed files with 1477 additions and 1477 deletions

View File

@ -1,4 +1,4 @@
#define IDI_ICON1 101
IDI_ICON1 ICON "pandaIcon.ico"
#define IDI_ICON1 101
IDI_ICON1 ICON "pandaIcon.ico"

View File

@ -1,95 +1,95 @@
VC7 upgrade instructions in 2 easy steps
------------------------
Step 1. cvs update wintools & dtool
Step 2. Run v:\msvc7\vc_setup\setup.exe, or install from the MSDN
'Visual Studio.NET' CD. Click on 'Windows Component Update' (if it is
highlighted, else click '2'). Click 'Continue' (Selecting 'Do not use
this machine to host web projects') You will install IE6, which will
requires a reboot. Give your pw if you want it to happen
automatically.
After rebooting, setup should start again. If it does not, go back and
rerun it, it should remember where it left off.
After installing components, you are ready to install VC7 in Step 2.
Enter this step and enter the product-key, which is stored in
V:\msvc7\vc7-prodkey.txt
On the 'select items to install page', you need uncheck things to
avoid wasting gigs of extra space and install time. Uncheck
everything except for Language Tools->Visual C++, Server
Components->Remote Debugger->Native Remote Debugger, and if you want,
Documentation (this is a gig, and is only a slight update if you
already have MSDN installed locally though. You will want to
uninstall the separately-installed MSDN docs if you get this.)
Unlike VC 6.0, there is no option to add the required compiler bin
directories to the environment path automatically. To do this, if you
are running from the NT command line, run
"C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin\vcvars32.bat"
If you are using tcsh.exe under cygwin, enable VC7 using
'source $WINTOOLS/etc/setup_msvc7.csh'
You will want to copy the top portion of setup_msvc7.csh to your
.cshrc, so you can do 'set_msvc7' to set up the PATH properly in the
future, or you can add the required dirs to the front of your path
explicitly as well as 'setenv USE_COMPILER MSVC7' to always use VC7.
The easiest thing to do is just put the 'set_msvc7' at the end of your
.cshrc.
IMPORTANT:
After finishing this process, make sure you are using VC7 in your
shell by typing 'cl' at the prompt. If you see:
> Microsoft (R)32-bit C/C++ Optimizing Compiler Version 13.00.9466 for 80x86
> Copyright (C) Microsoft Corporation 1984-2001.
then you have VC7. If you have still VC6, you will see
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
> Copyright (C) Microsoft Corp 1984-1998.
If you try to build with this broken setup, the build process
will get confused and compile with VC6 but try to link with
the VC7 libraries and you will get link errors.
To correct this problem, check your tcsh path to make sure it has the
.NET dirs in it, and make sure the cygwin softlink mount point /msvc7
exists, and is not empty but points to the proper VC7 directory. Doing
'ls /msvc7' should give you something like
Common7/ Visual Studio .NET Enterprise Architect - English/
Crystal Reports/ Visual Studio SDKs/
EnterpriseFrameworks/ contents.htm
FrameworkSDK/ readme.htm
Msdn/ redist.txt
Setup/ sqlserver/
Vb7/ toc.htm
Vc7/ vdt70vcs.dll*
If it does not, try running 'source ~/player/wintools/etc/setup_env.csh'
again to get it to do the
'mount -s C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET /msvc7'
cmd to create the softlink, or run the cmd yourself.
---
Notes:
The debug C runtime seems significantly slower than the vc6 one, which has
slowed Opt2 install builds considerably.
---------
To distribute toontown,
We need to rebuild the python and nspr DLLs to link to the new
VC7 C and C++ runtime DLLs, which are
msvcp70.dll
msvcr70.dll
and these must replace
msvcp60.dll
msvcrt.dll
in the Toontown download.
VC7 upgrade instructions in 2 easy steps
------------------------
Step 1. cvs update wintools & dtool
Step 2. Run v:\msvc7\vc_setup\setup.exe, or install from the MSDN
'Visual Studio.NET' CD. Click on 'Windows Component Update' (if it is
highlighted, else click '2'). Click 'Continue' (Selecting 'Do not use
this machine to host web projects') You will install IE6, which will
requires a reboot. Give your pw if you want it to happen
automatically.
After rebooting, setup should start again. If it does not, go back and
rerun it, it should remember where it left off.
After installing components, you are ready to install VC7 in Step 2.
Enter this step and enter the product-key, which is stored in
V:\msvc7\vc7-prodkey.txt
On the 'select items to install page', you need uncheck things to
avoid wasting gigs of extra space and install time. Uncheck
everything except for Language Tools->Visual C++, Server
Components->Remote Debugger->Native Remote Debugger, and if you want,
Documentation (this is a gig, and is only a slight update if you
already have MSDN installed locally though. You will want to
uninstall the separately-installed MSDN docs if you get this.)
Unlike VC 6.0, there is no option to add the required compiler bin
directories to the environment path automatically. To do this, if you
are running from the NT command line, run
"C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin\vcvars32.bat"
If you are using tcsh.exe under cygwin, enable VC7 using
'source $WINTOOLS/etc/setup_msvc7.csh'
You will want to copy the top portion of setup_msvc7.csh to your
.cshrc, so you can do 'set_msvc7' to set up the PATH properly in the
future, or you can add the required dirs to the front of your path
explicitly as well as 'setenv USE_COMPILER MSVC7' to always use VC7.
The easiest thing to do is just put the 'set_msvc7' at the end of your
.cshrc.
IMPORTANT:
After finishing this process, make sure you are using VC7 in your
shell by typing 'cl' at the prompt. If you see:
> Microsoft (R)32-bit C/C++ Optimizing Compiler Version 13.00.9466 for 80x86
> Copyright (C) Microsoft Corporation 1984-2001.
then you have VC7. If you have still VC6, you will see
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
> Copyright (C) Microsoft Corp 1984-1998.
If you try to build with this broken setup, the build process
will get confused and compile with VC6 but try to link with
the VC7 libraries and you will get link errors.
To correct this problem, check your tcsh path to make sure it has the
.NET dirs in it, and make sure the cygwin softlink mount point /msvc7
exists, and is not empty but points to the proper VC7 directory. Doing
'ls /msvc7' should give you something like
Common7/ Visual Studio .NET Enterprise Architect - English/
Crystal Reports/ Visual Studio SDKs/
EnterpriseFrameworks/ contents.htm
FrameworkSDK/ readme.htm
Msdn/ redist.txt
Setup/ sqlserver/
Vb7/ toc.htm
Vc7/ vdt70vcs.dll*
If it does not, try running 'source ~/player/wintools/etc/setup_env.csh'
again to get it to do the
'mount -s C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET /msvc7'
cmd to create the softlink, or run the cmd yourself.
---
Notes:
The debug C runtime seems significantly slower than the vc6 one, which has
slowed Opt2 install builds considerably.
---------
To distribute toontown,
We need to rebuild the python and nspr DLLs to link to the new
VC7 C and C++ runtime DLLs, which are
msvcp70.dll
msvcr70.dll
and these must replace
msvcp60.dll
msvcrt.dll
in the Toontown download.

View File

@ -1,44 +1,44 @@
// Filename: glShaderContext_src.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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: GLShaderContext::bind
// Access: Public
// Description: xyz
////////////////////////////////////////////////////////////////////
INLINE void CLP(ShaderContext)::
bind(ShaderMode *m) {
}
////////////////////////////////////////////////////////////////////
// Function: GLShaderContext::unbind
// Access: Public
// Description: xyz
////////////////////////////////////////////////////////////////////
INLINE void CLP(ShaderContext)::
unbind(void) {
}
////////////////////////////////////////////////////////////////////
// Function: GLShaderContext::rebind
// Access: Public
// Description: xyz
////////////////////////////////////////////////////////////////////
INLINE void CLP(ShaderContext)::
rebind(ShaderMode *oldmode, ShaderMode *newmode) {
}
// Filename: glShaderContext_src.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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: GLShaderContext::bind
// Access: Public
// Description: xyz
////////////////////////////////////////////////////////////////////
INLINE void CLP(ShaderContext)::
bind(ShaderMode *m) {
}
////////////////////////////////////////////////////////////////////
// Function: GLShaderContext::unbind
// Access: Public
// Description: xyz
////////////////////////////////////////////////////////////////////
INLINE void CLP(ShaderContext)::
unbind(void) {
}
////////////////////////////////////////////////////////////////////
// Function: GLShaderContext::rebind
// Access: Public
// Description: xyz
////////////////////////////////////////////////////////////////////
INLINE void CLP(ShaderContext)::
rebind(ShaderMode *oldmode, ShaderMode *newmode) {
}

View File

@ -1,43 +1,43 @@
// Filename: glShaderContext_src.cxx
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 .
//
////////////////////////////////////////////////////////////////////
TypeHandle CLP(ShaderContext)::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: GLShaderContext::Constructor
// Access: Public
// Description: xyz
////////////////////////////////////////////////////////////////////
CLP(ShaderContext)::
CLP(ShaderContext)(Shader *s) : ShaderContext(s) {
string header, body;
s->parse_init();
s->parse_line(header, true, true);
s->parse_rest(body);
cerr << "Compiling shader. Language=" << header << " Body=\n" << body << "\n";
}
////////////////////////////////////////////////////////////////////
// Function: GLShaderContext::Destructor
// Access: Public
// Description: xyz
////////////////////////////////////////////////////////////////////
CLP(ShaderContext)::
~CLP(ShaderContext)(void) {
}
// Filename: glShaderContext_src.cxx
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 .
//
////////////////////////////////////////////////////////////////////
TypeHandle CLP(ShaderContext)::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: GLShaderContext::Constructor
// Access: Public
// Description: xyz
////////////////////////////////////////////////////////////////////
CLP(ShaderContext)::
CLP(ShaderContext)(Shader *s) : ShaderContext(s) {
string header, body;
s->parse_init();
s->parse_line(header, true, true);
s->parse_rest(body);
cerr << "Compiling shader. Language=" << header << " Body=\n" << body << "\n";
}
////////////////////////////////////////////////////////////////////
// Function: GLShaderContext::Destructor
// Access: Public
// Description: xyz
////////////////////////////////////////////////////////////////////
CLP(ShaderContext)::
~CLP(ShaderContext)(void) {
}

View File

@ -1,55 +1,55 @@
// Filename: glShaderContext_src.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 "pandabase.h"
#include "shaderContext.h"
////////////////////////////////////////////////////////////////////
// Class : GLShaderContext
// Description : xyz
////////////////////////////////////////////////////////////////////
class EXPCL_GL CLP(ShaderContext): public ShaderContext {
public:
CLP(ShaderContext)(Shader *shader);
~CLP(ShaderContext)(void);
INLINE void bind(ShaderMode *mode);
INLINE void unbind(void);
INLINE void rebind(ShaderMode *oldmode, ShaderMode *newmode);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedObject::init_type();
register_type(_type_handle, CLASSPREFIX_QUOTED "ShaderContext",
TypedObject::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 "glShaderContext_src.I"
// Filename: glShaderContext_src.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 "pandabase.h"
#include "shaderContext.h"
////////////////////////////////////////////////////////////////////
// Class : GLShaderContext
// Description : xyz
////////////////////////////////////////////////////////////////////
class EXPCL_GL CLP(ShaderContext): public ShaderContext {
public:
CLP(ShaderContext)(Shader *shader);
~CLP(ShaderContext)(void);
INLINE void bind(ShaderMode *mode);
INLINE void unbind(void);
INLINE void rebind(ShaderMode *oldmode, ShaderMode *newmode);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedObject::init_type();
register_type(_type_handle, CLASSPREFIX_QUOTED "ShaderContext",
TypedObject::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 "glShaderContext_src.I"

View File

@ -1,279 +1,279 @@
// Filename: shader.cxx
// Created by: jyelon (Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 "pandabase.h"
#include "shader.h"
TypeHandle Shader::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: Shader::Constructor
// Access: Public
// Description: Construct a Shader.
////////////////////////////////////////////////////////////////////
Shader::
Shader(const string &text, const string &file) {
_text = text;
_file = file;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::Destructor
// Access: Public
// Description: Delete the compiled code, if it exists.
////////////////////////////////////////////////////////////////////
Shader::
~Shader() {
release_all();
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_init
// Access: Public
// Description: Set a 'parse pointer' to the beginning of the shader.
////////////////////////////////////////////////////////////////////
void Shader::
parse_init(void) {
_parse = 0;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_line
// Access: Public
// Description: Parse a line of text. If 'lt' is true, trim blanks
// from the left end of the line. If 'rt' is true, trim
// blanks from the right end (the newline is always
// trimmed).
////////////////////////////////////////////////////////////////////
void Shader::
parse_line(string &result, bool lt, bool rt) {
int len = _text.size();
int head = _parse;
int tail = head;
while ((tail < len) && (_text[tail] != '\n')) tail++;
if (tail < len) {
_parse = tail+1;
} else {
_parse = tail;
}
if (lt) {
while ((head < tail)&&(isspace(_text[head]))) head++;
while ((tail > head)&&(isspace(_text[tail-1]))) tail--;
}
result = _text.substr(head, tail-head);
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_upto
// Access: Public
// Description: Parse lines until you read a line that matches the
// specified pattern. Returns all the preceding lines,
// and if the include flag is set, returns the final
// line as well.
////////////////////////////////////////////////////////////////////
void Shader::
parse_upto(string &result, string pattern, bool include) {
int start = _parse;
int last = _parse;
while (true) {
string t;
parse_line(t, true, true);
if (t == pattern) break;
last = _parse;
}
if (include) {
result = _text.substr(start, _parse - start);
} else {
result = _text.substr(start, last - start);
}
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_rest
// Access: Public
// Description: Returns the rest of the text from the current
// parse location.
////////////////////////////////////////////////////////////////////
void Shader::
parse_rest(string &result) {
result = _text.substr(_parse, _text.size() - _parse);
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_eof
// Access: Public
// Description: Returns true if the parse pointer is at the end of
// the shader.
////////////////////////////////////////////////////////////////////
bool Shader::
parse_eof(void) {
return (int)_text.size() == _parse;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::arg_index
// Access: Public
// Description: Allocates an integer index to the given
// shader parameter name.
////////////////////////////////////////////////////////////////////
int Shader::
arg_index(const string &id) {
for (int i=0; i<(int)(_args.size()); i++)
if (_args[i] == id)
return i;
_args.push_back(id);
return _args.size() - 1;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::prepare
// Access: Published
// Description: Indicates that the shader should be enqueued to be
// prepared in the indicated prepared_objects at the
// beginning of the next frame. This will ensure the
// texture is already loaded into texture memory if it
// is expected to be rendered soon.
//
// Use this function instead of prepare_now() to preload
// textures from a user interface standpoint.
////////////////////////////////////////////////////////////////////
void Shader::
prepare(PreparedGraphicsObjects *prepared_objects) {
prepared_objects->enqueue_shader(this);
}
////////////////////////////////////////////////////////////////////
// Function: Shader::release
// Access: Published
// Description: Frees the texture context only on the indicated object,
// if it exists there. Returns true if it was released,
// false if it had not been prepared.
////////////////////////////////////////////////////////////////////
bool Shader::
release(PreparedGraphicsObjects *prepared_objects) {
Contexts::iterator ci;
ci = _contexts.find(prepared_objects);
if (ci != _contexts.end()) {
ShaderContext *sc = (*ci).second;
if (sc != (ShaderContext *)NULL) {
prepared_objects->release_shader(sc);
} else {
_contexts.erase(ci);
}
return true;
}
// Maybe it wasn't prepared yet, but it's about to be.
return prepared_objects->dequeue_shader(this);
}
////////////////////////////////////////////////////////////////////
// Function: Shader::prepare_now
// Access: Public
// Description: Creates a context for the texture on the particular
// GSG, if it does not already exist. Returns the new
// (or old) ShaderContext. This assumes that the
// GraphicsStateGuardian is the currently active
// rendering context and that it is ready to accept new
// textures. If this is not necessarily the case, you
// should use prepare() instead.
//
// Normally, this is not called directly except by the
// GraphicsStateGuardian; a texture does not need to be
// explicitly prepared by the user before it may be
// rendered.
////////////////////////////////////////////////////////////////////
ShaderContext *Shader::
prepare_now(PreparedGraphicsObjects *prepared_objects,
GraphicsStateGuardianBase *gsg) {
Contexts::const_iterator ci;
ci = _contexts.find(prepared_objects);
if (ci != _contexts.end()) {
return (*ci).second;
}
ShaderContext *tc = prepared_objects->prepare_shader_now(this, gsg);
_contexts[prepared_objects] = tc;
return tc;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::clear_prepared
// Access: Private
// Description: Removes the indicated PreparedGraphicsObjects table
// from the Shader's table, without actually releasing
// the texture. This is intended to be called only from
// PreparedGraphicsObjects::release_texture(); it should
// never be called by user code.
////////////////////////////////////////////////////////////////////
void Shader::
clear_prepared(PreparedGraphicsObjects *prepared_objects) {
Contexts::iterator ci;
ci = _contexts.find(prepared_objects);
if (ci != _contexts.end()) {
_contexts.erase(ci);
} else {
// If this assertion fails, clear_prepared() was given a
// prepared_objects which the texture didn't know about.
nassertv(false);
}
}
////////////////////////////////////////////////////////////////////
// Function: Shader::release_all
// Access: Published
// Description: Frees the context allocated on all objects for which
// the texture has been declared. Returns the number of
// contexts which have been freed.
////////////////////////////////////////////////////////////////////
int Shader::
release_all() {
// We have to traverse a copy of the _contexts list, because the
// PreparedGraphicsObjects object will call clear_prepared() in response
// to each release_texture(), and we don't want to be modifying the
// _contexts list while we're traversing it.
Contexts temp = _contexts;
int num_freed = (int)_contexts.size();
Contexts::const_iterator ci;
for (ci = temp.begin(); ci != temp.end(); ++ci) {
PreparedGraphicsObjects *prepared_objects = (*ci).first;
ShaderContext *sc = (*ci).second;
if (sc != (ShaderContext *)NULL) {
prepared_objects->release_shader(sc);
}
}
// There might still be some outstanding contexts in the map, if
// there were any NULL pointers there. Eliminate them.
_contexts.clear();
return num_freed;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::register_with_read_factory
// Access: Public, Static
// Description: Factory method to generate a Shader object
////////////////////////////////////////////////////////////////////
void Shader::
register_with_read_factory() {
// IMPLEMENT ME
}
// Filename: shader.cxx
// Created by: jyelon (Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 "pandabase.h"
#include "shader.h"
TypeHandle Shader::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: Shader::Constructor
// Access: Public
// Description: Construct a Shader.
////////////////////////////////////////////////////////////////////
Shader::
Shader(const string &text, const string &file) {
_text = text;
_file = file;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::Destructor
// Access: Public
// Description: Delete the compiled code, if it exists.
////////////////////////////////////////////////////////////////////
Shader::
~Shader() {
release_all();
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_init
// Access: Public
// Description: Set a 'parse pointer' to the beginning of the shader.
////////////////////////////////////////////////////////////////////
void Shader::
parse_init(void) {
_parse = 0;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_line
// Access: Public
// Description: Parse a line of text. If 'lt' is true, trim blanks
// from the left end of the line. If 'rt' is true, trim
// blanks from the right end (the newline is always
// trimmed).
////////////////////////////////////////////////////////////////////
void Shader::
parse_line(string &result, bool lt, bool rt) {
int len = _text.size();
int head = _parse;
int tail = head;
while ((tail < len) && (_text[tail] != '\n')) tail++;
if (tail < len) {
_parse = tail+1;
} else {
_parse = tail;
}
if (lt) {
while ((head < tail)&&(isspace(_text[head]))) head++;
while ((tail > head)&&(isspace(_text[tail-1]))) tail--;
}
result = _text.substr(head, tail-head);
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_upto
// Access: Public
// Description: Parse lines until you read a line that matches the
// specified pattern. Returns all the preceding lines,
// and if the include flag is set, returns the final
// line as well.
////////////////////////////////////////////////////////////////////
void Shader::
parse_upto(string &result, string pattern, bool include) {
int start = _parse;
int last = _parse;
while (true) {
string t;
parse_line(t, true, true);
if (t == pattern) break;
last = _parse;
}
if (include) {
result = _text.substr(start, _parse - start);
} else {
result = _text.substr(start, last - start);
}
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_rest
// Access: Public
// Description: Returns the rest of the text from the current
// parse location.
////////////////////////////////////////////////////////////////////
void Shader::
parse_rest(string &result) {
result = _text.substr(_parse, _text.size() - _parse);
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_eof
// Access: Public
// Description: Returns true if the parse pointer is at the end of
// the shader.
////////////////////////////////////////////////////////////////////
bool Shader::
parse_eof(void) {
return (int)_text.size() == _parse;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::arg_index
// Access: Public
// Description: Allocates an integer index to the given
// shader parameter name.
////////////////////////////////////////////////////////////////////
int Shader::
arg_index(const string &id) {
for (int i=0; i<(int)(_args.size()); i++)
if (_args[i] == id)
return i;
_args.push_back(id);
return _args.size() - 1;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::prepare
// Access: Published
// Description: Indicates that the shader should be enqueued to be
// prepared in the indicated prepared_objects at the
// beginning of the next frame. This will ensure the
// texture is already loaded into texture memory if it
// is expected to be rendered soon.
//
// Use this function instead of prepare_now() to preload
// textures from a user interface standpoint.
////////////////////////////////////////////////////////////////////
void Shader::
prepare(PreparedGraphicsObjects *prepared_objects) {
prepared_objects->enqueue_shader(this);
}
////////////////////////////////////////////////////////////////////
// Function: Shader::release
// Access: Published
// Description: Frees the texture context only on the indicated object,
// if it exists there. Returns true if it was released,
// false if it had not been prepared.
////////////////////////////////////////////////////////////////////
bool Shader::
release(PreparedGraphicsObjects *prepared_objects) {
Contexts::iterator ci;
ci = _contexts.find(prepared_objects);
if (ci != _contexts.end()) {
ShaderContext *sc = (*ci).second;
if (sc != (ShaderContext *)NULL) {
prepared_objects->release_shader(sc);
} else {
_contexts.erase(ci);
}
return true;
}
// Maybe it wasn't prepared yet, but it's about to be.
return prepared_objects->dequeue_shader(this);
}
////////////////////////////////////////////////////////////////////
// Function: Shader::prepare_now
// Access: Public
// Description: Creates a context for the texture on the particular
// GSG, if it does not already exist. Returns the new
// (or old) ShaderContext. This assumes that the
// GraphicsStateGuardian is the currently active
// rendering context and that it is ready to accept new
// textures. If this is not necessarily the case, you
// should use prepare() instead.
//
// Normally, this is not called directly except by the
// GraphicsStateGuardian; a texture does not need to be
// explicitly prepared by the user before it may be
// rendered.
////////////////////////////////////////////////////////////////////
ShaderContext *Shader::
prepare_now(PreparedGraphicsObjects *prepared_objects,
GraphicsStateGuardianBase *gsg) {
Contexts::const_iterator ci;
ci = _contexts.find(prepared_objects);
if (ci != _contexts.end()) {
return (*ci).second;
}
ShaderContext *tc = prepared_objects->prepare_shader_now(this, gsg);
_contexts[prepared_objects] = tc;
return tc;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::clear_prepared
// Access: Private
// Description: Removes the indicated PreparedGraphicsObjects table
// from the Shader's table, without actually releasing
// the texture. This is intended to be called only from
// PreparedGraphicsObjects::release_texture(); it should
// never be called by user code.
////////////////////////////////////////////////////////////////////
void Shader::
clear_prepared(PreparedGraphicsObjects *prepared_objects) {
Contexts::iterator ci;
ci = _contexts.find(prepared_objects);
if (ci != _contexts.end()) {
_contexts.erase(ci);
} else {
// If this assertion fails, clear_prepared() was given a
// prepared_objects which the texture didn't know about.
nassertv(false);
}
}
////////////////////////////////////////////////////////////////////
// Function: Shader::release_all
// Access: Published
// Description: Frees the context allocated on all objects for which
// the texture has been declared. Returns the number of
// contexts which have been freed.
////////////////////////////////////////////////////////////////////
int Shader::
release_all() {
// We have to traverse a copy of the _contexts list, because the
// PreparedGraphicsObjects object will call clear_prepared() in response
// to each release_texture(), and we don't want to be modifying the
// _contexts list while we're traversing it.
Contexts temp = _contexts;
int num_freed = (int)_contexts.size();
Contexts::const_iterator ci;
for (ci = temp.begin(); ci != temp.end(); ++ci) {
PreparedGraphicsObjects *prepared_objects = (*ci).first;
ShaderContext *sc = (*ci).second;
if (sc != (ShaderContext *)NULL) {
prepared_objects->release_shader(sc);
}
}
// There might still be some outstanding contexts in the map, if
// there were any NULL pointers there. Eliminate them.
_contexts.clear();
return num_freed;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::register_with_read_factory
// Access: Public, Static
// Description: Factory method to generate a Shader object
////////////////////////////////////////////////////////////////////
void Shader::
register_with_read_factory() {
// IMPLEMENT ME
}

View File

@ -1,114 +1,114 @@
// Filename: shader.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
//
// Current Loose Ends:
// - BAM reading/writing not implemented on most classes.
// - ShaderPool not implemented.
// - compilation of shaders for OpenGL not implemented.
// - compilation of shaders for DirectX8 not implemented.
// - compilation of shaders for DirectX9 not implemented.
//
////////////////////////////////////////////////////////////////////
#ifndef SHADER_H
#define SHADER_H
#include "pandabase.h"
#include "typedWritableReferenceCount.h"
#include "internalName.h"
////////////////////////////////////////////////////////////////////
// Class : Shader
// Summary: The Shader object contains the string which
// is the shader's text, a filename that indicates
// where the shader came from (optional), and an
// argument-name to argument-index allocator. The
// allocator is there so that all the Shader and
// ShaderContext objects associated with this Shader
// can refer to arguments by index instead of by name,
// which could make the bind process significantly
// faster.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA Shader: public TypedWritableReferenceCount {
PUBLISHED:
Shader(const string &text, const string &file);
~Shader(void);
INLINE const string &get_text(void);
INLINE const Filename &get_file(void);
void prepare(PreparedGraphicsObjects *prepared_objects);
bool release(PreparedGraphicsObjects *prepared_objects);
int release_all();
PUBLISHED:
void parse_init(void);
void parse_line(string &result, bool rt, bool lt);
void parse_upto(string &result, string pattern, bool include);
void parse_rest(string &result);
bool parse_eof(void);
public:
INLINE int arg_count(void);
int arg_index(const string &id);
string _text;
Filename _file;
int _parse;
vector<string> _args;
typedef pmap<PreparedGraphicsObjects *, ShaderContext *> Contexts;
Contexts _contexts;
static void register_with_read_factory(void);
friend class ShaderContext;
friend class PreparedGraphicsObjects;
ShaderContext *prepare_now(PreparedGraphicsObjects *prepared_objects,
GraphicsStateGuardianBase *gsg);
private:
void parse(void);
void clear_prepared(PreparedGraphicsObjects *prepared_objects);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedWritableReferenceCount::init_type();
register_type(_type_handle, "Shader",
TypedWritableReferenceCount::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 "shader.I"
#endif
// Filename: shader.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
//
// Current Loose Ends:
// - BAM reading/writing not implemented on most classes.
// - ShaderPool not implemented.
// - compilation of shaders for OpenGL not implemented.
// - compilation of shaders for DirectX8 not implemented.
// - compilation of shaders for DirectX9 not implemented.
//
////////////////////////////////////////////////////////////////////
#ifndef SHADER_H
#define SHADER_H
#include "pandabase.h"
#include "typedWritableReferenceCount.h"
#include "internalName.h"
////////////////////////////////////////////////////////////////////
// Class : Shader
// Summary: The Shader object contains the string which
// is the shader's text, a filename that indicates
// where the shader came from (optional), and an
// argument-name to argument-index allocator. The
// allocator is there so that all the Shader and
// ShaderContext objects associated with this Shader
// can refer to arguments by index instead of by name,
// which could make the bind process significantly
// faster.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA Shader: public TypedWritableReferenceCount {
PUBLISHED:
Shader(const string &text, const string &file);
~Shader(void);
INLINE const string &get_text(void);
INLINE const Filename &get_file(void);
void prepare(PreparedGraphicsObjects *prepared_objects);
bool release(PreparedGraphicsObjects *prepared_objects);
int release_all();
PUBLISHED:
void parse_init(void);
void parse_line(string &result, bool rt, bool lt);
void parse_upto(string &result, string pattern, bool include);
void parse_rest(string &result);
bool parse_eof(void);
public:
INLINE int arg_count(void);
int arg_index(const string &id);
string _text;
Filename _file;
int _parse;
vector<string> _args;
typedef pmap<PreparedGraphicsObjects *, ShaderContext *> Contexts;
Contexts _contexts;
static void register_with_read_factory(void);
friend class ShaderContext;
friend class PreparedGraphicsObjects;
ShaderContext *prepare_now(PreparedGraphicsObjects *prepared_objects,
GraphicsStateGuardianBase *gsg);
private:
void parse(void);
void clear_prepared(PreparedGraphicsObjects *prepared_objects);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedWritableReferenceCount::init_type();
register_type(_type_handle, "Shader",
TypedWritableReferenceCount::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 "shader.I"
#endif

View File

@ -1,30 +1,30 @@
// Filename: shaderContext.I
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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: ShaderContext::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE ShaderContext::
ShaderContext(Shader *s) :
_shader(s)
{
}
// Filename: shaderContext.I
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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: ShaderContext::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE ShaderContext::
ShaderContext(Shader *s) :
_shader(s)
{
}

View File

@ -1,20 +1,20 @@
// Filename: shaderContext.cxx
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 .
//
////////////////////////////////////////////////////////////////////
TypeHandle ShaderContext::_type_handle;
// Filename: shaderContext.cxx
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 .
//
////////////////////////////////////////////////////////////////////
TypeHandle ShaderContext::_type_handle;

View File

@ -1,65 +1,65 @@
// Filename: shaderContext.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 SHADERCONTEXT_H
#define SHADERCONTEXT_H
#include "pandabase.h"
#include "internalName.h"
#include "savedContext.h"
#include "shader.h"
////////////////////////////////////////////////////////////////////
// Class : ShaderContext
// Description : The ShaderContext is meant to contain the compiled
// version of a shader string. ShaderContext is an
// abstract base class, there will be a subclass of it
// for each shader language and graphics API.
// Since the languages are so different and the
// graphics APIs have so little in common, the base
// class contains almost nothing. All the implementation
// details are in the subclasses.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA ShaderContext: public SavedContext {
public:
INLINE ShaderContext(Shader *shader);
Shader *_shader;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedObject::init_type();
register_type(_type_handle, "ShaderContext",
TypedObject::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 "shaderContext.I"
#endif
// Filename: shaderContext.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 SHADERCONTEXT_H
#define SHADERCONTEXT_H
#include "pandabase.h"
#include "internalName.h"
#include "savedContext.h"
#include "shader.h"
////////////////////////////////////////////////////////////////////
// Class : ShaderContext
// Description : The ShaderContext is meant to contain the compiled
// version of a shader string. ShaderContext is an
// abstract base class, there will be a subclass of it
// for each shader language and graphics API.
// Since the languages are so different and the
// graphics APIs have so little in common, the base
// class contains almost nothing. All the implementation
// details are in the subclasses.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA ShaderContext: public SavedContext {
public:
INLINE ShaderContext(Shader *shader);
Shader *_shader;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedObject::init_type();
register_type(_type_handle, "ShaderContext",
TypedObject::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 "shaderContext.I"
#endif

View File

@ -1,120 +1,120 @@
#ifdef HAVE_CV
////////////////////////////////////////////////////////////////////
// Function: AviTexture::obtain_ram
// Access: Private
// Description: Grabs a fresh ram buffer to mess with
//
////////////////////////////////////////////////////////////////////
INLINE bool AviTexture::obtain_ram()
{
_buf=modify_ram_image();
if(_buf)
{
return true;
}
return 0;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::get_time
// Access: Published
// Description: returns the ratio between 0 and 1 that the movie is
// positioned at. Disabled for camera input
//
////////////////////////////////////////////////////////////////////
INLINE float AviTexture::get_time()
{
if(!_isCamera)
return _time;
return 0;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::set_time
// Access: Published
// Description: sets the time on the opencv video reader. Disabled
// for camera input
//
////////////////////////////////////////////////////////////////////
INLINE void AviTexture::set_time(float t)
{
if(_isCamera)
return;
if(t>=0 && t<=1)
{
_time=t;
}
if(_capture)
{
cvSetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO,t);
_current_frame=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES);
}
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::set_fps
// Access: Published
// Description: sets the fps for the movie, and affects frame recieves
// from camera. Note, since frame update is controlled
// by python, this item is sort of arbitrary
////////////////////////////////////////////////////////////////////
INLINE void AviTexture::set_fps(float fps)
{
if(fps>=0)
_fps=fps;
else
return;
if(_isCamera && _capture)
cvSetCaptureProperty(_capture,CV_CAP_PROP_FPS,int(fps));
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::get_fps
// Access: Published
// Description: returns the fps as recieved from movie
////////////////////////////////////////////////////////////////////
INLINE float AviTexture::get_fps()
{
return _fps;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::get_total_frames
// Access: Published
// Description: returns the total amount of frames
////////////////////////////////////////////////////////////////////
INLINE int AviTexture::get_total_frames()
{
return _total_frames;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::get_current_frame
// Access: Published
// Description: returns current frame (base 0)
////////////////////////////////////////////////////////////////////
INLINE int AviTexture::get_current_frame()
{
return _current_frame;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::set_current_frame
// Access: Published
// Description: sets the current frame (base 0)
////////////////////////////////////////////////////////////////////
INLINE void AviTexture::set_current_frame(int frame)
{
if(frame>=0 && frame<_total_frames)
{
_current_frame=frame;
cvSetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES,_current_frame);
_time=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO);
}
}
#endif
#ifdef HAVE_CV
////////////////////////////////////////////////////////////////////
// Function: AviTexture::obtain_ram
// Access: Private
// Description: Grabs a fresh ram buffer to mess with
//
////////////////////////////////////////////////////////////////////
INLINE bool AviTexture::obtain_ram()
{
_buf=modify_ram_image();
if(_buf)
{
return true;
}
return 0;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::get_time
// Access: Published
// Description: returns the ratio between 0 and 1 that the movie is
// positioned at. Disabled for camera input
//
////////////////////////////////////////////////////////////////////
INLINE float AviTexture::get_time()
{
if(!_isCamera)
return _time;
return 0;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::set_time
// Access: Published
// Description: sets the time on the opencv video reader. Disabled
// for camera input
//
////////////////////////////////////////////////////////////////////
INLINE void AviTexture::set_time(float t)
{
if(_isCamera)
return;
if(t>=0 && t<=1)
{
_time=t;
}
if(_capture)
{
cvSetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO,t);
_current_frame=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES);
}
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::set_fps
// Access: Published
// Description: sets the fps for the movie, and affects frame recieves
// from camera. Note, since frame update is controlled
// by python, this item is sort of arbitrary
////////////////////////////////////////////////////////////////////
INLINE void AviTexture::set_fps(float fps)
{
if(fps>=0)
_fps=fps;
else
return;
if(_isCamera && _capture)
cvSetCaptureProperty(_capture,CV_CAP_PROP_FPS,int(fps));
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::get_fps
// Access: Published
// Description: returns the fps as recieved from movie
////////////////////////////////////////////////////////////////////
INLINE float AviTexture::get_fps()
{
return _fps;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::get_total_frames
// Access: Published
// Description: returns the total amount of frames
////////////////////////////////////////////////////////////////////
INLINE int AviTexture::get_total_frames()
{
return _total_frames;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::get_current_frame
// Access: Published
// Description: returns current frame (base 0)
////////////////////////////////////////////////////////////////////
INLINE int AviTexture::get_current_frame()
{
return _current_frame;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::set_current_frame
// Access: Published
// Description: sets the current frame (base 0)
////////////////////////////////////////////////////////////////////
INLINE void AviTexture::set_current_frame(int frame)
{
if(frame>=0 && frame<_total_frames)
{
_current_frame=frame;
cvSetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES,_current_frame);
_time=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO);
}
}
#endif

View File

@ -1,160 +1,160 @@
#include "pandabase.h"
#ifdef HAVE_CV
#include "texture.h"
#include "aviTexture.h"
#include <stdio.h>
////////////////////////////////////////////////////////////////////
// Function: AviTexture::AviTexture
// Access: Published
// Description: Sets up the texture to read frames from a camera
////////////////////////////////////////////////////////////////////
AviTexture::AviTexture()
{
_isCamera=true;
_capture = cvCaptureFromCAM(0);
_buf=0;
_magicNum=0;
_time=0;
_fps=30;
_total_frames=0;
_current_frame=0;
if(_capture)
{
cvSetCaptureProperty(_capture,CV_CAP_PROP_FPS,_fps);
_width=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_WIDTH);
_height=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_HEIGHT);
if(_width<_height)
gen_tex(_width);
else
gen_tex(_height);
}
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::AviTexture
// Access: Published
// Description: Defines the texture as a movie texture.
// TODO: Make this search the panda paths
////////////////////////////////////////////////////////////////////
AviTexture::AviTexture(const string &filename)
{
_isCamera=false;
_capture = cvCaptureFromFile(filename.c_str());
_buf=0;
_magicNum=0;
_current_frame=0;
if(_capture)
{
_fps=cvGetCaptureProperty(_capture,CV_CAP_PROP_FPS);
_total_frames=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_COUNT);
_width=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_WIDTH);
_height=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_HEIGHT);
if(_width<_height)
gen_tex(_width);
else
gen_tex(_height);
}
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::~AviTexture
// Access: Published
// Description: Destructor. Release the camera or video stream
////////////////////////////////////////////////////////////////////
AviTexture::~AviTexture()
{
cvReleaseCapture(&_capture);
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::gen_tex
// Access: Published
// Description: Tries to find the largest texture that will fit
// inside the video stream. TODO: allow for fit around
////////////////////////////////////////////////////////////////////
void AviTexture::gen_tex(int magicNum)
{
if(magicNum<32)
{
magicNum=16;
}
else if(magicNum<64)
{
magicNum=32;
}
else if(magicNum<128)
{
magicNum=64;
}
else if(magicNum<256)
{
magicNum=128;
}
else if(magicNum<512)
{
magicNum=256;
}
else if(magicNum<1024)
{
magicNum=512;
}
else
magicNum=1024;
setup_2d_texture(magicNum,magicNum, Texture::T_unsigned_byte,Texture::F_rgb8);
_magicNum=magicNum;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::update
// Access: Published
// Description: Grabs the next frame off the camera or avi file
// Returns false if the capture fails or reached EOF
////////////////////////////////////////////////////////////////////
bool AviTexture::update()
{
int begx,endx,begy,endy;
IplImage* frame = 0;
int xs,ys;
if(_capture)
{
if(_time==1)
return false;
frame = cvQueryFrame( _capture );
if(frame)
{
_time=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO);
_current_frame=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES);
if(!obtain_ram())
return false;
begx=(_width-_magicNum)/2.0;
endx=_width-begx;
begy=(_height-_magicNum)/2.0;
endy=_height-begy;
if(_buf)
{
xs=get_x_size();
ys=get_y_size();
if(get_num_components()!=3)
return false;
for(int i=begy;i<endy;i++)
memcpy(_buf+((i-begy)*xs*3),frame->imageData+i*+_width*3+begx*3,xs*3);
return true;
}
}
}
return false;
}
#endif
#include "pandabase.h"
#ifdef HAVE_CV
#include "texture.h"
#include "aviTexture.h"
#include <stdio.h>
////////////////////////////////////////////////////////////////////
// Function: AviTexture::AviTexture
// Access: Published
// Description: Sets up the texture to read frames from a camera
////////////////////////////////////////////////////////////////////
AviTexture::AviTexture()
{
_isCamera=true;
_capture = cvCaptureFromCAM(0);
_buf=0;
_magicNum=0;
_time=0;
_fps=30;
_total_frames=0;
_current_frame=0;
if(_capture)
{
cvSetCaptureProperty(_capture,CV_CAP_PROP_FPS,_fps);
_width=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_WIDTH);
_height=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_HEIGHT);
if(_width<_height)
gen_tex(_width);
else
gen_tex(_height);
}
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::AviTexture
// Access: Published
// Description: Defines the texture as a movie texture.
// TODO: Make this search the panda paths
////////////////////////////////////////////////////////////////////
AviTexture::AviTexture(const string &filename)
{
_isCamera=false;
_capture = cvCaptureFromFile(filename.c_str());
_buf=0;
_magicNum=0;
_current_frame=0;
if(_capture)
{
_fps=cvGetCaptureProperty(_capture,CV_CAP_PROP_FPS);
_total_frames=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_COUNT);
_width=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_WIDTH);
_height=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_HEIGHT);
if(_width<_height)
gen_tex(_width);
else
gen_tex(_height);
}
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::~AviTexture
// Access: Published
// Description: Destructor. Release the camera or video stream
////////////////////////////////////////////////////////////////////
AviTexture::~AviTexture()
{
cvReleaseCapture(&_capture);
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::gen_tex
// Access: Published
// Description: Tries to find the largest texture that will fit
// inside the video stream. TODO: allow for fit around
////////////////////////////////////////////////////////////////////
void AviTexture::gen_tex(int magicNum)
{
if(magicNum<32)
{
magicNum=16;
}
else if(magicNum<64)
{
magicNum=32;
}
else if(magicNum<128)
{
magicNum=64;
}
else if(magicNum<256)
{
magicNum=128;
}
else if(magicNum<512)
{
magicNum=256;
}
else if(magicNum<1024)
{
magicNum=512;
}
else
magicNum=1024;
setup_2d_texture(magicNum,magicNum, Texture::T_unsigned_byte,Texture::F_rgb8);
_magicNum=magicNum;
}
////////////////////////////////////////////////////////////////////
// Function: AviTexture::update
// Access: Published
// Description: Grabs the next frame off the camera or avi file
// Returns false if the capture fails or reached EOF
////////////////////////////////////////////////////////////////////
bool AviTexture::update()
{
int begx,endx,begy,endy;
IplImage* frame = 0;
int xs,ys;
if(_capture)
{
if(_time==1)
return false;
frame = cvQueryFrame( _capture );
if(frame)
{
_time=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO);
_current_frame=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES);
if(!obtain_ram())
return false;
begx=(_width-_magicNum)/2.0;
endx=_width-begx;
begy=(_height-_magicNum)/2.0;
endy=_height-begy;
if(_buf)
{
xs=get_x_size();
ys=get_y_size();
if(get_num_components()!=3)
return false;
for(int i=begy;i<endy;i++)
memcpy(_buf+((i-begy)*xs*3),frame->imageData+i*+_width*3+begx*3,xs*3);
return true;
}
}
}
return false;
}
#endif

View File

@ -1,47 +1,47 @@
#ifndef AVITEXTURE_H
#define AVITEXTURE_H
#include "pandabase.h"
#ifdef HAVE_CV
#include "texture.h"
#include <cxcore.h>
#include <cv.h>
#include <highgui.h>
class EXPCL_PANDA AviTexture : public Texture {
PUBLISHED:
AviTexture();
AviTexture(const string &filename);
INLINE void set_time(float t);
INLINE float get_time();
INLINE float get_fps();
INLINE void set_fps(float fps);
INLINE int get_total_frames();
INLINE int get_current_frame();
INLINE void set_current_frame(int frame);
bool update();
public:
~AviTexture();
private:
void gen_tex(int magicNum);
INLINE bool obtain_ram();
int _magicNum;
PTA_uchar _buf;
CvCapture * _capture;
float _time;
bool _isCamera;
float _fps;
int _total_frames;
int _current_frame;
int _width;
int _height;
};
#include "aviTexture.I"
#endif
#endif
#ifndef AVITEXTURE_H
#define AVITEXTURE_H
#include "pandabase.h"
#ifdef HAVE_CV
#include "texture.h"
#include <cxcore.h>
#include <cv.h>
#include <highgui.h>
class EXPCL_PANDA AviTexture : public Texture {
PUBLISHED:
AviTexture();
AviTexture(const string &filename);
INLINE void set_time(float t);
INLINE float get_time();
INLINE float get_fps();
INLINE void set_fps(float fps);
INLINE int get_total_frames();
INLINE int get_current_frame();
INLINE void set_current_frame(int frame);
bool update();
public:
~AviTexture();
private:
void gen_tex(int magicNum);
INLINE bool obtain_ram();
int _magicNum;
PTA_uchar _buf;
CvCapture * _capture;
float _time;
bool _isCamera;
float _fps;
int _total_frames;
int _current_frame;
int _width;
int _height;
};
#include "aviTexture.I"
#endif
#endif

View File

@ -1,47 +1,47 @@
// Filename: shaderMode.I
// Heavily Modified: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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: ShaderModeArg::Constructor
// Access: Public
// Description: initialize a shader arg storage structure.
////////////////////////////////////////////////////////////////////
INLINE ShaderModeArg::
ShaderModeArg(void) {
_type = SAT_INVALID;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderModeArg::Destructor
// Access: Public
// Description: delete a shader arg storage structure.
////////////////////////////////////////////////////////////////////
INLINE ShaderModeArg::
~ShaderModeArg(void) {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::get_shader
// Access: Public
// Description: Return the Shader associated with this shader mode.
////////////////////////////////////////////////////////////////////
INLINE Shader *ShaderMode::
get_shader(void) {
return _shader;
}
// Filename: shaderMode.I
// Heavily Modified: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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: ShaderModeArg::Constructor
// Access: Public
// Description: initialize a shader arg storage structure.
////////////////////////////////////////////////////////////////////
INLINE ShaderModeArg::
ShaderModeArg(void) {
_type = SAT_INVALID;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderModeArg::Destructor
// Access: Public
// Description: delete a shader arg storage structure.
////////////////////////////////////////////////////////////////////
INLINE ShaderModeArg::
~ShaderModeArg(void) {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::get_shader
// Access: Public
// Description: Return the Shader associated with this shader mode.
////////////////////////////////////////////////////////////////////
INLINE Shader *ShaderMode::
get_shader(void) {
return _shader;
}

View File

@ -1,237 +1,237 @@
// Filename: shaderMode.cxx
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 "pandabase.h"
#include "shader.h"
#include "shaderMode.h"
#include "virtualFileSystem.h"
TypeHandle ShaderMode::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::load
// Access: Published
// Description: Obtain the shader associated with the specified
// file and construct a ShaderMode for that shader.
////////////////////////////////////////////////////////////////////
PT(ShaderMode) ShaderMode::
load(const Filename &file)
{
string text;
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
if (!vfs->read_file(file, text)) {
cerr << "Could not read " << file << "\n";
return new ShaderMode(new Shader("", file));
}
return new ShaderMode(new Shader(text, file));
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::load
// Access: Published
// Description: Obtain the shader associated with the specified
// file and construct a ShaderMode for that shader.
////////////////////////////////////////////////////////////////////
PT(ShaderMode) ShaderMode::
load(const string &file)
{
Filename fn(file);
return load(fn);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::make
// Access: Published
// Description: Obtain the shader associated with the specified
// text and construct a ShaderMode for that shader.
////////////////////////////////////////////////////////////////////
PT(ShaderMode) ShaderMode::
make(const string &text)
{
return new ShaderMode(new Shader(text, ""));
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::Constructor
// Access: Published
// Description: Use to construct a new shader instance.
////////////////////////////////////////////////////////////////////
ShaderMode::
ShaderMode(Shader *shader) {
_shader = shader;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::Destructor
// Access: Public
// Description: delete a shader
////////////////////////////////////////////////////////////////////
ShaderMode::
~ShaderMode() {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::mod_param
// Access: Private
// Description: To set a parameter, you must first access it and
// then clear it. This function accesses then clears
// the storage for a parameter, prior to setting it.
////////////////////////////////////////////////////////////////////
INLINE ShaderModeArg *ShaderMode::
mod_param(const string &pname, int t) {
int index = _shader->arg_index(pname);
if (index >= (int)(_args.size()))
_args.resize(index+1);
ShaderModeArg *arg = &(_args[index]);
arg->_type = t;
arg->_nvalue = NodePath();
arg->_tvalue = (Texture*)NULL;
arg->_fvalue = LVector4d(0,0,0,0);
return arg;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param texture
// Access: Public
// Description: Store texture in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, Texture *x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_TEXTURE);
arg->_tvalue = x;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param nodepath
// Access: Public
// Description: Store nodepath in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, const NodePath &x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_NODEPATH);
arg->_nvalue = x;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 1f
// Access: Public
// Description: Store 1f in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, float x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x,0,0,0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 2f
// Access: Public
// Description: Store 2f in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector2f x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x[0],x[1],0,0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 3f
// Access: Public
// Description: Store 3f in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector3f x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x[0],x[1],x[2],0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 4f
// Access: Public
// Description: Store 4f in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector4f x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x[0],x[1],x[2],x[3]);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 1d
// Access: Public
// Description: Store 1d in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, double x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x,0,0,0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 2d
// Access: Public
// Description: Store 2d in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector2d x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x[0],x[1],0,0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 3d
// Access: Public
// Description: Store 3d in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector3d x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x[0],x[1],x[2],0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 4d
// Access: Public
// Description: Store 4d in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector4d x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = x;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::register_with_read_factory
// Access: Public, Static
// Description: Factory method to generate a ShaderMode object
////////////////////////////////////////////////////////////////////
void ShaderMode::
register_with_read_factory() {
// IMPLEMENT ME
}
// Filename: shaderMode.cxx
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 "pandabase.h"
#include "shader.h"
#include "shaderMode.h"
#include "virtualFileSystem.h"
TypeHandle ShaderMode::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::load
// Access: Published
// Description: Obtain the shader associated with the specified
// file and construct a ShaderMode for that shader.
////////////////////////////////////////////////////////////////////
PT(ShaderMode) ShaderMode::
load(const Filename &file)
{
string text;
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
if (!vfs->read_file(file, text)) {
cerr << "Could not read " << file << "\n";
return new ShaderMode(new Shader("", file));
}
return new ShaderMode(new Shader(text, file));
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::load
// Access: Published
// Description: Obtain the shader associated with the specified
// file and construct a ShaderMode for that shader.
////////////////////////////////////////////////////////////////////
PT(ShaderMode) ShaderMode::
load(const string &file)
{
Filename fn(file);
return load(fn);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::make
// Access: Published
// Description: Obtain the shader associated with the specified
// text and construct a ShaderMode for that shader.
////////////////////////////////////////////////////////////////////
PT(ShaderMode) ShaderMode::
make(const string &text)
{
return new ShaderMode(new Shader(text, ""));
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::Constructor
// Access: Published
// Description: Use to construct a new shader instance.
////////////////////////////////////////////////////////////////////
ShaderMode::
ShaderMode(Shader *shader) {
_shader = shader;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::Destructor
// Access: Public
// Description: delete a shader
////////////////////////////////////////////////////////////////////
ShaderMode::
~ShaderMode() {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::mod_param
// Access: Private
// Description: To set a parameter, you must first access it and
// then clear it. This function accesses then clears
// the storage for a parameter, prior to setting it.
////////////////////////////////////////////////////////////////////
INLINE ShaderModeArg *ShaderMode::
mod_param(const string &pname, int t) {
int index = _shader->arg_index(pname);
if (index >= (int)(_args.size()))
_args.resize(index+1);
ShaderModeArg *arg = &(_args[index]);
arg->_type = t;
arg->_nvalue = NodePath();
arg->_tvalue = (Texture*)NULL;
arg->_fvalue = LVector4d(0,0,0,0);
return arg;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param texture
// Access: Public
// Description: Store texture in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, Texture *x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_TEXTURE);
arg->_tvalue = x;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param nodepath
// Access: Public
// Description: Store nodepath in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, const NodePath &x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_NODEPATH);
arg->_nvalue = x;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 1f
// Access: Public
// Description: Store 1f in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, float x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x,0,0,0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 2f
// Access: Public
// Description: Store 2f in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector2f x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x[0],x[1],0,0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 3f
// Access: Public
// Description: Store 3f in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector3f x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x[0],x[1],x[2],0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 4f
// Access: Public
// Description: Store 4f in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector4f x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x[0],x[1],x[2],x[3]);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 1d
// Access: Public
// Description: Store 1d in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, double x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x,0,0,0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 2d
// Access: Public
// Description: Store 2d in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector2d x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x[0],x[1],0,0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 3d
// Access: Public
// Description: Store 3d in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector3d x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = LVector4d(x[0],x[1],x[2],0);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::set_param 4d
// Access: Public
// Description: Store 4d in the map to associate with
// param name
////////////////////////////////////////////////////////////////////
void ShaderMode::
set_param(const string &pname, LVector4d x) {
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
arg->_fvalue = x;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderMode::register_with_read_factory
// Access: Public, Static
// Description: Factory method to generate a ShaderMode object
////////////////////////////////////////////////////////////////////
void ShaderMode::
register_with_read_factory() {
// IMPLEMENT ME
}

View File

@ -1,117 +1,117 @@
// Filename: shaderMode.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 SHADERMODE_H
#define SHADERMODE_H
#include "pandabase.h"
#include "nodePath.h"
////////////////////////////////////////////////////////////////////
// Class : ShaderModeArg
// Description : The ShaderModeArg is a small structure designed to hold
// any of the various kinds of values that can be
// passed to a shader. Basically, it is a temporary
// storage repository for shader input parameters.
////////////////////////////////////////////////////////////////////
class ShaderModeArg
{
public:
enum ShaderModeArgType
{
SAT_INVALID,
SAT_FLOAT,
SAT_TEXTURE,
SAT_NODEPATH,
};
INLINE ShaderModeArg(void);
INLINE ~ShaderModeArg(void);
int _type;
NodePath _nvalue;
PT(Texture) _tvalue;
LVector4d _fvalue;
};
////////////////////////////////////////////////////////////////////
// Class : ShaderMode
// Summary: The ShaderMode object contains a Shader and a
// list of input data to pass into the shader when
// it is executing.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA ShaderMode: public TypedWritableReferenceCount {
public:
PT(Shader) _shader;
vector<ShaderModeArg> _args;
PUBLISHED:
ShaderMode(Shader *body);
static PT(ShaderMode) load(const string &file);
static PT(ShaderMode) load(const Filename &file);
static PT(ShaderMode) make(const string &text);
~ShaderMode();
INLINE Shader *get_shader(void);
// Overloaded set_param to be used based on your param type
void set_param(const string &pname, Texture *t);
void set_param(const string &pname, const NodePath &np);
void set_param(const string &pname, float p1f);
void set_param(const string &pname, LVector2f p2f);
void set_param(const string &pname, LVector3f p3f);
void set_param(const string &pname, LVector4f p4f);
void set_param(const string &pname, double p1d);
void set_param(const string &pname, LVector2d p2d);
void set_param(const string &pname, LVector3d p3d);
void set_param(const string &pname, LVector4d p4d);
static void register_with_read_factory(void);
private:
ShaderModeArg *mod_param(const string &pname, int kind);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedWritableReferenceCount::init_type();
register_type(_type_handle, "ShaderMode",
TypedWritableReferenceCount::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 "shaderMode.I"
#endif
// Filename: shaderMode.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// 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 SHADERMODE_H
#define SHADERMODE_H
#include "pandabase.h"
#include "nodePath.h"
////////////////////////////////////////////////////////////////////
// Class : ShaderModeArg
// Description : The ShaderModeArg is a small structure designed to hold
// any of the various kinds of values that can be
// passed to a shader. Basically, it is a temporary
// storage repository for shader input parameters.
////////////////////////////////////////////////////////////////////
class ShaderModeArg
{
public:
enum ShaderModeArgType
{
SAT_INVALID,
SAT_FLOAT,
SAT_TEXTURE,
SAT_NODEPATH,
};
INLINE ShaderModeArg(void);
INLINE ~ShaderModeArg(void);
int _type;
NodePath _nvalue;
PT(Texture) _tvalue;
LVector4d _fvalue;
};
////////////////////////////////////////////////////////////////////
// Class : ShaderMode
// Summary: The ShaderMode object contains a Shader and a
// list of input data to pass into the shader when
// it is executing.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA ShaderMode: public TypedWritableReferenceCount {
public:
PT(Shader) _shader;
vector<ShaderModeArg> _args;
PUBLISHED:
ShaderMode(Shader *body);
static PT(ShaderMode) load(const string &file);
static PT(ShaderMode) load(const Filename &file);
static PT(ShaderMode) make(const string &text);
~ShaderMode();
INLINE Shader *get_shader(void);
// Overloaded set_param to be used based on your param type
void set_param(const string &pname, Texture *t);
void set_param(const string &pname, const NodePath &np);
void set_param(const string &pname, float p1f);
void set_param(const string &pname, LVector2f p2f);
void set_param(const string &pname, LVector3f p3f);
void set_param(const string &pname, LVector4f p4f);
void set_param(const string &pname, double p1d);
void set_param(const string &pname, LVector2d p2d);
void set_param(const string &pname, LVector3d p3d);
void set_param(const string &pname, LVector4d p4d);
static void register_with_read_factory(void);
private:
ShaderModeArg *mod_param(const string &pname, int kind);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedWritableReferenceCount::init_type();
register_type(_type_handle, "ShaderMode",
TypedWritableReferenceCount::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 "shaderMode.I"
#endif