Init
This commit is contained in:
@ -0,0 +1,56 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef FRAMEWORK_FOUNDATION_H
|
||||
#define FRAMEWORK_FOUNDATION_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "foundation/PxPreprocessor.h"
|
||||
|
||||
namespace physx
|
||||
{
|
||||
namespace shdfnd{}
|
||||
}
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
using namespace physx;
|
||||
namespace Fnd = physx::shdfnd;
|
||||
typedef ::FILE File;
|
||||
|
||||
} // namespace Renderer
|
||||
|
||||
#include <foundation/PxSimpleTypes.h>
|
||||
#include <foundation/PxVec3.h>
|
||||
#include <foundation/PxMat33.h>
|
||||
#include <foundation/PxMat44.h>
|
||||
#include <foundation/PxTransform.h>
|
||||
#include <foundation/PxBounds3.h>
|
||||
#include <foundation/PxErrorCallback.h>
|
||||
|
||||
#endif
|
||||
168
physx/samples/sampleframework/framework/include/ODBlock.h
Normal file
168
physx/samples/sampleframework/framework/include/ODBlock.h
Normal file
@ -0,0 +1,168 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
#ifndef ODBLOCK_H
|
||||
#define ODBLOCK_H
|
||||
/*----------------------------------------------------------------------------*\
|
||||
|
|
||||
| Ageia PhysX Technology
|
||||
|
|
||||
| www.ageia.com
|
||||
|
|
||||
\*----------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
ObjectDescription Scripts
|
||||
--------------------------
|
||||
ODScript = Block
|
||||
Statement = Block | Terminal
|
||||
Block = indent '{' {Statement} '}'
|
||||
Terminal = ident ';'
|
||||
|
||||
Comments:
|
||||
# = line comment
|
||||
/ * * / = multiline comment. The / character cannot be used in identifiers.
|
||||
|
||||
idents may be enclosed in quotes, and should be unique to facilitate searching.
|
||||
|
||||
In a typical application, program would look for known Blocks, and read out its user set terminal(s).
|
||||
Particular users define semantics:
|
||||
|
||||
SHIPFILE
|
||||
{
|
||||
Shipname
|
||||
{
|
||||
Client
|
||||
{
|
||||
ShipModel
|
||||
{
|
||||
MeshFile
|
||||
{
|
||||
Filename;
|
||||
lodlevels;
|
||||
}
|
||||
Texturefile
|
||||
{
|
||||
Filename;
|
||||
}
|
||||
}
|
||||
CockpitModel
|
||||
{
|
||||
...
|
||||
}
|
||||
}
|
||||
Server
|
||||
{
|
||||
...
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "FrameworkFoundation.h"
|
||||
#include "SampleArray.h"
|
||||
|
||||
#define OD_MAXID 30 //max identifier length
|
||||
class ODBlock;
|
||||
typedef SampleFramework::Array<ODBlock *> ODBlockList;
|
||||
|
||||
|
||||
class ODBlock
|
||||
/*-------------------------\
|
||||
| Block = indent '{' {Statement} '}'
|
||||
| Terminals are simply empty blocks
|
||||
|
|
||||
|
|
||||
\-------------------------*/
|
||||
{
|
||||
class ODSyntaxError
|
||||
{
|
||||
public:
|
||||
enum Error { ODSE_UNEX_QUOTE, ODSE_UNEX_OBRACE, ODSE_UNEX_CBRACE, ODSE_UNEX_LITERAL,ODSE_UNEX_EOF,ODSE_ENC_UNKNOWN };
|
||||
private:
|
||||
Error err;
|
||||
public:
|
||||
ODSyntaxError(Error e) {err = e;}
|
||||
const char * asString();
|
||||
};
|
||||
enum State {WAIT_IDENT,IDENT,WAIT_BLOCK,BLOCK};
|
||||
char identifier[128];
|
||||
unsigned identSize; //size of above array.
|
||||
bool bTerminal;
|
||||
ODBlockList subBlocks;
|
||||
ODBlockList::Iterator termiter; //iterator for reading terminals
|
||||
|
||||
|
||||
public:
|
||||
ODBlock(); //create a new one
|
||||
~ODBlock();
|
||||
bool loadScript(SampleFramework::File* fp);
|
||||
bool saveScript(SampleFramework::File* writeP, bool bQuote);//saves this block to scipt file. set bQuote == true if you want to machine parse output.
|
||||
|
||||
//reading:
|
||||
const char * ident();
|
||||
inline unsigned numSubBlocks() {return subBlocks.size(); }//returns number of sub blocks
|
||||
bool isTerminal(); //resets to first statement returns false if its a terminal == no contained Blocks
|
||||
|
||||
//writing:
|
||||
void ident(const char *); //identifier of the block
|
||||
void addStatement(ODBlock &);
|
||||
|
||||
//queries: return true in success
|
||||
ODBlock * getBlock(const char * identifier,bool bRecursiveSearch=false); //returns block with given identifier, or NULL.
|
||||
|
||||
void reset(); //prepares to get first terminal or sub block of current block
|
||||
|
||||
//getting terminals:
|
||||
bool moreTerminals(); //returns true if more terminals are available
|
||||
char * nextTerminal(); //returns a pointer to the next immediate terminal child of current block's identifier string.
|
||||
|
||||
//getting terminals:
|
||||
bool moreSubBlocks(); //returns true if more sub blocks (including terminals) are available
|
||||
ODBlock * nextSubBlock(); //returns a pointer to the next sub block.
|
||||
|
||||
// hig level macro functs, return true on success: (call for obj containing:)
|
||||
bool getBlockInt(const char * ident, int* p = 0, unsigned count = 1); //reads blocks of form: ident{ 123;}
|
||||
bool getBlockU32(const char * ident, physx::PxU32* p = 0, unsigned count = 1); //reads blocks of form: ident{ 123;}
|
||||
|
||||
bool getBlockString(const char * ident, const char **); //of form: ident{abcdef;}
|
||||
bool getBlockStrings(const char * ident, const char **, unsigned count); //of form: ident{abcdef; abcdef; ...}
|
||||
|
||||
bool getBlockFloat(const char * ident, float * p = 0); //of form: ident{123.456;}
|
||||
bool getBlockFloats(const char * ident, float *, unsigned count);//form: ident{12.3; 12.3; 12.3; ... };
|
||||
|
||||
bool addBlockFloats(const char * ident, float *, unsigned count);
|
||||
bool addBlockInts(const char * ident, int *, unsigned count);
|
||||
|
||||
//errors
|
||||
static const char * lastError;
|
||||
};
|
||||
|
||||
|
||||
#endif //ODBLOCK_H
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
|
||||
#ifndef SAMPLE_ACTOR_H
|
||||
#define SAMPLE_ACTOR_H
|
||||
|
||||
#include "FrameworkFoundation.h"
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
class SampleActor
|
||||
{
|
||||
public:
|
||||
SampleActor(void) {}
|
||||
virtual ~SampleActor(void) {}
|
||||
|
||||
void release(void) { delete this; }
|
||||
|
||||
public:
|
||||
virtual void tick(float /*dtime*/, bool /*rewriteBuffers*/ = false) {}
|
||||
virtual void render(bool /*rewriteBuffers*/ = false) {}
|
||||
//virtual void render(const PxMat44 &eyeT) { render(); } // TODO: provide a version of render() with some info about the current scene like camera pose...
|
||||
virtual int getType() { return -1; }
|
||||
};
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,180 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef SAMPLE_APPLICATION_H
|
||||
#define SAMPLE_APPLICATION_H
|
||||
|
||||
#include <Renderer.h>
|
||||
#include <RendererWindow.h>
|
||||
#include <RendererDesc.h>
|
||||
|
||||
#include <FrameworkFoundation.h>
|
||||
|
||||
#include <SampleAssetManager.h>
|
||||
#include <PsTime.h>
|
||||
#include <PsString.h>
|
||||
#include "foundation/PxMat44.h"
|
||||
#include <SampleUserInput.h>
|
||||
|
||||
namespace physx {
|
||||
class PxFoundation;
|
||||
}
|
||||
|
||||
#define SMOOTH_CAM
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
class SampleCommandLine;
|
||||
|
||||
template <typename T>
|
||||
class Transform
|
||||
{
|
||||
public:
|
||||
Transform() : m_dirty(true) {}
|
||||
|
||||
void setForwardTransform( const T& t )
|
||||
{
|
||||
m_fwd = t;
|
||||
m_dirty = true;
|
||||
}
|
||||
|
||||
void setInverseTransform( const T& t )
|
||||
{
|
||||
m_inv = t;
|
||||
m_fwd = t.inverseRT();
|
||||
m_dirty = false;
|
||||
}
|
||||
|
||||
const T& getForwardTransform() const
|
||||
{
|
||||
return m_fwd;
|
||||
}
|
||||
|
||||
const T& getInverseTransform() const
|
||||
{
|
||||
if(m_dirty)
|
||||
{
|
||||
m_inv = m_fwd.inverseRT();
|
||||
m_dirty = false;
|
||||
}
|
||||
return m_inv;
|
||||
}
|
||||
|
||||
private:
|
||||
T m_fwd;
|
||||
mutable T m_inv;
|
||||
mutable bool m_dirty;
|
||||
};
|
||||
|
||||
class SampleApplication : public SampleRenderer::RendererWindow
|
||||
{
|
||||
public:
|
||||
SampleApplication(const SampleCommandLine& cmdline);
|
||||
virtual ~SampleApplication(void);
|
||||
SampleRenderer::Renderer* getRenderer(void) { return m_renderer; }
|
||||
SampleAssetManager* getAssetManager(void) { return m_assetManager; }
|
||||
|
||||
const PxMat44& getEyeTransform(void) const { return m_worldToView.getInverseTransform(); }
|
||||
void setEyeTransform(const PxMat44& eyeTransform);
|
||||
void setEyeTransform(const PxVec3& pos, const PxVec3& rot);
|
||||
void setViewTransform(const PxMat44& viewTransform);
|
||||
const PxMat44& getViewTransform(void) const;
|
||||
|
||||
const SampleCommandLine& getCommandLine(void) const { return m_cmdline; }
|
||||
|
||||
virtual void onInit(void) = 0;
|
||||
virtual void onShutdown(void) = 0;
|
||||
|
||||
virtual float tweakElapsedTime(float dtime) { return dtime; }
|
||||
virtual void onTickPreRender(float dtime) = 0;
|
||||
virtual void onRender(void) = 0;
|
||||
virtual void onTickPostRender(float dtime) = 0;
|
||||
|
||||
virtual void onOpen(void);
|
||||
virtual bool onClose(void);
|
||||
|
||||
virtual void onDraw(void);
|
||||
|
||||
virtual void onAnalogInputEvent(const InputEvent& , float val);
|
||||
virtual void onDigitalInputEvent(const InputEvent& , bool val);
|
||||
virtual void onPointerInputEvent(const InputEvent&, physx::PxU32 x, physx::PxU32 y, physx::PxReal dx, physx::PxReal dy, bool val);
|
||||
|
||||
virtual void rotateCamera(PxF32 dx, PxF32 dy);
|
||||
virtual void moveCamera(PxF32 dx, PxF32 dy);
|
||||
|
||||
virtual void doInput(void);
|
||||
virtual void fatalError(const char * msg);
|
||||
|
||||
virtual PxF32 getRotationSpeedScale(void) const { return m_rotationSpeedScale; }
|
||||
virtual void setRotationSpeedScale(PxF32 scale) { m_rotationSpeedScale = scale; }
|
||||
virtual PxF32 getMoveSpeedScale(void) const { return m_moveSpeedScale; }
|
||||
virtual void setMoveSpeedScale(PxF32 scale) { m_moveSpeedScale = scale; }
|
||||
|
||||
virtual bool getRightStickRotate(void) const { return m_rightStickRotate; }
|
||||
virtual void setRightStickRotate(bool rsr) { m_rightStickRotate = rsr; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual void setupRendererDescription(SampleRenderer::RendererDesc& renDesc);
|
||||
|
||||
const SampleCommandLine& m_cmdline;
|
||||
|
||||
PxF32 m_sceneSize;
|
||||
|
||||
SampleRenderer::Renderer* m_renderer;
|
||||
|
||||
SampleAssetManager* m_assetManager;
|
||||
|
||||
PxVec3 m_eyeRot;
|
||||
Transform<PxMat44> m_worldToView;
|
||||
|
||||
PxI32 m_camMoveButton;
|
||||
|
||||
#if defined(SMOOTH_CAM)
|
||||
PxVec3 m_targetEyeRot;
|
||||
PxVec3 m_targetEyePos;
|
||||
#endif
|
||||
physx::PxU64 m_timeCounter;
|
||||
physx::shdfnd::Time m_time;
|
||||
PxF32 m_lastDTime;
|
||||
bool m_disableRendering;
|
||||
|
||||
PxF32 m_rotationSpeedScale;
|
||||
PxF32 m_moveSpeedScale;
|
||||
|
||||
bool m_rightStickRotate;
|
||||
bool m_rewriteBuffers;
|
||||
|
||||
private:
|
||||
// get rid of C4512
|
||||
void operator=(const SampleApplication&);
|
||||
};
|
||||
|
||||
} //namespace SampleFramework
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,48 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef SAMPLEFRAMEWORK_ARRAY
|
||||
#define SAMPLEFRAMEWORK_ARRAY
|
||||
|
||||
#include "PsArray.h"
|
||||
#include "PsInlineArray.h"
|
||||
#include "PsHashMap.h"
|
||||
#include "PsAllocator.h"
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
template<typename T>
|
||||
class Array : public physx::shdfnd::Array<T, physx::shdfnd::RawAllocator>
|
||||
{
|
||||
public:
|
||||
PX_INLINE explicit Array() : physx::shdfnd::Array<T, physx::shdfnd::RawAllocator>() {}
|
||||
PX_INLINE explicit Array(physx::PxU32 size, const T& a = T()) : physx::shdfnd::Array<T, physx::shdfnd::RawAllocator>(size, a) {}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,70 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef SAMPLE_ASSET_H
|
||||
#define SAMPLE_ASSET_H
|
||||
|
||||
#include "FrameworkFoundation.h"
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
class SampleAsset
|
||||
{
|
||||
friend class SampleAssetManager;
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
ASSET_MATERIAL = 0,
|
||||
ASSET_TEXTURE,
|
||||
ASSET_INPUT,
|
||||
|
||||
NUM_TYPES
|
||||
}_Type;
|
||||
|
||||
virtual bool isOk(void) const = 0;
|
||||
|
||||
Type getType(void) const { return m_type; }
|
||||
const char *getPath(void) const { return m_path; }
|
||||
|
||||
protected:
|
||||
SampleAsset(Type type, const char *path);
|
||||
virtual ~SampleAsset(void);
|
||||
|
||||
virtual void release(void) { delete this; }
|
||||
|
||||
private:
|
||||
SampleAsset &operator=(const SampleAsset&) { return *this; }
|
||||
|
||||
const Type m_type;
|
||||
char *m_path;
|
||||
PxU32 m_numUsers;
|
||||
};
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,114 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
|
||||
#ifndef SAMPLE_ASSET_MANAGER_H
|
||||
#define SAMPLE_ASSET_MANAGER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#include <SampleAsset.h>
|
||||
#include <SampleTextureAsset.h>
|
||||
|
||||
#include <RendererConfig.h>
|
||||
|
||||
|
||||
|
||||
namespace SampleRenderer
|
||||
{
|
||||
class Renderer;
|
||||
}
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
class SampleAsset;
|
||||
|
||||
class SampleAssetManager
|
||||
{
|
||||
public:
|
||||
|
||||
class SampleAssetCreator {
|
||||
public:
|
||||
virtual ~SampleAssetCreator() {}
|
||||
virtual SampleAsset* create(const char*, SampleAsset::Type) = 0;
|
||||
};
|
||||
|
||||
public:
|
||||
SampleAssetManager(SampleRenderer::Renderer &renderer,
|
||||
SampleAssetCreator* fallbackAssetCreator = NULL);
|
||||
~SampleAssetManager();
|
||||
|
||||
SampleRenderer::Renderer& getRenderer() { return m_renderer; }
|
||||
|
||||
SampleAsset* getAsset(const char* path, SampleAsset::Type type);
|
||||
void returnAsset(SampleAsset& asset);
|
||||
|
||||
protected:
|
||||
SampleAsset* findAsset(const char* path);
|
||||
SampleAsset* loadAsset(const char* path, SampleAsset::Type type);
|
||||
void releaseAsset(SampleAsset& asset);
|
||||
|
||||
void addAssetUser(SampleAsset& asset);
|
||||
void addAsset(SampleAsset* asset);
|
||||
void deleteAsset(SampleAsset* asset);
|
||||
|
||||
SampleAsset* loadXMLAsset(File& file, const char* path);
|
||||
SampleAsset* loadTextureAsset(File& file, const char* path, SampleTextureAsset::Type texType);
|
||||
SampleAsset* loadODSAsset(File& file, const char* path);
|
||||
|
||||
private:
|
||||
SampleAssetManager& operator=(const SampleAssetManager&) { return *this; }
|
||||
|
||||
protected:
|
||||
SampleRenderer::Renderer& m_renderer;
|
||||
SampleAssetCreator* m_fallbackAssetCreator;
|
||||
std::vector<SampleAsset*> m_assets;
|
||||
};
|
||||
|
||||
void addSearchPath(const char* path);
|
||||
void clearSearchPaths();
|
||||
File* findFile(const char* path, bool binary = true);
|
||||
const char* findPath(const char* path);
|
||||
|
||||
/**
|
||||
Search for the speficied path in the current directory. If not found, move up in the folder hierarchy
|
||||
until the path can be found or until the specified maximum number of steps is reached.
|
||||
|
||||
\note On consoles no recursive search will be done
|
||||
|
||||
\param [in] path The path to look for
|
||||
\param [out] buffer Buffer to store the (potentially) adjusted path
|
||||
\param [in] bufferSize Size of buffer
|
||||
\param [in] maxRecursion Maximum number steps to move up in the folder hierarchy
|
||||
return true if path was found
|
||||
*/
|
||||
bool searchForPath(const char* path, char* buffer, int bufferSize, bool isReadOnly, int maxRecursion);
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,98 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#ifndef SAMPLE_COMMANDLINE_H
|
||||
#define SAMPLE_COMMANDLINE_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
// Container for command-line arguments.
|
||||
// This class assumes argument 0 is always the executable path!
|
||||
class SampleCommandLine
|
||||
{
|
||||
public:
|
||||
//! commandLineFilePathFallback is an optional fall-back to a configuration file containing command line arguments.
|
||||
// Its contents are only processed and used if the other constructor arguments yield only an executable path.
|
||||
// This is especially useful in the case of an Andriod platform, which does not support command line options.
|
||||
// e.g. commandLineFilePathFallback = "commandline.txt"
|
||||
// e.g. contents of commandline.txt = --argument1 --argument2
|
||||
|
||||
SampleCommandLine(unsigned int argc, const char *const* argv, const char * commandLineFilePathFallback = 0);
|
||||
SampleCommandLine(const char *args, const char * commandLineFilePathFallback = 0);
|
||||
~SampleCommandLine(void);
|
||||
|
||||
//! has a given command-line switch?
|
||||
// e.g. s=="foo" checks for -foo
|
||||
bool hasSwitch(const char *s, const unsigned int argNum = invalidArgNum) const;
|
||||
|
||||
//! gets the value of a switch...
|
||||
// e.g. s="foo" returns "bar" if '-foo=bar' is in the commandline.
|
||||
const char* getValue(const char *s, unsigned int argNum = invalidArgNum) const;
|
||||
|
||||
// return how many command line arguments there are
|
||||
unsigned int getNumArgs(void) const;
|
||||
|
||||
// what is the program name
|
||||
const char* getProgramName(void) const;
|
||||
|
||||
// get the string that contains the unsued args
|
||||
unsigned int unusedArgsBufSize(void) const;
|
||||
|
||||
// get the string that contains the unsued args
|
||||
const char* getUnusedArgs(char *buf, unsigned int bufSize) const;
|
||||
|
||||
//! if the first argument is the given command.
|
||||
bool isCommand(const char *s) const;
|
||||
|
||||
//! get the first argument assuming it isn't a switch.
|
||||
// e.g. for the command-line "myapp.exe editor -foo" it will return "editor".
|
||||
const char *getCommand(void) const;
|
||||
|
||||
//! get the raw command-line argument list...
|
||||
unsigned int getArgC(void) const { return m_argc; }
|
||||
const char *const*getArgV(void) const { return m_argv; }
|
||||
|
||||
//! whether or not an argument has been read already
|
||||
bool isUsed(unsigned int argNum) const;
|
||||
|
||||
private:
|
||||
SampleCommandLine(const SampleCommandLine&);
|
||||
SampleCommandLine(void);
|
||||
SampleCommandLine operator=(const SampleCommandLine&);
|
||||
void initCommon(const char * commandLineFilePathFallback);
|
||||
unsigned int m_argc;
|
||||
const char *const *m_argv;
|
||||
void *m_freeme;
|
||||
static const unsigned int invalidArgNum = 0xFFFFFFFFU;
|
||||
bool* m_argUsed;
|
||||
};
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
#endif // SAMPLE_COMMANDLINE_H
|
||||
@ -0,0 +1,48 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef SAMPLE_DIR_MANAGER_H
|
||||
#define SAMPLE_DIR_MANAGER_H
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
class SampleDirManager
|
||||
{
|
||||
public:
|
||||
SampleDirManager(const char* relativePathRoot, bool isReadOnly = true, int maxRecursion = 20);
|
||||
|
||||
public:
|
||||
const char* getPathRoot() const { return mPathRoot; }
|
||||
const char* getFilePath(const char* relativeFilePath, char* pathBuffer, bool testFileValidity = true);
|
||||
|
||||
private:
|
||||
char mPathRoot[256];
|
||||
bool mIsReadOnly;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,59 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
|
||||
#ifndef SAMPLE_FILESYSTEM_H
|
||||
#define SAMPLE_FILESYSTEM_H
|
||||
|
||||
#include "FrameworkFoundation.h"
|
||||
|
||||
#error "Is this file ever used?"
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
/*class SampleStream : public PxFileBuf
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class SampleFilesystem
|
||||
{
|
||||
public:
|
||||
SampleFilesystem(const char *pathPrefix = "../../../../../externals/");
|
||||
~SampleFilesystem(void);
|
||||
|
||||
SampleStream *openStream(const char *path);
|
||||
void closeStream(SampleStream &stream);
|
||||
|
||||
private:
|
||||
char *m_pathPrefix;
|
||||
};
|
||||
*/
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,92 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#ifndef SAMPLE_FRAMEWORK_INPUT_EVENT_IDS_H
|
||||
#define SAMPLE_FRAMEWORK_INPUT_EVENT_IDS_H
|
||||
|
||||
static const float GAMEPAD_ROTATE_SENSITIVITY = 0.7f;
|
||||
static const float GAMEPAD_DEFAULT_SENSITIVITY = 1.0f;
|
||||
|
||||
// InputEvents used by SampleApplication
|
||||
enum SampleFrameworkInputEventIds
|
||||
{
|
||||
CAMERA_SHIFT_SPEED = 0,
|
||||
CAMERA_MOVE_LEFT,
|
||||
CAMERA_MOVE_RIGHT,
|
||||
CAMERA_MOVE_UP,
|
||||
CAMERA_MOVE_DOWN,
|
||||
CAMERA_MOVE_FORWARD,
|
||||
CAMERA_MOVE_BACKWARD,
|
||||
CAMERA_SPEED_INCREASE,
|
||||
CAMERA_SPEED_DECREASE,
|
||||
|
||||
CAMERA_MOUSE_LOOK,
|
||||
CAMERA_MOVE_BUTTON,
|
||||
|
||||
CAMERA_GAMEPAD_ROTATE_LEFT_RIGHT,
|
||||
CAMERA_GAMEPAD_ROTATE_UP_DOWN,
|
||||
CAMERA_GAMEPAD_MOVE_LEFT_RIGHT,
|
||||
CAMERA_GAMEPAD_MOVE_FORWARD_BACK,
|
||||
|
||||
CAMERA_JUMP,
|
||||
CAMERA_CROUCH,
|
||||
CAMERA_CONTROLLER_INCREASE,
|
||||
CAMERA_CONTROLLER_DECREASE,
|
||||
|
||||
NUM_SAMPLE_FRAMEWORK_INPUT_EVENT_IDS,
|
||||
};
|
||||
|
||||
// InputEvent descriptions used by SampleApplication
|
||||
const char* const SampleFrameworkInputEventDescriptions[] =
|
||||
{
|
||||
"change the camera speed",
|
||||
"move the camera left",
|
||||
"move the camera right",
|
||||
"move the camera up",
|
||||
"move the camera down",
|
||||
"move the camera forward",
|
||||
"move the camera backward",
|
||||
"increase the camera move speed",
|
||||
"decrease the camera move speed",
|
||||
|
||||
"look around with the camera",
|
||||
"enable looking around with the camera",
|
||||
|
||||
"look left and right with the camera",
|
||||
"look up and down look with the camera",
|
||||
"move the camera left and right",
|
||||
"move the camera forward and backward",
|
||||
|
||||
"jump",
|
||||
"crouch",
|
||||
"next controller",
|
||||
"previous controller",
|
||||
};
|
||||
|
||||
PX_COMPILE_TIME_ASSERT(PX_ARRAY_SIZE(SampleFrameworkInputEventDescriptions) == NUM_SAMPLE_FRAMEWORK_INPUT_EVENT_IDS);
|
||||
|
||||
#endif
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
|
||||
#ifndef SAMPLE_INPUT_ASSET_H
|
||||
#define SAMPLE_INPUT_ASSET_H
|
||||
|
||||
|
||||
#include <SampleAssetManager.h>
|
||||
#include <SampleAsset.h>
|
||||
#include <SampleUserInput.h>
|
||||
#include <ODBlock.h>
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
class SampleInputAsset : public SampleAsset
|
||||
{
|
||||
friend class SampleAssetManager;
|
||||
protected:
|
||||
SampleInputAsset(File* file, const char *path);
|
||||
virtual ~SampleInputAsset(void);
|
||||
|
||||
public:
|
||||
virtual bool isOk(void) const;
|
||||
|
||||
const T_SampleInputData& GetSampleInputData() const { return m_SampleInputData; }
|
||||
|
||||
private:
|
||||
void LoadData(ODBlock* odsSettings);
|
||||
|
||||
private:
|
||||
T_SampleInputData m_SampleInputData;
|
||||
ODBlock* m_SettingsBlock;
|
||||
ODBlock m_Mapping;
|
||||
File* m_File;
|
||||
};
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,89 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
|
||||
#ifndef SAMPLE_LINE_DEBUG_RENDER_H
|
||||
#define SAMPLE_LINE_DEBUG_RENDER_H
|
||||
|
||||
#include <RendererMeshContext.h>
|
||||
|
||||
#include <FrameworkFoundation.h>
|
||||
|
||||
namespace SampleRenderer
|
||||
{
|
||||
class Renderer;
|
||||
class RendererColor;
|
||||
class RendererVertexBuffer;
|
||||
}
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
class SampleAssetManager;
|
||||
class SampleMaterialAsset;
|
||||
|
||||
class SampleLineDebugRender
|
||||
{
|
||||
public:
|
||||
void addLine(const PxVec3 &p0, const PxVec3 &p1, const SampleRenderer::RendererColor &color);
|
||||
void checkResizeLine(PxU32 maxVerts);
|
||||
void queueForRenderLine(void);
|
||||
void clearLine(void);
|
||||
protected:
|
||||
SampleLineDebugRender(SampleRenderer::Renderer &renderer, SampleAssetManager &assetmanager);
|
||||
virtual ~SampleLineDebugRender(void);
|
||||
|
||||
private:
|
||||
void checkLock(void);
|
||||
void checkUnlock(void);
|
||||
void addVert(const PxVec3 &p, const SampleRenderer::RendererColor &color);
|
||||
|
||||
private:
|
||||
SampleLineDebugRender &operator=(const SampleLineDebugRender&) { return *this; }
|
||||
|
||||
private:
|
||||
SampleRenderer::Renderer &m_renderer;
|
||||
SampleAssetManager &m_assetmanager;
|
||||
|
||||
SampleMaterialAsset *m_material;
|
||||
|
||||
PxU32 m_maxVerts;
|
||||
PxU32 m_numVerts;
|
||||
SampleRenderer::RendererVertexBuffer *m_vertexbuffer;
|
||||
SampleRenderer::RendererMesh *m_mesh;
|
||||
SampleRenderer::RendererMeshContext m_meshContext;
|
||||
|
||||
void *m_lockedPositions;
|
||||
PxU32 m_positionStride;
|
||||
|
||||
void *m_lockedColors;
|
||||
PxU32 m_colorStride;
|
||||
};
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,81 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
|
||||
#ifndef SAMPLE_MATERIAL_ASSET_H
|
||||
#define SAMPLE_MATERIAL_ASSET_H
|
||||
|
||||
#include <SampleAsset.h>
|
||||
#include <vector>
|
||||
|
||||
namespace FAST_XML
|
||||
{
|
||||
class xml_node;
|
||||
}
|
||||
|
||||
namespace SampleRenderer
|
||||
{
|
||||
class RendererMaterial;
|
||||
class RendererMaterialInstance;
|
||||
}
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
class SampleAssetManager;
|
||||
|
||||
class SampleMaterialAsset : public SampleAsset
|
||||
{
|
||||
friend class SampleAssetManager;
|
||||
protected:
|
||||
SampleMaterialAsset(SampleAssetManager &assetManager, FAST_XML::xml_node &xmlroot, const char *path);
|
||||
SampleMaterialAsset(SampleAssetManager &assetManager, Type type, const char *path);
|
||||
virtual ~SampleMaterialAsset(void);
|
||||
|
||||
public:
|
||||
size_t getNumVertexShaders() const;
|
||||
SampleRenderer::RendererMaterial *getMaterial(size_t vertexShaderIndex = 0);
|
||||
SampleRenderer::RendererMaterialInstance *getMaterialInstance(size_t vertexShaderIndex = 0);
|
||||
unsigned int getMaxBones(size_t vertexShaderIndex) const;
|
||||
|
||||
public:
|
||||
virtual bool isOk(void) const;
|
||||
|
||||
protected:
|
||||
SampleAssetManager &m_assetManager;
|
||||
struct MaterialStruct
|
||||
{
|
||||
SampleRenderer::RendererMaterial *m_material;
|
||||
SampleRenderer::RendererMaterialInstance *m_materialInstance;
|
||||
unsigned int m_maxBones;
|
||||
};
|
||||
std::vector<MaterialStruct> m_vertexShaders;
|
||||
std::vector<SampleAsset*> m_assets;
|
||||
};
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,88 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
|
||||
#ifndef SAMPLE_POINT_DEBUG_RENDER_H
|
||||
#define SAMPLE_POINT_DEBUG_RENDER_H
|
||||
|
||||
#include <RendererMeshContext.h>
|
||||
#include <FrameworkFoundation.h>
|
||||
|
||||
namespace SampleRenderer
|
||||
{
|
||||
class Renderer;
|
||||
class RendererColor;
|
||||
class RendererVertexBuffer;
|
||||
}
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
class SampleAssetManager;
|
||||
class SampleMaterialAsset;
|
||||
|
||||
class SamplePointDebugRender
|
||||
{
|
||||
public:
|
||||
void addPoint(const PxVec3 &p0, const SampleRenderer::RendererColor &color);
|
||||
|
||||
void queueForRenderPoint(void);
|
||||
|
||||
protected:
|
||||
SamplePointDebugRender(SampleRenderer::Renderer &renderer, SampleAssetManager &assetmanager);
|
||||
virtual ~SamplePointDebugRender(void);
|
||||
|
||||
void checkResizePoint(PxU32 maxVerts);
|
||||
void clearPoint(void);
|
||||
|
||||
private:
|
||||
void checkLock(void);
|
||||
void checkUnlock(void);
|
||||
void addVert(const PxVec3 &p, const SampleRenderer::RendererColor &color);
|
||||
|
||||
SamplePointDebugRender &operator=(const SamplePointDebugRender&) { return *this; }
|
||||
|
||||
SampleRenderer::Renderer &m_renderer;
|
||||
SampleAssetManager &m_assetmanager;
|
||||
|
||||
SampleMaterialAsset *m_material;
|
||||
|
||||
PxU32 m_maxVerts;
|
||||
PxU32 m_numVerts;
|
||||
SampleRenderer::RendererVertexBuffer *m_vertexbuffer;
|
||||
SampleRenderer::RendererMesh *m_mesh;
|
||||
SampleRenderer::RendererMeshContext m_meshContext;
|
||||
|
||||
void *m_lockedPositions;
|
||||
PxU32 m_positionStride;
|
||||
|
||||
void *m_lockedColors;
|
||||
PxU32 m_colorStride;
|
||||
};
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,81 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
|
||||
#ifndef SAMPLE_TEXTURE_ASSET_H
|
||||
#define SAMPLE_TEXTURE_ASSET_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <SampleAsset.h>
|
||||
|
||||
namespace SampleRenderer
|
||||
{
|
||||
class Renderer;
|
||||
class RendererTexture;
|
||||
}
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
class SampleTextureAsset : public SampleAsset
|
||||
{
|
||||
friend class SampleAssetManager;
|
||||
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
DDS,
|
||||
TGA,
|
||||
BMP,
|
||||
PVR,
|
||||
TEXTURE_FILE_TYPE_COUNT,
|
||||
};
|
||||
|
||||
public:
|
||||
SampleTextureAsset(SampleRenderer::Renderer &renderer, File &file, const char *path, Type texType);
|
||||
virtual ~SampleTextureAsset(void);
|
||||
|
||||
public:
|
||||
SampleRenderer::RendererTexture *getTexture(void);
|
||||
const SampleRenderer::RendererTexture *getTexture(void) const;
|
||||
|
||||
public:
|
||||
virtual bool isOk(void) const;
|
||||
|
||||
private:
|
||||
void loadDDS(SampleRenderer::Renderer &renderer, File &file);
|
||||
void loadTGA(SampleRenderer::Renderer &renderer, File &file);
|
||||
void loadPVR(SampleRenderer::Renderer &renderer, File &file);
|
||||
void loadBMP(SampleRenderer::Renderer &renderer, File &file);
|
||||
|
||||
SampleRenderer::RendererTexture *m_texture;
|
||||
};
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
#endif
|
||||
83
physx/samples/sampleframework/framework/include/SampleTree.h
Normal file
83
physx/samples/sampleframework/framework/include/SampleTree.h
Normal file
@ -0,0 +1,83 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef SAMPLE_TREE_H
|
||||
#define SAMPLE_TREE_H
|
||||
|
||||
#include "foundation/Px.h"
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
class Tree
|
||||
{
|
||||
public:
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
Node() : mParent(NULL), mHead(NULL), mTail(NULL), mPrev(NULL), mNext(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
Node(const Node& node);
|
||||
Node& operator=(const Node& node);
|
||||
|
||||
public:
|
||||
PX_FORCE_INLINE bool isRoot() const { return NULL == mParent; }
|
||||
PX_FORCE_INLINE bool isLeaf() const { return NULL == mHead; }
|
||||
|
||||
PX_FORCE_INLINE Node* getParent() const { return mParent; }
|
||||
PX_FORCE_INLINE Node* getFirstChild() const { return mHead; }
|
||||
PX_FORCE_INLINE Node* getLastChild() const { return mTail; }
|
||||
PX_FORCE_INLINE Node* getPrevSibling() const { return mPrev; }
|
||||
PX_FORCE_INLINE Node* getNextSibling() const { return mNext; }
|
||||
|
||||
PX_FORCE_INLINE Node* getFirstLeaf() const { return NULL == mHead ? const_cast<Node*>(this) : mHead->getFirstLeaf(); }
|
||||
PX_FORCE_INLINE Node* getLastLeaf() const { return NULL == mTail ? const_cast<Node*>(this) : mTail->getLastLeaf(); }
|
||||
|
||||
bool isOffspringOf(const Node& node) const
|
||||
{
|
||||
return (this == &node) || (NULL != mParent && mParent->isOffspringOf(node));
|
||||
}
|
||||
|
||||
public:
|
||||
bool appendChild(Node& node);
|
||||
bool removeChild(Node& node);
|
||||
|
||||
private:
|
||||
Node* mParent;
|
||||
Node* mHead;
|
||||
Node* mTail;
|
||||
Node* mPrev;
|
||||
Node* mNext;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,95 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
|
||||
#ifndef SAMPLE_TRIANGLE_DEBUG_RENDER_H
|
||||
#define SAMPLE_TRIANGLE_DEBUG_RENDER_H
|
||||
|
||||
#include <RendererMeshContext.h>
|
||||
#include <FrameworkFoundation.h>
|
||||
|
||||
namespace SampleRenderer
|
||||
{
|
||||
class Renderer;
|
||||
class RendererColor;
|
||||
class RendererVertexBuffer;
|
||||
}
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
|
||||
class SampleAssetManager;
|
||||
class SampleMaterialAsset;
|
||||
|
||||
class SampleTriangleDebugRender
|
||||
{
|
||||
public:
|
||||
void addTriangle(const PxVec3 &p0, const PxVec3 &p1, const PxVec3 &p2, const SampleRenderer::RendererColor &color);
|
||||
void addTriangle(const PxVec3 &p0, const PxVec3 &p1, const PxVec3 &p2, const PxVec3& n0, const PxVec3& n1, const PxVec3& n2, const SampleRenderer::RendererColor &color);
|
||||
|
||||
void queueForRenderTriangle(void);
|
||||
|
||||
protected:
|
||||
SampleTriangleDebugRender(SampleRenderer::Renderer &renderer, SampleAssetManager &assetmanager);
|
||||
virtual ~SampleTriangleDebugRender(void);
|
||||
|
||||
void checkResizeTriangle(PxU32 maxVerts);
|
||||
void clearTriangle(void);
|
||||
|
||||
private:
|
||||
void checkLock(void);
|
||||
void checkUnlock(void);
|
||||
void addVert(const PxVec3 &p, const PxVec3 &n, const SampleRenderer::RendererColor &color);
|
||||
|
||||
private:
|
||||
SampleTriangleDebugRender &operator=(const SampleTriangleDebugRender&) { return *this; }
|
||||
|
||||
private:
|
||||
SampleRenderer::Renderer &m_renderer;
|
||||
SampleAssetManager &m_assetmanager;
|
||||
|
||||
SampleMaterialAsset *m_material;
|
||||
|
||||
PxU32 m_maxVerts;
|
||||
PxU32 m_numVerts;
|
||||
SampleRenderer::RendererVertexBuffer *m_vertexbuffer;
|
||||
SampleRenderer::RendererMesh *m_mesh;
|
||||
SampleRenderer::RendererMeshContext m_meshContext;
|
||||
|
||||
void *m_lockedPositions;
|
||||
PxU32 m_positionStride;
|
||||
|
||||
void *m_lockedNormals;
|
||||
PxU32 m_normalStride;
|
||||
|
||||
void *m_lockedColors;
|
||||
PxU32 m_colorStride;
|
||||
};
|
||||
|
||||
} // namespace SampleFramework
|
||||
|
||||
#endif
|
||||
163
physx/samples/sampleframework/framework/include/SampleXml.h
Normal file
163
physx/samples/sampleframework/framework/include/SampleXml.h
Normal file
@ -0,0 +1,163 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef SAMPLE_XML_H
|
||||
#define SAMPLE_XML_H
|
||||
|
||||
#include "PsFastXml.h"
|
||||
#include "PsString.h"
|
||||
#include "SampleTree.h"
|
||||
|
||||
namespace FAST_XML
|
||||
{
|
||||
|
||||
class xml_node : private SampleFramework::Tree::Node
|
||||
{
|
||||
public:
|
||||
xml_node(const char* name, const char* data, const physx::shdfnd::FastXml::AttributePairs& attr)
|
||||
: mName(name), mData(data)
|
||||
{
|
||||
PX_ASSERT( (attr.getNbAttr()*2+1) < MAX_ARGS);
|
||||
for(physx::PxI32 i=0; i<attr.getNbAttr(); i++)
|
||||
{
|
||||
mArgv[i*2] = attr.getKey(i);
|
||||
mArgv[i*2+1] = attr.getValue(i);
|
||||
}
|
||||
physx::shdfnd::FastXml::AttributePairs tmp(attr.getNbAttr()*2, mArgv);
|
||||
mAttr = tmp;
|
||||
}
|
||||
|
||||
~xml_node()
|
||||
{
|
||||
xml_node* node = first_node();
|
||||
while (node != NULL)
|
||||
{
|
||||
xml_node* child = node;
|
||||
node = node->next_sibling();
|
||||
delete child;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
xml_node* parent() const { return static_cast<xml_node*>(getParent()); }
|
||||
xml_node* first_node() const { return static_cast<xml_node*>(getFirstChild()); }
|
||||
xml_node* next_sibling() const { return static_cast<xml_node*>(getNextSibling()); }
|
||||
bool append_node(xml_node& node) { return appendChild(node); }
|
||||
|
||||
xml_node* first_node(const char* name) const
|
||||
{
|
||||
for (xml_node* node = first_node(); node != NULL; node = node->next_sibling())
|
||||
{
|
||||
if (0 == strcmp(node->name(), name))
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public:
|
||||
const char* name() const { return mName; }
|
||||
const char* value() const { return mData; }
|
||||
const char *getXMLAttribute(const char *attr) const
|
||||
{
|
||||
return mAttr.get(attr);
|
||||
}
|
||||
|
||||
private:
|
||||
static const physx::PxI32 MAX_ARGS = 50;
|
||||
|
||||
const char* mName;
|
||||
const char* mData;
|
||||
const char* mArgv[MAX_ARGS];
|
||||
physx::shdfnd::FastXml::AttributePairs mAttr;
|
||||
};
|
||||
|
||||
class XmlBuilder : public physx::shdfnd::FastXml::Callback
|
||||
{
|
||||
public:
|
||||
XmlBuilder() : mRoot(NULL), mThis(NULL) {}
|
||||
virtual ~XmlBuilder()
|
||||
{
|
||||
delete mRoot;
|
||||
}
|
||||
|
||||
public:
|
||||
xml_node* rootnode() const { return mRoot; }
|
||||
|
||||
virtual bool processComment(const char *comment)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool processClose(const char *element, physx::PxU32 depth, bool &isError)
|
||||
{
|
||||
mThis = mThis->parent();
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool processElement(
|
||||
const char *elementName, // name of the element
|
||||
const char *elementData, // element data, null if none
|
||||
const physx::shdfnd::FastXml::AttributePairs& attr, // attributes
|
||||
physx::PxI32 lineno)
|
||||
{
|
||||
xml_node* node = new xml_node(elementName, elementData, attr);
|
||||
|
||||
if (NULL != mThis)
|
||||
mThis->append_node(*node);
|
||||
else if (NULL == mRoot)
|
||||
mRoot = node;
|
||||
else
|
||||
{
|
||||
physx::shdfnd::printFormatted("error: more than 1 root node in xml file\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
mThis = node;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void* allocate(physx::PxU32 size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
virtual void deallocate(void *mem)
|
||||
{
|
||||
free(mem);
|
||||
}
|
||||
|
||||
private:
|
||||
xml_node* mRoot;
|
||||
xml_node* mThis;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
530
physx/samples/sampleframework/framework/src/ODBlock.cpp
Normal file
530
physx/samples/sampleframework/framework/src/ODBlock.cpp
Normal file
@ -0,0 +1,530 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
| |
|
||||
| ODBlock class - object description script |
|
||||
| |
|
||||
| Copyright (C) 1999 Adam Moravanszky |
|
||||
| |
|
||||
| |
|
||||
\*-------------------------------------------------------------*/
|
||||
/*-Revision----------------------\
|
||||
| At: 10/3/99 5:51:37 PM
|
||||
|
|
||||
| Changed vector container from
|
||||
| storing val to refernce.
|
||||
\-------------------------------*/
|
||||
/*-Revision----------------------\
|
||||
| At: 5/18/00 9:29:43 PM
|
||||
| changed static sized indentifiers
|
||||
| to arbitrary dynamic identifiers.
|
||||
|
|
||||
\-------------------------------*/
|
||||
/*-Revision----------------------\
|
||||
| At: 6/19/02
|
||||
| added multiline comments.
|
||||
|
|
||||
|
|
||||
\-------------------------------*/
|
||||
/*-Revision----------------------\
|
||||
| At: 5/19/03
|
||||
| fixed commend bug with
|
||||
| file > 0xffff chars.
|
||||
|
|
||||
\-------------------------------*/
|
||||
/*-Revision----------------------\
|
||||
| At: 19/10/09
|
||||
| removed encryption
|
||||
| converted to FILE * usage.
|
||||
|
|
||||
\-------------------------------*/
|
||||
#include "ODBlock.h"
|
||||
#include "PxTkFile.h"
|
||||
|
||||
const char * ODBlock::lastError = NULL;
|
||||
|
||||
|
||||
const char * ODBlock::ODSyntaxError::asString()
|
||||
{
|
||||
static const char unex1[] = "Quote unexpected.";
|
||||
static const char unex2[] = "Opening brace unexpected.";
|
||||
static const char unex3[] = "Closing brace unexpected.";
|
||||
static const char unex4[] = "Literal or semicolon unexpected.";
|
||||
static const char unex5[] = "Unexpected end of file found.";
|
||||
static const char encun[] = "Unknown encryption algo code.";
|
||||
switch (err)
|
||||
{
|
||||
case ODSE_UNEX_QUOTE:
|
||||
return unex1;
|
||||
case ODSE_UNEX_OBRACE:
|
||||
return unex2;
|
||||
case ODSE_UNEX_CBRACE:
|
||||
return unex3;
|
||||
case ODSE_UNEX_LITERAL:
|
||||
return unex4;
|
||||
case ODSE_UNEX_EOF:
|
||||
return unex5;
|
||||
case ODSE_ENC_UNKNOWN:
|
||||
return encun;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool isNewLine(char c)
|
||||
{
|
||||
return c == '\n' || c == '\r';
|
||||
}
|
||||
|
||||
bool ODBlock::loadScript(SampleFramework::File * fp) //loads block from script, including subbocks
|
||||
{
|
||||
int c;
|
||||
unsigned currindex = 0;
|
||||
bool bQuote = false; //if we're inside a pair of quotes
|
||||
identifier[0] = '\0';
|
||||
identSize = 0;
|
||||
bTerminal = true;
|
||||
termiter = NULL;
|
||||
bool ignoreWhiteSpace = true;
|
||||
|
||||
State state;
|
||||
|
||||
state = WAIT_IDENT;
|
||||
|
||||
|
||||
//0) read possible comments starting with # to end of line
|
||||
//1) read our identifier. -->forget quotes for now.
|
||||
|
||||
while(!feof(fp))
|
||||
{
|
||||
do
|
||||
{
|
||||
c = fgetc(fp);
|
||||
}
|
||||
while (ignoreWhiteSpace && ((c == ' ') || (c == '\t') || isNewLine((char)c)) && !feof(fp));
|
||||
|
||||
if (c == '"')
|
||||
{
|
||||
if (state == BLOCK)
|
||||
{
|
||||
bTerminal = false;
|
||||
ungetc(c, fp);
|
||||
ODBlock * child = new ODBlock();
|
||||
addStatement(*child);
|
||||
if (!child->loadScript(fp))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (state != WAIT_IDENT && state != IDENT)
|
||||
{
|
||||
lastError = ODSyntaxError(ODSyntaxError::ODSE_UNEX_QUOTE).asString();
|
||||
return false;
|
||||
}
|
||||
ignoreWhiteSpace = bQuote;
|
||||
bQuote = !bQuote;
|
||||
state = IDENT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bQuote)
|
||||
{
|
||||
PX_ASSERT(state == IDENT);
|
||||
//if (currindex >= identSize)
|
||||
// {
|
||||
// identSize = 2*currindex + 4;
|
||||
// char * newi = new char [identSize+1];
|
||||
// if (identifier)
|
||||
// strcpy(newi,identifier);
|
||||
// delete [] identifier;
|
||||
// identifier = newi;
|
||||
// }
|
||||
identifier[currindex] = (char) c;
|
||||
identifier[currindex+1] = 0;
|
||||
currindex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '#':
|
||||
while(!isNewLine((char)fgetc(fp))) ; //read and discard line
|
||||
break;
|
||||
case '/':
|
||||
while(fgetc(fp) != '/') ; //read and discard comment
|
||||
break;
|
||||
case '{':
|
||||
if (state != WAIT_BLOCK && state != IDENT)
|
||||
{
|
||||
lastError = ODSyntaxError(ODSyntaxError::ODSE_UNEX_OBRACE).asString();//identifier can be followed by block w/o whitespace inbetween
|
||||
return false;
|
||||
}
|
||||
state = BLOCK;
|
||||
break;
|
||||
case '}':
|
||||
if (state != BLOCK)
|
||||
{
|
||||
lastError = ODSyntaxError(ODSyntaxError::ODSE_UNEX_CBRACE).asString();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
//text
|
||||
//our identifier?
|
||||
if (state == BLOCK)
|
||||
{
|
||||
bTerminal = false;
|
||||
ungetc(c, fp);
|
||||
ODBlock * child = new ODBlock();
|
||||
addStatement(*child);
|
||||
if (!child->loadScript(fp))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (state != WAIT_IDENT && state != IDENT)
|
||||
{
|
||||
lastError = ODSyntaxError(ODSyntaxError::ODSE_UNEX_LITERAL).asString();
|
||||
return false;
|
||||
}
|
||||
if (state == IDENT && c == ';') //terminal ended
|
||||
return true;
|
||||
state = IDENT;
|
||||
//if (currindex >= identSize)
|
||||
// {
|
||||
// identSize = 2*currindex + 4;
|
||||
// char * newi = new char [identSize+1];
|
||||
// if (identifier)
|
||||
// strcpy(newi,identifier);
|
||||
// delete [] identifier;
|
||||
// identifier = newi;
|
||||
// }
|
||||
identifier[currindex] = (char)c;
|
||||
identifier[currindex+1] = 0;
|
||||
currindex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//eof and block didn't close
|
||||
lastError = ODSyntaxError(ODSyntaxError::ODSE_UNEX_EOF).asString();
|
||||
return false;
|
||||
}
|
||||
|
||||
ODBlock::ODBlock()
|
||||
{
|
||||
//create empty block
|
||||
identifier[0] = '\0';
|
||||
identSize = 0;
|
||||
bTerminal = true;
|
||||
termiter = NULL;
|
||||
subBlocks.reserve(32);
|
||||
}
|
||||
|
||||
ODBlock::~ODBlock()
|
||||
{
|
||||
//free the contents
|
||||
ODBlockList::Iterator i;
|
||||
for (i = subBlocks.begin(); i != subBlocks.end(); ++i)
|
||||
delete (*i);
|
||||
//free the pointers
|
||||
subBlocks.clear();
|
||||
|
||||
//delete [] identifier;
|
||||
identifier[0] = '\0';
|
||||
identSize = 0;
|
||||
}
|
||||
|
||||
|
||||
bool ODBlock::saveScript(SampleFramework::File * fp,bool bQuote)
|
||||
{
|
||||
static int tablevel = 1;
|
||||
static int retVal = 0;
|
||||
int j;
|
||||
//save the script in said file should be stream!!
|
||||
for (j=0; j<tablevel-1; j++)
|
||||
retVal = fprintf(fp,"\t");
|
||||
if (bQuote)
|
||||
retVal = fprintf(fp,"\"");
|
||||
if (identifier)
|
||||
retVal = fprintf(fp, "%s", identifier);
|
||||
else
|
||||
retVal = fprintf(fp,"_noname");
|
||||
if (bQuote)
|
||||
retVal = fprintf(fp,"\"");
|
||||
if (!bTerminal)
|
||||
{
|
||||
retVal =fprintf(fp,"\n");
|
||||
for (j=0; j<tablevel; j++)
|
||||
retVal = fprintf(fp,"\t");
|
||||
retVal = fprintf(fp,"{\n");
|
||||
tablevel ++;
|
||||
for (physx::PxU32 i = 0; i < subBlocks.size(); ++i)
|
||||
(subBlocks[i])->saveScript(fp,bQuote);
|
||||
tablevel --;
|
||||
for (j=0; j<tablevel; j++)
|
||||
retVal = fprintf(fp,"\t");
|
||||
retVal = fprintf(fp,"}\n");
|
||||
}
|
||||
else
|
||||
retVal = fprintf(fp,";\n");
|
||||
|
||||
PX_ASSERT( retVal >= 0 );
|
||||
// added this return to make this compile on snc & release
|
||||
return retVal >= 0;
|
||||
}
|
||||
|
||||
|
||||
const char * ODBlock::ident()
|
||||
{
|
||||
static char noname[] = "_noname";
|
||||
if (identifier)
|
||||
return identifier;
|
||||
else
|
||||
return noname;
|
||||
}
|
||||
|
||||
|
||||
bool ODBlock::isTerminal()
|
||||
{
|
||||
return bTerminal;
|
||||
}
|
||||
|
||||
|
||||
void ODBlock::ident(const char * i)
|
||||
{
|
||||
if (!i) return;
|
||||
strcpy(identifier,i);
|
||||
}
|
||||
|
||||
|
||||
void ODBlock::addStatement(ODBlock &b)
|
||||
{
|
||||
bTerminal = false;
|
||||
subBlocks.pushBack(&b);
|
||||
}
|
||||
|
||||
void ODBlock::reset() //prepares to get first immediate terminal child of current block
|
||||
{
|
||||
termiter = subBlocks.begin();
|
||||
}
|
||||
|
||||
bool ODBlock::moreTerminals() //returns true if more terminals are available
|
||||
{
|
||||
//skip any nonterminals
|
||||
while ( (termiter != subBlocks.end()) && !(*termiter)->bTerminal)
|
||||
++termiter;
|
||||
return termiter != subBlocks.end(); //return true if not the end yet
|
||||
}
|
||||
|
||||
char * ODBlock::nextTerminal() //returns a pointer to the next terminal string.
|
||||
{
|
||||
char * s = (*termiter)->identifier;
|
||||
++termiter;
|
||||
|
||||
static char noname[] = "_noname";
|
||||
if (s)
|
||||
return s;
|
||||
else
|
||||
return noname;
|
||||
}
|
||||
|
||||
bool ODBlock::moreSubBlocks() //returns true if more sub blocks are available
|
||||
{
|
||||
return termiter != subBlocks.end(); //return true if not the end yet
|
||||
}
|
||||
ODBlock * ODBlock::nextSubBlock() //returns a pointer to the next sub block.
|
||||
{
|
||||
ODBlock * b = (*termiter);
|
||||
++termiter;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
ODBlock * ODBlock::getBlock(const char * ident,bool bRecursiveSearch) //returns block with given identifier, or NULL.
|
||||
{
|
||||
ODBlock * b;
|
||||
if (identifier && ident && strncmp(identifier,ident,OD_MAXID) == 0)
|
||||
return this;
|
||||
else
|
||||
{
|
||||
if (bTerminal)
|
||||
return NULL;
|
||||
else
|
||||
{
|
||||
ODBlockList::Iterator i;
|
||||
for (i = subBlocks.begin(); i != subBlocks.end(); ++i)
|
||||
if (bRecursiveSearch)
|
||||
{
|
||||
b = (*i)->getBlock(ident,true);
|
||||
if (b)
|
||||
return b;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((*i)->identifier && ident && strncmp((*i)->identifier,ident,OD_MAXID) == 0)
|
||||
return (*i);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// hig level macro functs, return true on success:
|
||||
bool ODBlock::getBlockInt(const char * ident, int* p, unsigned count) //reads blocks of form: ident{ 123; 123; ... }
|
||||
{
|
||||
ODBlock* temp = getBlock(ident);
|
||||
if (temp)
|
||||
{
|
||||
temp->reset();
|
||||
for(; count && temp->moreTerminals(); --count)
|
||||
if(p)
|
||||
sscanf(temp->nextTerminal(),"%d", p++);
|
||||
|
||||
return !count;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// hig level macro functs, return true on success:
|
||||
bool ODBlock::getBlockU32(const char * ident, physx::PxU32* p, unsigned count) //reads blocks of form: ident{ 123;}
|
||||
{
|
||||
ODBlock* temp = getBlock(ident);
|
||||
if (temp)
|
||||
{
|
||||
temp->reset();
|
||||
for(; count && temp->moreTerminals(); --count)
|
||||
if(p)
|
||||
sscanf(temp->nextTerminal(),"%u", p++);
|
||||
|
||||
return !count;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ODBlock::getBlockString(const char * ident, const char ** p) //of form: ident{abcdef;}
|
||||
{
|
||||
ODBlock * temp = getBlock(ident);
|
||||
if (temp)
|
||||
{
|
||||
temp->reset();
|
||||
if (temp->moreTerminals())
|
||||
{
|
||||
*p = temp->nextTerminal();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool ODBlock::getBlockStrings(const char * ident, const char ** p, unsigned numStrings) //of form: ident{abcdef; abcdef;...}
|
||||
{
|
||||
ODBlock * temp= getBlock(ident);
|
||||
if (temp)
|
||||
{
|
||||
temp->reset();
|
||||
for (unsigned int n=0; n<numStrings; n++)
|
||||
{
|
||||
if (temp->moreTerminals())
|
||||
{
|
||||
p[n] = temp->nextTerminal();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool ODBlock::getBlockFloat(const char * ident, float *p) //of form: ident{123.456;}
|
||||
{
|
||||
ODBlock * temp = getBlock(ident);
|
||||
if (temp)
|
||||
{
|
||||
temp->reset();
|
||||
if (temp->moreTerminals())
|
||||
{
|
||||
if(p) sscanf(temp->nextTerminal(),"%f",p);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool ODBlock::getBlockFloats(const char * ident, float *p, unsigned numfloats)//form: ident{12.3; 12.3; 12.3; ... };
|
||||
{
|
||||
ODBlock * temp = getBlock(ident);
|
||||
if (temp)
|
||||
{
|
||||
temp->reset();
|
||||
for (unsigned int n=0; n<numfloats; n++)
|
||||
if (temp->moreTerminals()) sscanf(temp->nextTerminal(),"%f",&(p[n]));
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ODBlock::addBlockFloats(const char * ident, float *f, unsigned numfloats)
|
||||
{
|
||||
char buf[32];
|
||||
ODBlock & newBlock = *new ODBlock();
|
||||
|
||||
addStatement(newBlock);
|
||||
newBlock.ident(ident);
|
||||
|
||||
for (unsigned i = 0; i < numfloats; i++)
|
||||
{
|
||||
ODBlock & floatBlock = *new ODBlock();
|
||||
newBlock.addStatement(floatBlock);
|
||||
|
||||
//_gcvt_s(buf, 32, f[i],5); //gcc doesn't support this
|
||||
sprintf(buf, "%.5f", f[i]);
|
||||
|
||||
floatBlock.ident(buf);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ODBlock::addBlockInts(const char * ident, int *f, unsigned numInts)
|
||||
{
|
||||
char buf[32];
|
||||
ODBlock & newBlock = *new ODBlock();
|
||||
|
||||
addStatement(newBlock);
|
||||
newBlock.ident(ident);
|
||||
|
||||
for (unsigned i = 0; i < numInts; i++)
|
||||
{
|
||||
ODBlock & floatBlock = *new ODBlock();
|
||||
newBlock.addStatement(floatBlock);
|
||||
//_itoa_s(f[i], buf, 32, 10); //gcc doesn't support this
|
||||
sprintf(buf, "%d", f[i]);
|
||||
floatBlock.ident(buf);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -0,0 +1,470 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include <PsUtilities.h>
|
||||
#include <SampleApplication.h>
|
||||
#include <SampleCommandLine.h>
|
||||
#include <SampleAssetManager.h>
|
||||
#include <Renderer.h>
|
||||
#include <RendererMemoryMacros.h>
|
||||
#include <SamplePlatform.h>
|
||||
#include "SampleFrameworkInputEventIds.h"
|
||||
|
||||
#include "PsString.h"
|
||||
#include "PsFoundation.h"
|
||||
#include "PsUtilities.h"
|
||||
|
||||
namespace Ps = physx::shdfnd;
|
||||
|
||||
#define MEDIA_PATH "samples/sampleframework/media/"
|
||||
|
||||
//#define RENDERER_USE_OPENGL_ON_WINDONWS 1
|
||||
|
||||
#if defined(SMOOTH_CAM)
|
||||
const float g_smoothCamBaseVel = 6.0f;
|
||||
const float g_smoothCamFastMul = 4.0f;
|
||||
const float g_smoothCamPosLerp = 0.4f;
|
||||
|
||||
const float g_smoothCamRotSpeed = 0.005f;
|
||||
const float g_smoothCamRotLerp = 0.4f;
|
||||
#endif
|
||||
|
||||
#include "FrameworkFoundation.h"
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
static PxMat44 EulerToMat33(const PxVec3& e)
|
||||
{
|
||||
const float c1 = cosf(e.z);
|
||||
const float s1 = sinf(e.z);
|
||||
const float c2 = cosf(e.y);
|
||||
const float s2 = sinf(e.y);
|
||||
const float c3 = cosf(e.x);
|
||||
const float s3 = sinf(e.x);
|
||||
PxMat44 m;
|
||||
m.column0 = PxVec4(c1*c2, -s1*c2, s2, 0.0f);
|
||||
m.column1 = PxVec4((s1*c3)+(c1*s2*s3), (c1*c3)-(s1*s2*s3),-c2*s3, 0.0f);
|
||||
m.column2 = PxVec4((s1*s3)-(c1*s2*c3), (c1*s3)+(s1*s2*c3), c2*c3, 0.0f);
|
||||
m.column3 = PxVec4(0,0,0,1);
|
||||
return m;
|
||||
}
|
||||
|
||||
static PxVec3 Mat33ToEuler(const PxMat44& m)
|
||||
{
|
||||
const PxF32 epsilon = 0.99999f;
|
||||
PxVec3 e, x, y, z;
|
||||
|
||||
x = PxVec3(m.column0.x, m.column1.x, m.column2.x);
|
||||
y = PxVec3(m.column0.y, m.column1.y, m.column2.y);
|
||||
z = PxVec3(m.column0.z, m.column1.z, m.column2.z);
|
||||
|
||||
if(x.z > epsilon)
|
||||
{
|
||||
e.x = PxAtan2(z.y, y.y);
|
||||
e.y = PxPi * 0.5f;
|
||||
e.z = 0;
|
||||
}
|
||||
else if(x.z < -epsilon)
|
||||
{
|
||||
e.x = PxAtan2(z.y, y.y);
|
||||
e.y = -PxPi * 0.5f;
|
||||
e.z = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.x = PxAtan2(-y.z, z.z);
|
||||
e.y = PxAsin(x.z);
|
||||
e.z = PxAtan2(-x.y, x.x);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
SampleApplication::SampleApplication(const SampleCommandLine &cmdline) :
|
||||
m_cmdline(cmdline)
|
||||
, m_disableRendering(false)
|
||||
, m_rotationSpeedScale(200.0f)
|
||||
, m_moveSpeedScale(40.0f)
|
||||
, m_rightStickRotate(false)
|
||||
, m_rewriteBuffers(false)
|
||||
{
|
||||
// Don't set the working directory to the exe's working directory. We want to be able to set the working directory to have the media somewhere else.
|
||||
// m_platform->setCWDToEXE();
|
||||
m_renderer = 0;
|
||||
m_sceneSize = 1.0f;
|
||||
m_assetManager = 0;
|
||||
m_timeCounter = 0;
|
||||
m_camMoveButton = -1;
|
||||
}
|
||||
|
||||
SampleApplication::~SampleApplication(void)
|
||||
{
|
||||
RENDERER_ASSERT(!m_renderer, "Renderer was not released prior to window closure.");
|
||||
RENDERER_ASSERT(!m_assetManager, "Asset Manager was not released prior to window closure.");
|
||||
|
||||
DELETESINGLE(m_platform);
|
||||
|
||||
clearSearchPaths();
|
||||
}
|
||||
|
||||
void SampleApplication::setEyeTransform(const PxMat44& eyeTransform)
|
||||
{
|
||||
m_worldToView.setInverseTransform(eyeTransform);
|
||||
m_eyeRot = Mat33ToEuler(eyeTransform);
|
||||
#if defined(SMOOTH_CAM)
|
||||
m_targetEyePos = m_worldToView.getInverseTransform().getPosition();
|
||||
m_targetEyeRot = m_eyeRot;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SampleApplication::setEyeTransform(const PxVec3& pos, const PxVec3& rot)
|
||||
{
|
||||
PxMat44 eye;
|
||||
m_eyeRot = rot;
|
||||
eye = EulerToMat33(m_eyeRot);
|
||||
eye.setPosition(pos);
|
||||
#if defined(SMOOTH_CAM)
|
||||
m_targetEyePos = pos;
|
||||
m_targetEyeRot = m_eyeRot;
|
||||
#endif
|
||||
|
||||
m_worldToView.setInverseTransform(eye);
|
||||
}
|
||||
|
||||
void SampleApplication::setViewTransform(const PxMat44 &viewTransform)
|
||||
{
|
||||
m_worldToView.setForwardTransform(viewTransform);
|
||||
m_eyeRot = Mat33ToEuler( m_worldToView.getInverseTransform() );
|
||||
#if defined(SMOOTH_CAM)
|
||||
m_targetEyePos = m_worldToView.getInverseTransform().getPosition();
|
||||
m_targetEyeRot = m_eyeRot;
|
||||
#endif
|
||||
}
|
||||
|
||||
const PxMat44& SampleApplication::getViewTransform() const
|
||||
{
|
||||
return m_worldToView.getForwardTransform();
|
||||
}
|
||||
|
||||
void SampleApplication::onOpen(void)
|
||||
{
|
||||
m_platform->preRendererSetup();
|
||||
|
||||
m_eyeRot = PxVec3(0,0,0);
|
||||
PxMat44 eye = PxMat44(PxIdentity);
|
||||
const PxVec3 pos = PxVec3(0.0f, 2.0f, 16.0f);
|
||||
eye.setPosition(pos);
|
||||
m_worldToView.setInverseTransform(eye);
|
||||
#if defined(SMOOTH_CAM)
|
||||
m_targetEyePos = pos;
|
||||
m_targetEyeRot = m_eyeRot;
|
||||
#endif
|
||||
|
||||
// default renderer drivers for various platforms...
|
||||
SampleRenderer::RendererDesc renDesc;
|
||||
setupRendererDescription(renDesc);
|
||||
#if defined RENDERER_USE_OPENGL_ON_WINDONWS
|
||||
renDesc.driver = SampleRenderer::Renderer::DRIVER_OPENGL;
|
||||
#endif
|
||||
|
||||
// check to see if the user wants to override the renderer driver...
|
||||
if(m_cmdline.hasSwitch("ogl")) renDesc.driver = SampleRenderer::Renderer::DRIVER_OPENGL;
|
||||
else if(m_cmdline.hasSwitch("d3d9")) renDesc.driver = SampleRenderer::Renderer::DRIVER_DIRECT3D9;
|
||||
else if(m_cmdline.hasSwitch("d3d11")) renDesc.driver = SampleRenderer::Renderer::DRIVER_DIRECT3D11;
|
||||
else if(m_cmdline.hasSwitch("null")) renDesc.driver = SampleRenderer::Renderer::DRIVER_NULL;
|
||||
|
||||
char assetPath[512];
|
||||
if (!searchForPath(MEDIA_PATH, assetPath, PX_ARRAY_SIZE(assetPath), true, 20)) {
|
||||
RENDERER_ASSERT(false, MEDIA_PATH " could not be found in any of the parent directories!");
|
||||
exit(1);
|
||||
}
|
||||
addSearchPath(assetPath);
|
||||
|
||||
m_renderer = SampleRenderer::Renderer::createRenderer(renDesc, assetPath);
|
||||
m_platform->postRendererSetup(m_renderer);
|
||||
|
||||
m_timeCounter = m_time.getCurrentCounterValue();
|
||||
|
||||
m_assetManager = new SampleAssetManager(*m_renderer);
|
||||
|
||||
onInit();
|
||||
|
||||
// make sure the resize method is called once
|
||||
if (m_renderer)
|
||||
{
|
||||
PxU32 width,height;
|
||||
m_renderer->getWindowSize(width, height);
|
||||
onResize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
bool SampleApplication::onClose(void)
|
||||
{
|
||||
onShutdown();
|
||||
DELETESINGLE(m_assetManager);
|
||||
|
||||
SAFE_RELEASE(m_renderer);
|
||||
m_platform->postRendererRelease();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline float SmoothStepPolynomial( float s )
|
||||
{
|
||||
if( s <= 0 ) return 0;
|
||||
if( s >= 1 ) return 1;
|
||||
return s*s*(3-2*s);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T SmoothStep( const T& start, const T& end, float s )
|
||||
{
|
||||
float ss = SmoothStepPolynomial( s );
|
||||
return ss * (end - start) + start;
|
||||
}
|
||||
|
||||
void SampleApplication::onDraw(void)
|
||||
{
|
||||
|
||||
if (!getRenderer())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PX_PROFILE_ZONE("OnDraw", 0);
|
||||
|
||||
physx::PxU64 qpc = m_time.getCurrentCounterValue();
|
||||
static float sToSeconds = float(m_time.getBootCounterFrequency().mNumerator) / float(m_time.getBootCounterFrequency().mDenominator * m_time.sNumTensOfNanoSecondsInASecond);
|
||||
float dtime = float(qpc - m_timeCounter) * sToSeconds;
|
||||
m_lastDTime = dtime;
|
||||
m_timeCounter = qpc;
|
||||
PX_ASSERT(dtime > 0);
|
||||
if(dtime > 0)
|
||||
{
|
||||
dtime = tweakElapsedTime(dtime);
|
||||
|
||||
{
|
||||
PX_PROFILE_ZONE("PreRender", 0);
|
||||
onTickPreRender(dtime);
|
||||
}
|
||||
if(m_renderer)
|
||||
{
|
||||
PX_PROFILE_ZONE("onRender", 0);
|
||||
if(!m_disableRendering)
|
||||
{
|
||||
onRender();
|
||||
}
|
||||
}
|
||||
{
|
||||
PX_PROFILE_ZONE("onPostRender", 0);
|
||||
onTickPostRender(dtime);
|
||||
}
|
||||
|
||||
if(m_renderer && !m_disableRendering)
|
||||
{
|
||||
m_rewriteBuffers = m_renderer->swapBuffers();
|
||||
}
|
||||
|
||||
// update scene...
|
||||
|
||||
PxMat44 tmp = m_worldToView.getInverseTransform();
|
||||
PxMat44 eye = EulerToMat33(m_eyeRot);
|
||||
eye.column3 = tmp.column3;
|
||||
|
||||
PxVec3* targetParam;
|
||||
#if defined(SMOOTH_CAM)
|
||||
const float eyeSpeed = m_sceneSize * g_smoothCamBaseVel * dtime * (getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_SHIFT_SPEED) ? g_smoothCamFastMul : 1.0f);
|
||||
targetParam = &m_targetEyePos;
|
||||
#else
|
||||
const float eyeSpeed = m_sceneSize * 4.0f * dtime * (getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_SHIFT_SPEED) ? 4.0f : 1.0f);
|
||||
targetParam = &eye.t;
|
||||
#endif
|
||||
|
||||
const PxVec3 column2 = eye.getBasis(2);
|
||||
const PxVec3 column0 = eye.getBasis(0);
|
||||
const PxVec3 column1 = eye.getBasis(1);
|
||||
|
||||
if(getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_MOVE_FORWARD))
|
||||
*targetParam -= column2 * eyeSpeed;
|
||||
if(getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_MOVE_LEFT))
|
||||
*targetParam -= column0 * eyeSpeed;
|
||||
if(getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_MOVE_BACKWARD))
|
||||
*targetParam += column2 * eyeSpeed;
|
||||
if(getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_MOVE_RIGHT))
|
||||
*targetParam += column0 * eyeSpeed;
|
||||
if(getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_MOVE_UP))
|
||||
*targetParam += column1 * eyeSpeed;
|
||||
if(getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_MOVE_DOWN))
|
||||
*targetParam -= column1 * eyeSpeed;
|
||||
|
||||
// move forward from gamepad
|
||||
*targetParam -= column2 * eyeSpeed * getPlatform()->getSampleUserInput()->getAnalogInputEventState(CAMERA_GAMEPAD_MOVE_FORWARD_BACK) * m_moveSpeedScale * dtime;
|
||||
// strafe from gamepad
|
||||
*targetParam += column0 * eyeSpeed * getPlatform()->getSampleUserInput()->getAnalogInputEventState(CAMERA_GAMEPAD_MOVE_LEFT_RIGHT) * m_moveSpeedScale* dtime;
|
||||
|
||||
#if defined(SMOOTH_CAM)
|
||||
PxVec3 eye_t = eye.getPosition();
|
||||
eye_t = eye_t + (m_targetEyePos - eye_t) * g_smoothCamPosLerp;
|
||||
eye.setPosition(eye_t);
|
||||
#endif
|
||||
|
||||
// rotate from gamepad
|
||||
{
|
||||
const PxF32 rotationSpeed = m_rotationSpeedScale * dtime;
|
||||
PxF32 dx = getPlatform()->getSampleUserInput()->getAnalogInputEventState(CAMERA_GAMEPAD_ROTATE_LEFT_RIGHT) * rotationSpeed;
|
||||
PxF32 dy = getPlatform()->getSampleUserInput()->getAnalogInputEventState(CAMERA_GAMEPAD_ROTATE_UP_DOWN) * rotationSpeed;
|
||||
rotateCamera(dx, dy);
|
||||
}
|
||||
|
||||
m_worldToView.setInverseTransform(eye);
|
||||
}
|
||||
}
|
||||
|
||||
// When holding down the mouse button and dragging across the edge of the window,
|
||||
// the input provider will spit out nonsensical delta values... so threshold appropriately
|
||||
void thresholdCameraRotate(physx::PxReal& dx, physx::PxReal& dy)
|
||||
{
|
||||
static const physx::PxReal invalidDelta = 1000.f;
|
||||
if ( physx::PxAbs(dx) > invalidDelta )
|
||||
dx = physx::PxSign(dx);
|
||||
if ( physx::PxAbs(dy) > invalidDelta )
|
||||
dy = physx::PxSign(dy);
|
||||
}
|
||||
|
||||
void SampleApplication::onPointerInputEvent(const InputEvent& ie, physx::PxU32 x, physx::PxU32 y, physx::PxReal dx, physx::PxReal dy, bool val)
|
||||
{
|
||||
switch (ie.m_Id)
|
||||
{
|
||||
case CAMERA_MOUSE_LOOK:
|
||||
{
|
||||
if(getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_MOVE_BUTTON))
|
||||
{
|
||||
thresholdCameraRotate(dx, dy);
|
||||
rotateCamera(dx, dy);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SampleApplication::onDigitalInputEvent(const InputEvent& , bool val)
|
||||
{
|
||||
}
|
||||
|
||||
void SampleApplication::moveCamera(PxF32 dx, PxF32 dy)
|
||||
{
|
||||
PxMat44 tmp = m_worldToView.getInverseTransform();
|
||||
PxMat44 eye = EulerToMat33(m_eyeRot);
|
||||
eye.column3 = tmp.column3;
|
||||
|
||||
PxVec3* targetParam;
|
||||
#if defined(SMOOTH_CAM)
|
||||
const float eyeSpeed = m_sceneSize * g_smoothCamBaseVel * m_lastDTime * (getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_SHIFT_SPEED) ? g_smoothCamFastMul : 1.0f);
|
||||
targetParam = &m_targetEyePos;
|
||||
#else
|
||||
const float eyeSpeed = m_sceneSize * 4.0f * m_lastDTime * (getPlatform()->getSampleUserInput()->getDigitalInputEventState(CAMERA_SHIFT_SPEED) ? 4.0f : 1.0f);
|
||||
targetParam = &eye.t;
|
||||
#endif
|
||||
|
||||
const PxVec3 column2 = eye.getBasis(2);
|
||||
const PxVec3 column0 = eye.getBasis(0);
|
||||
|
||||
// strafe from gamepad
|
||||
*targetParam += column0 * eyeSpeed * dx * m_moveSpeedScale* m_lastDTime;
|
||||
// move forward from gamepad
|
||||
*targetParam -= column2 * eyeSpeed * dy * m_moveSpeedScale * m_lastDTime;
|
||||
|
||||
#if defined(SMOOTH_CAM)
|
||||
PxVec3 eye_t = eye.getPosition();
|
||||
eye_t = eye_t + (m_targetEyePos - eye_t) * g_smoothCamPosLerp;
|
||||
eye.setPosition(eye_t);
|
||||
#endif
|
||||
|
||||
m_worldToView.setInverseTransform(eye);
|
||||
}
|
||||
|
||||
void SampleApplication::onAnalogInputEvent(const InputEvent& ie, float val)
|
||||
{
|
||||
switch (ie.m_Id)
|
||||
{
|
||||
case CAMERA_GAMEPAD_ROTATE_LEFT_RIGHT:
|
||||
{
|
||||
rotateCamera((PxF32)val, (PxF32)0.0);
|
||||
}
|
||||
break;
|
||||
case CAMERA_GAMEPAD_ROTATE_UP_DOWN:
|
||||
{
|
||||
rotateCamera((PxF32)0.0, (PxF32)val);
|
||||
}
|
||||
break;
|
||||
case CAMERA_GAMEPAD_MOVE_LEFT_RIGHT:
|
||||
{
|
||||
moveCamera((PxF32)val, (PxF32)0.0);
|
||||
}
|
||||
break;
|
||||
case CAMERA_GAMEPAD_MOVE_FORWARD_BACK:
|
||||
{
|
||||
moveCamera((PxF32)0.0, (PxF32)val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SampleApplication::rotateCamera(PxF32 dx, PxF32 dy)
|
||||
{
|
||||
const float eyeCap = 1.5f;
|
||||
#if defined(SMOOTH_CAM)
|
||||
m_targetEyeRot.x -= dy * g_smoothCamRotSpeed;
|
||||
m_targetEyeRot.y += dx * g_smoothCamRotSpeed;
|
||||
if(m_targetEyeRot.x > eyeCap) m_targetEyeRot.x = eyeCap;
|
||||
if(m_targetEyeRot.x < -eyeCap) m_targetEyeRot.x = -eyeCap;
|
||||
|
||||
m_eyeRot= m_eyeRot + (m_targetEyeRot - m_eyeRot) * g_smoothCamRotLerp;
|
||||
#else
|
||||
const float eyeRotSpeed = 0.005f;
|
||||
m_eyeRot.x -= dy * eyeRotSpeed;
|
||||
m_eyeRot.y += dx * eyeRotSpeed;
|
||||
if(m_eyeRot.x > eyeCap) m_eyeRot.x = eyeCap;
|
||||
if(m_eyeRot.x < -eyeCap) m_eyeRot.x = -eyeCap;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SampleApplication::fatalError(const char * msg)
|
||||
{
|
||||
shdfnd::printFormatted("Fatal Error in SampleApplication: %s\n", msg);
|
||||
close();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void SampleApplication::doInput()
|
||||
{
|
||||
m_platform->doInput();
|
||||
}
|
||||
|
||||
void SampleApplication::setupRendererDescription(SampleRenderer::RendererDesc& renDesc)
|
||||
{
|
||||
m_platform->setupRendererDescription(renDesc);
|
||||
}
|
||||
|
||||
44
physx/samples/sampleframework/framework/src/SampleAsset.cpp
Normal file
44
physx/samples/sampleframework/framework/src/SampleAsset.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include <SampleAsset.h>
|
||||
#include "PsString.h"
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
SampleAsset::SampleAsset(Type type, const char *path) :
|
||||
m_type(type)
|
||||
{
|
||||
size_t len = strlen(path)+1;
|
||||
m_path = new char[len];
|
||||
physx::shdfnd::strlcpy(m_path, len, path);
|
||||
m_numUsers = 0;
|
||||
}
|
||||
|
||||
SampleAsset::~SampleAsset(void)
|
||||
{
|
||||
if(m_path) delete [] m_path;
|
||||
}
|
||||
@ -0,0 +1,436 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include <SampleAssetManager.h>
|
||||
#include <SampleAsset.h>
|
||||
#include <SampleMaterialAsset.h>
|
||||
#include <SampleTextureAsset.h>
|
||||
#include <SampleInputAsset.h>
|
||||
|
||||
#include <Renderer.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include "SamplePlatform.h"
|
||||
#include "ODBlock.h"
|
||||
|
||||
// for PsString.h
|
||||
#include <PsString.h>
|
||||
#include <PxTkFile.h>
|
||||
|
||||
namespace Ps = physx::shdfnd;
|
||||
|
||||
#include "SampleXml.h"
|
||||
#include "extensions/PxDefaultStreams.h"
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static std::vector<char*>* gSearchPaths = NULL;
|
||||
|
||||
void SampleFramework::addSearchPath(const char* path)
|
||||
{
|
||||
if(!path)
|
||||
return;
|
||||
|
||||
const PxU32 len = *path ? (PxU32)strlen(path) : 0;
|
||||
if(!len)
|
||||
return;
|
||||
|
||||
const PxU32 len2 = len+2;
|
||||
char* searchPath = new char[len2];
|
||||
Ps::strlcpy(searchPath, len2, path);
|
||||
if(path[len-1] != '/' && path[len-1] != '\\')
|
||||
{
|
||||
Ps::strlcat(searchPath, len2, "/");
|
||||
}
|
||||
if(!gSearchPaths)
|
||||
gSearchPaths = new std::vector<char*>;
|
||||
gSearchPaths->push_back(searchPath);
|
||||
}
|
||||
|
||||
void SampleFramework::clearSearchPaths()
|
||||
{
|
||||
if(!gSearchPaths)
|
||||
return;
|
||||
const PxU32 numSearchPaths = (PxU32)gSearchPaths->size();
|
||||
for(PxU32 i=0; i<numSearchPaths; i++)
|
||||
{
|
||||
delete [] (*gSearchPaths)[i];
|
||||
}
|
||||
delete gSearchPaths;
|
||||
gSearchPaths = NULL;
|
||||
}
|
||||
|
||||
static void FixSeparators(char* path)
|
||||
{
|
||||
for (unsigned i = 0; i < strlen(path); ++i)
|
||||
if (path[i] == '\\' || path[i] == '/')
|
||||
path[i] = SampleFramework::SamplePlatform::platform()->getPathSeparator()[0];
|
||||
}
|
||||
|
||||
File* SampleFramework::findFile(const char* path, bool binary)
|
||||
{
|
||||
if(!gSearchPaths)
|
||||
return NULL;
|
||||
|
||||
File* file = NULL;
|
||||
const PxU32 numSearchPaths = (PxU32)gSearchPaths->size();
|
||||
for(PxU32 i=0; i<numSearchPaths; i++)
|
||||
{
|
||||
const char* prefix = (*gSearchPaths)[i];
|
||||
|
||||
char fullPath[512];
|
||||
Ps::strlcpy(fullPath, 512, prefix);
|
||||
Ps::strlcat(fullPath, 512, path);
|
||||
FixSeparators(fullPath);
|
||||
if(binary)
|
||||
PxToolkit::fopen_s(&file, fullPath, "rb");
|
||||
else
|
||||
{
|
||||
// text files open also for write
|
||||
PxToolkit::fopen_s(&file, fullPath, "r+");
|
||||
}
|
||||
if(file) break;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
const char* SampleFramework::findPath(const char* path)
|
||||
{
|
||||
if(!gSearchPaths)
|
||||
return path;
|
||||
|
||||
static char fullPath[512];
|
||||
|
||||
File* file = NULL;
|
||||
const PxU32 numSearchPaths = (PxU32)gSearchPaths->size();
|
||||
for(PxU32 i=0; i<numSearchPaths; i++)
|
||||
{
|
||||
const char* prefix = (*gSearchPaths)[i];
|
||||
Ps::strlcpy(fullPath, 512, prefix);
|
||||
Ps::strlcat(fullPath, 512, path);
|
||||
FixSeparators(fullPath);
|
||||
PxToolkit::fopen_s(&file, fullPath, "rb");
|
||||
if(file) break;
|
||||
}
|
||||
if(file)
|
||||
{
|
||||
fclose(file);
|
||||
return fullPath;
|
||||
}
|
||||
else
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SampleAssetManager::SampleAssetManager(SampleRenderer::Renderer& renderer,
|
||||
SampleAssetCreator* fallbackAssetCreator) :
|
||||
m_renderer(renderer),
|
||||
m_fallbackAssetCreator(fallbackAssetCreator)
|
||||
{
|
||||
}
|
||||
|
||||
SampleAssetManager::~SampleAssetManager(void)
|
||||
{
|
||||
PX_ASSERT(m_assets.size() == 0);
|
||||
}
|
||||
|
||||
SampleAsset* SampleAssetManager::getAsset(const char* path, SampleAsset::Type type)
|
||||
{
|
||||
SampleAsset* asset = findAsset(path);
|
||||
if(!asset)
|
||||
{
|
||||
asset = loadAsset(path, type);
|
||||
}
|
||||
if(asset && asset->getType() != type)
|
||||
{
|
||||
releaseAsset(*asset);
|
||||
asset = 0;
|
||||
}
|
||||
if(asset)
|
||||
{
|
||||
addAssetUser(*asset);
|
||||
}
|
||||
return asset;
|
||||
}
|
||||
|
||||
void SampleAssetManager::returnAsset(SampleAsset& asset)
|
||||
{
|
||||
PX_ASSERT(asset.m_numUsers > 0);
|
||||
if(asset.m_numUsers > 0)
|
||||
{
|
||||
asset.m_numUsers--;
|
||||
}
|
||||
if(asset.m_numUsers == 0)
|
||||
{
|
||||
releaseAsset(asset);
|
||||
}
|
||||
}
|
||||
|
||||
SampleAsset* SampleAssetManager::findAsset(const char* path)
|
||||
{
|
||||
SampleAsset* asset = NULL;
|
||||
PxU32 numAssets = (PxU32)m_assets.size();
|
||||
for(PxU32 i=0; i<numAssets; i++)
|
||||
{
|
||||
if(!strcmp(m_assets[i]->getPath(), path))
|
||||
{
|
||||
asset = m_assets[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return asset;
|
||||
}
|
||||
|
||||
static const char* strext(const char* str)
|
||||
{
|
||||
const char* ext = str;
|
||||
while(str)
|
||||
{
|
||||
str = strchr(str, '.');
|
||||
if(str)
|
||||
{
|
||||
str++;
|
||||
ext = str;
|
||||
}
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
class FileExtensions
|
||||
{
|
||||
public:
|
||||
explicit FileExtensions(const char** extensions, PxU32 numExtensions)
|
||||
: mExtensions(extensions), mNumExtensions(numExtensions) { }
|
||||
|
||||
template<typename EnumType>
|
||||
EnumType typeOf(const char* extension)
|
||||
{
|
||||
PxU32 type = 0;
|
||||
while (type < mNumExtensions && (Ps::stricmp(extension, mExtensions[type]) != 0)) ++type;
|
||||
return static_cast<EnumType>(type);
|
||||
}
|
||||
|
||||
protected:
|
||||
const char** mExtensions;
|
||||
PxU32 mNumExtensions;
|
||||
};
|
||||
|
||||
enum FileType { TYPE_XML = 0, TYPE_DDS, TYPE_TGA, TYPE_ODS, TYPE_PVR, TYPE_BMP, NUM_TYPES, TYPE_NOT_SUPPORTED = NUM_TYPES };
|
||||
static const char* sSupportedExtensions[NUM_TYPES] = {"xml", "dds", "tga", "ods", "pvr", "bmp"};
|
||||
static FileExtensions sFileExtensions(sSupportedExtensions, NUM_TYPES);
|
||||
|
||||
#if defined(RENDERER_ENABLE_PVR_SUPPORT)
|
||||
static FILE* findFileExchangeExtension(const char* path, bool binary, const char* origEnding, const char* newEnding)
|
||||
{
|
||||
char pathPVR[512];
|
||||
strcpy(pathPVR, path);
|
||||
char* endStr = strstr(pathPVR, origEnding);
|
||||
strcpy(endStr, newEnding);
|
||||
return findFile(pathPVR, binary);
|
||||
}
|
||||
#endif
|
||||
|
||||
SampleAsset* SampleAssetManager::loadAsset(const char* path, SampleAsset::Type type)
|
||||
{
|
||||
SampleAsset* asset = NULL;
|
||||
const char* extension = strext(path);
|
||||
if(extension && *extension)
|
||||
{
|
||||
FileType fileType = sFileExtensions.typeOf<FileType>(extension);
|
||||
if (TYPE_NOT_SUPPORTED != fileType )
|
||||
{
|
||||
File* file = NULL;
|
||||
#if defined(RENDERER_ENABLE_PVR_SUPPORT)
|
||||
if(fileType == TYPE_DDS)
|
||||
{
|
||||
file = findFileExchangeExtension(path, true, ".dds", ".pvr");
|
||||
fileType = TYPE_PVR;
|
||||
}
|
||||
#endif
|
||||
if(!file)
|
||||
file = findFile(path, fileType != TYPE_ODS);
|
||||
|
||||
if(!file)
|
||||
PxToolkit::fopen_s(&file, path, fileType != TYPE_ODS ? "rb" : "r+");
|
||||
|
||||
if(file)
|
||||
{
|
||||
switch(fileType)
|
||||
{
|
||||
case TYPE_XML:
|
||||
asset = loadXMLAsset(*file, path);
|
||||
break;
|
||||
case TYPE_DDS:
|
||||
asset = loadTextureAsset(*file, path, SampleTextureAsset::DDS);
|
||||
break;
|
||||
case TYPE_PVR:
|
||||
asset = loadTextureAsset(*file, path, SampleTextureAsset::PVR);
|
||||
break;
|
||||
case TYPE_BMP:
|
||||
asset = loadTextureAsset(*file, path, SampleTextureAsset::BMP);
|
||||
break;
|
||||
case TYPE_TGA:
|
||||
asset = loadTextureAsset(*file, path, SampleTextureAsset::TGA);
|
||||
break;
|
||||
case TYPE_ODS:
|
||||
asset = loadODSAsset(*file, path);
|
||||
break;
|
||||
case TYPE_NOT_SUPPORTED:
|
||||
default:
|
||||
PX_ALWAYS_ASSERT();
|
||||
};
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == asset)
|
||||
{
|
||||
if (m_fallbackAssetCreator)
|
||||
{
|
||||
asset = m_fallbackAssetCreator->create(path, type);
|
||||
}
|
||||
if (NULL == asset)
|
||||
{
|
||||
|
||||
#define SAM_DEFAULT_MATERIAL "materials/simple_lit.xml"
|
||||
|
||||
#if defined(RENDERER_ENABLE_PVR_SUPPORT)
|
||||
# define SAM_DEFAULT_TEXTURE "textures/test.pvr"
|
||||
#else
|
||||
# define SAM_DEFAULT_TEXTURE "textures/test.dds"
|
||||
#endif
|
||||
|
||||
// report the missing asset
|
||||
char msg[1024];
|
||||
|
||||
if (type == SampleAsset::ASSET_MATERIAL && strcmp(path, SAM_DEFAULT_MATERIAL) ) // Avoid infinite recursion
|
||||
{
|
||||
Ps::snprintf(msg, sizeof(msg), "Could not find material: %s, loading default material: %s",
|
||||
path, SAM_DEFAULT_MATERIAL);
|
||||
RENDERER_OUTPUT_MESSAGE(&m_renderer, msg);
|
||||
|
||||
return loadAsset(SAM_DEFAULT_MATERIAL, type); // Try to use the default asset
|
||||
}
|
||||
else if (type == SampleAsset::ASSET_TEXTURE)
|
||||
{
|
||||
Ps::snprintf(msg, sizeof(msg), "Could not find texture: %s, loading default texture: %s",
|
||||
path, SAM_DEFAULT_TEXTURE);
|
||||
RENDERER_OUTPUT_MESSAGE(&m_renderer, msg);
|
||||
|
||||
return loadAsset(SAM_DEFAULT_TEXTURE, type); // Try to use the default asset
|
||||
}
|
||||
else if (fileType == TYPE_ODS)
|
||||
{
|
||||
Ps::snprintf(msg, sizeof(msg), "Could not find input definition: %s", path);
|
||||
RENDERER_OUTPUT_MESSAGE(&m_renderer, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//PX_ASSERT(asset && asset->isOk());
|
||||
if(asset && !asset->isOk())
|
||||
{
|
||||
deleteAsset(asset);
|
||||
asset = 0;
|
||||
}
|
||||
if(asset)
|
||||
{
|
||||
addAsset(asset);
|
||||
}
|
||||
return asset;
|
||||
}
|
||||
|
||||
void SampleAssetManager::releaseAsset(SampleAsset& asset)
|
||||
{
|
||||
PxU32 numAssets = (PxU32)m_assets.size();
|
||||
PxU32 found = numAssets;
|
||||
for(PxU32 i=0; i<numAssets; i++)
|
||||
{
|
||||
if(&asset == m_assets[i])
|
||||
{
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
PX_ASSERT(found < numAssets);
|
||||
if(found < numAssets)
|
||||
{
|
||||
m_assets[found] = m_assets.back();
|
||||
m_assets.pop_back();
|
||||
deleteAsset(&asset);
|
||||
}
|
||||
}
|
||||
|
||||
void SampleAssetManager::addAssetUser(SampleAsset& asset)
|
||||
{
|
||||
asset.m_numUsers++;
|
||||
}
|
||||
|
||||
void SampleAssetManager::addAsset(SampleAsset* asset)
|
||||
{
|
||||
if (asset)
|
||||
m_assets.push_back(asset);
|
||||
}
|
||||
|
||||
void SampleAssetManager::deleteAsset(SampleAsset* asset)
|
||||
{
|
||||
if (asset)
|
||||
asset->release();
|
||||
}
|
||||
|
||||
SampleAsset* SampleAssetManager::loadXMLAsset(File& file, const char* path)
|
||||
{
|
||||
SampleAsset* asset = NULL;
|
||||
|
||||
PxDefaultFileInputData theBuffer(findPath(path));
|
||||
FAST_XML::XmlBuilder builder;
|
||||
physx::shdfnd::FastXml *xml = createFastXml(&builder);
|
||||
xml->processXml(theBuffer, false);
|
||||
FAST_XML::xml_node* rootnode = builder.rootnode();
|
||||
if(!strcmp(rootnode->name(), "material"))
|
||||
{
|
||||
asset = new SampleMaterialAsset(*this, *rootnode, path);
|
||||
}
|
||||
xml->release();
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
SampleAsset* SampleAssetManager::loadTextureAsset(File& file, const char* path, SampleTextureAsset::Type texType)
|
||||
{
|
||||
SampleTextureAsset* asset = new SampleTextureAsset(getRenderer(), file, path, texType);
|
||||
return asset;
|
||||
}
|
||||
|
||||
SampleAsset* SampleAssetManager::loadODSAsset(File& file, const char* path)
|
||||
{
|
||||
SampleAsset* asset = new SampleInputAsset(&file, path);
|
||||
return asset;
|
||||
}
|
||||
@ -0,0 +1,424 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include "FrameworkFoundation.h"
|
||||
#include <SampleCommandLine.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include "PxTkFile.h"
|
||||
#include "foundation/PxAssert.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "PsString.h"
|
||||
|
||||
using namespace SampleFramework;
|
||||
namespace Ps = physx::shdfnd;
|
||||
|
||||
static char **CommandLineToArgvA(const char *cmdLine, unsigned int &_argc)
|
||||
{
|
||||
char **argv = 0;
|
||||
char *_argv = 0;
|
||||
unsigned int len = 0;
|
||||
unsigned int argc = 0;
|
||||
char a = 0;
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
bool in_QM = false;
|
||||
bool in_TEXT = false;
|
||||
bool in_SPACE = true;
|
||||
|
||||
len = (unsigned int)strlen(cmdLine);
|
||||
i = ((len+2)/2)*sizeof(char*) + sizeof(char*);
|
||||
argv = (char **)malloc(i + (len+2)*sizeof(char));
|
||||
_argv = (char *)(((char *)argv)+i);
|
||||
argv[0] = _argv;
|
||||
|
||||
i = 0;
|
||||
|
||||
a = cmdLine[i];
|
||||
while(a)
|
||||
{
|
||||
if(in_QM)
|
||||
{
|
||||
if(a == '\"')
|
||||
{
|
||||
in_QM = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_argv[j] = a;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(a)
|
||||
{
|
||||
case '\"':
|
||||
in_QM = true;
|
||||
in_TEXT = true;
|
||||
if(in_SPACE)
|
||||
{
|
||||
argv[argc] = _argv+j;
|
||||
argc++;
|
||||
}
|
||||
in_SPACE = false;
|
||||
break;
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
if(in_TEXT)
|
||||
{
|
||||
_argv[j] = '\0';
|
||||
j++;
|
||||
}
|
||||
in_TEXT = false;
|
||||
in_SPACE = true;
|
||||
break;
|
||||
default:
|
||||
in_TEXT = true;
|
||||
if(in_SPACE)
|
||||
{
|
||||
argv[argc] = _argv+j;
|
||||
argc++;
|
||||
}
|
||||
_argv[j] = a;
|
||||
j++;
|
||||
in_SPACE = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
a = cmdLine[i];
|
||||
}
|
||||
_argv[j] = '\0';
|
||||
argv[argc] = 0;
|
||||
_argc = argc;
|
||||
return argv;
|
||||
}
|
||||
|
||||
static bool isSwitchChar(char c)
|
||||
{
|
||||
return (c == '-' || c == '/');
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void operationOK(int e)
|
||||
{
|
||||
PX_UNUSED(e);
|
||||
PX_ASSERT(0 == e);
|
||||
}
|
||||
|
||||
const char * const * getCommandLineArgumentsFromFile(unsigned int & argc, const char * programName, const char * commandLineFilePath)
|
||||
{
|
||||
const char * const * argv = NULL;
|
||||
argc = 0;
|
||||
PX_ASSERT(NULL != programName);
|
||||
PX_ASSERT(NULL != commandLineFilePath);
|
||||
if(NULL != programName && NULL != commandLineFilePath)
|
||||
{
|
||||
File* commandLineFile = NULL;
|
||||
operationOK(PxToolkit::fopen_s(&commandLineFile, commandLineFilePath, "r"));
|
||||
if(NULL != commandLineFile)
|
||||
{
|
||||
operationOK(fseek(commandLineFile, 0, SEEK_END));
|
||||
const unsigned int commandLineFileCount = static_cast<unsigned int>(ftell(commandLineFile));
|
||||
rewind(commandLineFile);
|
||||
const unsigned int bufferCount = static_cast<unsigned int>(::strlen(programName)) + 1 + commandLineFileCount + 1;
|
||||
if(bufferCount > 0)
|
||||
{
|
||||
char * argsOwn = static_cast<char*>(::malloc(bufferCount));
|
||||
Ps::strlcpy(argsOwn, bufferCount, programName);
|
||||
Ps::strlcat(argsOwn, bufferCount, " ");
|
||||
const unsigned int offset = static_cast<unsigned int>(::strlen(argsOwn));
|
||||
PX_ASSERT((bufferCount - offset - 1) == commandLineFileCount);
|
||||
if(NULL != fgets(argsOwn + offset, bufferCount - offset, commandLineFile))
|
||||
{
|
||||
argv = CommandLineToArgvA(argsOwn, argc);
|
||||
}
|
||||
::free(argsOwn);
|
||||
argsOwn = NULL;
|
||||
}
|
||||
operationOK(fclose(commandLineFile));
|
||||
commandLineFile = NULL;
|
||||
}
|
||||
}
|
||||
return argv;
|
||||
}
|
||||
} //namespace nameless
|
||||
|
||||
SampleCommandLine::SampleCommandLine(unsigned int argc, const char * const * argv, const char * commandLineFilePathFallback)
|
||||
:m_argc(0)
|
||||
,m_argv(NULL)
|
||||
,m_freeme(NULL)
|
||||
,m_argUsed(NULL)
|
||||
{
|
||||
//initially, set to use inherent command line arguments
|
||||
PX_ASSERT((0 != argc) && (NULL != argv) && "This class assumes argument 0 is always the executable path!");
|
||||
m_argc = argc;
|
||||
m_argv = argv;
|
||||
|
||||
//finalize init
|
||||
initCommon(commandLineFilePathFallback);
|
||||
}
|
||||
|
||||
SampleCommandLine::SampleCommandLine(const char * args, const char * commandLineFilePathFallback)
|
||||
:m_argc(0)
|
||||
,m_argv(NULL)
|
||||
,m_freeme(NULL)
|
||||
,m_argUsed(NULL)
|
||||
{
|
||||
//initially, set to use inherent command line arguments
|
||||
unsigned int argc = 0;
|
||||
const char * const * argvOwning = NULL;
|
||||
argvOwning = CommandLineToArgvA(args, argc);
|
||||
PX_ASSERT((0 != argc) && (NULL != argvOwning) && "This class assumes argument 0 is always the executable path!");
|
||||
m_argc = argc;
|
||||
m_argv = argvOwning;
|
||||
m_freeme = const_cast<void *>(static_cast<const void *>(argvOwning));
|
||||
argvOwning = NULL;
|
||||
|
||||
//finalize init
|
||||
initCommon(commandLineFilePathFallback);
|
||||
}
|
||||
|
||||
SampleCommandLine::~SampleCommandLine(void)
|
||||
{
|
||||
if(m_freeme)
|
||||
{
|
||||
free(m_freeme);
|
||||
m_freeme = NULL;
|
||||
}
|
||||
if(m_argUsed)
|
||||
{
|
||||
delete[] m_argUsed;
|
||||
m_argUsed = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void SampleCommandLine::initCommon(const char * commandLineFilePathFallback)
|
||||
{
|
||||
//if available, set to use command line arguments from file
|
||||
const bool tryUseCommandLineArgumentsFromFile = ((1 == m_argc) && (NULL != commandLineFilePathFallback));
|
||||
if(tryUseCommandLineArgumentsFromFile)
|
||||
{
|
||||
unsigned int argcFile = 0;
|
||||
const char * const * argvFileOwn = NULL;
|
||||
argvFileOwn = getCommandLineArgumentsFromFile(argcFile, m_argv[0], commandLineFilePathFallback);
|
||||
if((0 != argcFile) && (NULL != argvFileOwn))
|
||||
{
|
||||
if(NULL != m_freeme)
|
||||
{
|
||||
::free(m_freeme);
|
||||
m_freeme = NULL;
|
||||
}
|
||||
m_argc = argcFile;
|
||||
m_argv = argvFileOwn;
|
||||
m_freeme = const_cast<void *>(static_cast<const void *>(argvFileOwn));
|
||||
argvFileOwn = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//for tracking use-status of arguments
|
||||
if((0 != m_argc) && (NULL != m_argv))
|
||||
{
|
||||
m_argUsed = new bool[m_argc];
|
||||
for(unsigned int i = 0; i < m_argc; i++)
|
||||
{
|
||||
m_argUsed[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int SampleCommandLine::getNumArgs(void) const
|
||||
{
|
||||
return(m_argc);
|
||||
}
|
||||
|
||||
const char * SampleCommandLine::getProgramName(void) const
|
||||
{
|
||||
return(m_argv[0]);
|
||||
}
|
||||
|
||||
unsigned int SampleCommandLine::unusedArgsBufSize(void) const
|
||||
{
|
||||
unsigned int bufLen = 0;
|
||||
for(unsigned int i = 1; i < m_argc; i++)
|
||||
{
|
||||
if((!m_argUsed[i]) && isSwitchChar(m_argv[i][0]))
|
||||
{
|
||||
bufLen += (unsigned int) strlen(m_argv[i]) + 1; // + 1 is for the space between unused args
|
||||
}
|
||||
}
|
||||
if(bufLen != 0)
|
||||
{
|
||||
bufLen++; // if there are unused args add a space for the '\0' char.
|
||||
}
|
||||
return(bufLen);
|
||||
}
|
||||
|
||||
const char* SampleCommandLine::getUnusedArgs(char *buf, unsigned int bufSize) const
|
||||
{
|
||||
if(bufSize != 0)
|
||||
{
|
||||
buf[0] = '\0';
|
||||
for(unsigned int i = 1; i < m_argc; i++)
|
||||
{
|
||||
if((!m_argUsed[i]) && isSwitchChar(m_argv[i][0]))
|
||||
{
|
||||
Ps::strlcat(buf, bufSize, m_argv[i]);
|
||||
Ps::strlcat(buf, bufSize, " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
return(buf);
|
||||
}
|
||||
|
||||
//! has a given command-line switch?
|
||||
// e.g. s=="foo" checks for -foo
|
||||
bool SampleCommandLine::hasSwitch(const char *s, unsigned int argNum) const
|
||||
{
|
||||
bool has = false;
|
||||
PX_ASSERT(*s);
|
||||
if(*s)
|
||||
{
|
||||
unsigned int n = (unsigned int) strlen(s);
|
||||
unsigned int firstArg;
|
||||
unsigned int lastArg;
|
||||
if(argNum != invalidArgNum)
|
||||
{
|
||||
firstArg = argNum;
|
||||
lastArg = argNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstArg = 1;
|
||||
lastArg = (m_argc > 1) ? (m_argc - 1) : 0;
|
||||
}
|
||||
for(unsigned int i=firstArg; i<=lastArg; i++)
|
||||
{
|
||||
const char *arg = m_argv[i];
|
||||
// allow switches of '/', '-', and double character versions of both.
|
||||
if( (isSwitchChar(*arg) && !Ps::strnicmp(arg+1, s, n) && ((arg[n+1]=='\0')||(arg[n+1]=='='))) ||
|
||||
(isSwitchChar(*(arg+1)) && !Ps::strnicmp(arg+2, s, n) && ((arg[n+2]=='\0')||(arg[n+2]=='='))) )
|
||||
{
|
||||
m_argUsed[i] = true;
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return has;
|
||||
}
|
||||
|
||||
//! gets the value of a switch...
|
||||
// e.g. s="foo" returns "bar" if '-foo=bar' is in the commandline.
|
||||
const char *SampleCommandLine::getValue(const char *s, unsigned int argNum) const
|
||||
{
|
||||
const char *value = 0;
|
||||
PX_ASSERT(*s);
|
||||
if(*s)
|
||||
{
|
||||
unsigned int firstArg;
|
||||
unsigned int lastArg;
|
||||
if(argNum != invalidArgNum)
|
||||
{
|
||||
firstArg = argNum;
|
||||
lastArg = argNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstArg = 1;
|
||||
lastArg = m_argc - 1;
|
||||
}
|
||||
for(unsigned int i=firstArg; i<=lastArg; i++)
|
||||
{
|
||||
const char *arg = m_argv[i];
|
||||
if(isSwitchChar(*arg))
|
||||
{
|
||||
arg++;
|
||||
if(isSwitchChar(*arg)) // is it a double dash arg? '--'
|
||||
{
|
||||
arg++;
|
||||
}
|
||||
const char *st=s;
|
||||
for(; *st && *arg && toupper(*st)==toupper(*arg) && *arg!='='; st++,arg++)
|
||||
{
|
||||
}
|
||||
if(!*st && *arg=='=')
|
||||
{
|
||||
m_argUsed[i] = true;
|
||||
value = arg+1;
|
||||
break;
|
||||
}
|
||||
if(!*st && !*arg && ((i+1)<m_argc) && (!isSwitchChar(*m_argv[i+1])))
|
||||
{
|
||||
m_argUsed[i] = true;
|
||||
value = m_argv[i+1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
//! if the first argument is the given command.
|
||||
bool SampleCommandLine::isCommand(const char *s) const
|
||||
{
|
||||
bool has = false;
|
||||
const char *command = getCommand();
|
||||
if(command && !Ps::stricmp(command, s))
|
||||
{
|
||||
has = true;
|
||||
}
|
||||
return has;
|
||||
}
|
||||
|
||||
//! get the first argument assuming it isn't a switch.
|
||||
// e.g. for the command-line "myapp.exe editor -foo" it will return "editor".
|
||||
const char *SampleCommandLine::getCommand(void) const
|
||||
{
|
||||
const char *command = 0;
|
||||
if(m_argc > 1 && !isSwitchChar(*m_argv[1]))
|
||||
{
|
||||
command = m_argv[1];
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
//! whether or not an argument has been read already
|
||||
bool SampleCommandLine::isUsed(unsigned int argNum) const
|
||||
{
|
||||
return argNum < m_argc ? m_argUsed[argNum] : false;
|
||||
}
|
||||
101
physx/samples/sampleframework/framework/src/SampleDirManager.cpp
Normal file
101
physx/samples/sampleframework/framework/src/SampleDirManager.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include "SampleDirManager.h"
|
||||
#include "SampleAssetManager.h"
|
||||
#include "SamplePlatform.h"
|
||||
#include "PsUtilities.h"
|
||||
#include "PxTkFile.h"
|
||||
#include "PsString.h"
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
static void FixPathSeparator(char* pathBuffer)
|
||||
{
|
||||
char separator = SampleFramework::SamplePlatform::platform()->getPathSeparator()[0];
|
||||
|
||||
const size_t length = strlen(pathBuffer);
|
||||
for(size_t i=0; i<length ; ++i)
|
||||
{
|
||||
if ('/' == pathBuffer[i] || '\\' == pathBuffer[i])
|
||||
pathBuffer[i] = separator;
|
||||
}
|
||||
}
|
||||
|
||||
SampleDirManager::SampleDirManager(const char* relativePathRoot, bool isReadOnly, int maxRecursion) : mIsReadOnly(isReadOnly)
|
||||
{
|
||||
if(!relativePathRoot || !SampleFramework::searchForPath(relativePathRoot, mPathRoot, PX_ARRAY_SIZE(mPathRoot), isReadOnly, maxRecursion))
|
||||
{
|
||||
shdfnd::printFormatted("path \"%s\" not found\n", relativePathRoot);
|
||||
mPathRoot[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
#define MAX_PATH_LENGTH 256
|
||||
|
||||
const char* SampleDirManager::getFilePath(const char* relativeFilePath, char* pathBuffer, bool testFileValidity)
|
||||
{
|
||||
PX_ASSERT(pathBuffer);
|
||||
|
||||
strcpy(pathBuffer, getPathRoot());
|
||||
strcat(pathBuffer, "/");
|
||||
|
||||
strcat(pathBuffer, relativeFilePath);
|
||||
if (!mIsReadOnly)
|
||||
{
|
||||
FixPathSeparator(pathBuffer);
|
||||
//strip file from path and make sure the output directory exists
|
||||
const char* ptr = strrchr(pathBuffer, '/');
|
||||
if (!ptr)
|
||||
ptr = strrchr(pathBuffer, '\\');
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
char dir[MAX_PATH_LENGTH];
|
||||
assert(MAX_PATH_LENGTH >= strlen(pathBuffer));
|
||||
strcpy(dir, pathBuffer);
|
||||
dir[ptr - pathBuffer] = '\0';
|
||||
FixPathSeparator(dir);
|
||||
SampleFramework::SamplePlatform::platform()->makeSureDirectoryPathExists(dir);
|
||||
}
|
||||
}
|
||||
|
||||
FixPathSeparator(pathBuffer);
|
||||
|
||||
if(testFileValidity)
|
||||
{
|
||||
File* fp = NULL;
|
||||
PxToolkit::fopen_s(&fp, pathBuffer, "rb");
|
||||
if(!fp)
|
||||
{
|
||||
// Kai: user can still get full path in the path buffer (side effect)
|
||||
return NULL;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return pathBuffer;
|
||||
}
|
||||
100
physx/samples/sampleframework/framework/src/SampleInputAsset.cpp
Normal file
100
physx/samples/sampleframework/framework/src/SampleInputAsset.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#include "SampleInputAsset.h"
|
||||
#include "ODBlock.h"
|
||||
#include <PxTkFile.h>
|
||||
#include <PsString.h>
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
SampleInputAsset::SampleInputAsset(File* file, const char *path)
|
||||
: SampleAsset(SampleAsset::ASSET_INPUT, path)
|
||||
, m_SettingsBlock(NULL)
|
||||
, m_File(file)
|
||||
{
|
||||
m_SampleInputData.reserve(128);
|
||||
|
||||
PX_ASSERT(file);
|
||||
|
||||
if (!m_Mapping.loadScript(file))
|
||||
{
|
||||
shdfnd::printFormatted("ODS parse error: %s in file: %s\n", m_Mapping.lastError, path);
|
||||
PX_ASSERT(0);
|
||||
}
|
||||
|
||||
m_SettingsBlock = m_Mapping.getBlock("InputMapping");
|
||||
if (!m_SettingsBlock)
|
||||
{
|
||||
shdfnd::printFormatted("No \"InputEventSettings\" block found!\n");
|
||||
PX_ASSERT(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadData(m_SettingsBlock);
|
||||
}
|
||||
}
|
||||
|
||||
SampleInputAsset::~SampleInputAsset()
|
||||
{
|
||||
if(m_File)
|
||||
{
|
||||
fclose(m_File);
|
||||
}
|
||||
}
|
||||
|
||||
void SampleInputAsset::LoadData(ODBlock* odsSettings)
|
||||
{
|
||||
odsSettings->reset();
|
||||
while (odsSettings->moreSubBlocks())
|
||||
{
|
||||
ODBlock* subBlock = odsSettings->nextSubBlock();
|
||||
subBlock->reset();
|
||||
|
||||
SampleInputData inputData;
|
||||
if (!strcmp(subBlock->ident(), "map"))
|
||||
{
|
||||
if (subBlock->moreTerminals())
|
||||
{
|
||||
const char* p = subBlock->nextTerminal();
|
||||
strcpy(inputData.m_UserInputName, p);
|
||||
}
|
||||
if (subBlock->moreTerminals())
|
||||
{
|
||||
const char* p = subBlock->nextTerminal();
|
||||
strcpy(inputData.m_InputEventName, p);
|
||||
}
|
||||
|
||||
m_SampleInputData.push_back(inputData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SampleInputAsset::isOk(void) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -0,0 +1,210 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include <SampleLineDebugRender.h>
|
||||
#include <Renderer.h>
|
||||
#include <RendererVertexBuffer.h>
|
||||
#include <RendererVertexBufferDesc.h>
|
||||
#include <RendererMesh.h>
|
||||
#include <RendererMeshDesc.h>
|
||||
#include <SampleAssetManager.h>
|
||||
#include <SampleMaterialAsset.h>
|
||||
#include <RendererMemoryMacros.h>
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
SampleLineDebugRender::SampleLineDebugRender(SampleRenderer::Renderer &renderer, SampleAssetManager &assetmanager) :
|
||||
m_renderer(renderer),
|
||||
m_assetmanager(assetmanager)
|
||||
{
|
||||
m_material = static_cast<SampleMaterialAsset*>(m_assetmanager.getAsset("materials/simple_unlit.xml", SampleAsset::ASSET_MATERIAL));
|
||||
PX_ASSERT(m_material);
|
||||
PX_ASSERT(m_material->getNumVertexShaders() == 1);
|
||||
m_meshContext.material = m_material ? m_material->getMaterial(0) : 0;
|
||||
|
||||
m_maxVerts = 0;
|
||||
m_numVerts = 0;
|
||||
m_vertexbuffer = 0;
|
||||
m_mesh = 0;
|
||||
m_lockedPositions = 0;
|
||||
m_positionStride = 0;
|
||||
m_lockedColors = 0;
|
||||
m_colorStride = 0;
|
||||
|
||||
checkResizeLine(2048);
|
||||
}
|
||||
|
||||
SampleLineDebugRender::~SampleLineDebugRender(void)
|
||||
{
|
||||
checkUnlock();
|
||||
SAFE_RELEASE(m_vertexbuffer);
|
||||
SAFE_RELEASE(m_mesh);
|
||||
if(m_material)
|
||||
{
|
||||
m_assetmanager.returnAsset(*m_material);
|
||||
}
|
||||
}
|
||||
|
||||
void SampleLineDebugRender::addLine(const PxVec3 &p0, const PxVec3 &p1, const SampleRenderer::RendererColor &color)
|
||||
{
|
||||
checkResizeLine(m_numVerts+2);
|
||||
addVert(p0, color);
|
||||
addVert(p1, color);
|
||||
}
|
||||
|
||||
void SampleLineDebugRender::queueForRenderLine(void)
|
||||
{
|
||||
if(m_meshContext.mesh)
|
||||
{
|
||||
checkUnlock();
|
||||
m_mesh->setVertexBufferRange(0, m_numVerts);
|
||||
m_renderer.queueMeshForRender(m_meshContext);
|
||||
}
|
||||
}
|
||||
|
||||
void SampleLineDebugRender::clearLine(void)
|
||||
{
|
||||
m_numVerts = 0;
|
||||
}
|
||||
|
||||
void SampleLineDebugRender::checkResizeLine(PxU32 maxVerts)
|
||||
{
|
||||
if(maxVerts > m_maxVerts)
|
||||
{
|
||||
m_maxVerts = maxVerts + (PxU32)(maxVerts*0.2f);
|
||||
|
||||
SampleRenderer::RendererVertexBufferDesc vbdesc;
|
||||
vbdesc.hint = SampleRenderer::RendererVertexBuffer::HINT_DYNAMIC;
|
||||
vbdesc.semanticFormats[SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION] = SampleRenderer::RendererVertexBuffer::FORMAT_FLOAT3;
|
||||
vbdesc.semanticFormats[SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR] = SampleRenderer::RendererVertexBuffer::FORMAT_COLOR_NATIVE; // same as RendererColor
|
||||
vbdesc.maxVertices = m_maxVerts;
|
||||
SampleRenderer::RendererVertexBuffer *vertexbuffer = m_renderer.createVertexBuffer(vbdesc);
|
||||
PX_ASSERT(vertexbuffer);
|
||||
|
||||
if(vertexbuffer)
|
||||
{
|
||||
PxU32 positionStride = 0;
|
||||
void *positions = vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION, positionStride);
|
||||
|
||||
PxU32 colorStride = 0;
|
||||
void *colors = vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR, colorStride);
|
||||
|
||||
PX_ASSERT(positions && colors);
|
||||
if(positions && colors)
|
||||
{
|
||||
if(m_numVerts > 0)
|
||||
{
|
||||
// if we have existing verts, copy them to the new VB...
|
||||
PX_ASSERT(m_lockedPositions);
|
||||
PX_ASSERT(m_lockedColors);
|
||||
if(m_lockedPositions && m_lockedColors)
|
||||
{
|
||||
for(PxU32 i=0; i<m_numVerts; i++)
|
||||
{
|
||||
memcpy(((PxU8*)positions) + (positionStride*i), ((PxU8*)m_lockedPositions) + (m_positionStride*i), sizeof(PxVec3));
|
||||
memcpy(((PxU8*)colors) + (colorStride*i), ((PxU8*)m_lockedColors) + (m_colorStride*i), sizeof(SampleRenderer::RendererColor));
|
||||
}
|
||||
}
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR);
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION);
|
||||
}
|
||||
}
|
||||
vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR);
|
||||
vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION);
|
||||
}
|
||||
if(m_vertexbuffer)
|
||||
{
|
||||
m_vertexbuffer->release();
|
||||
m_vertexbuffer = 0;
|
||||
m_lockedPositions = 0;
|
||||
m_positionStride = 0;
|
||||
m_lockedColors = 0;
|
||||
m_colorStride = 0;
|
||||
}
|
||||
SAFE_RELEASE(m_mesh);
|
||||
if(vertexbuffer)
|
||||
{
|
||||
m_vertexbuffer = vertexbuffer;
|
||||
SampleRenderer::RendererMeshDesc meshdesc;
|
||||
meshdesc.primitives = SampleRenderer::RendererMesh::PRIMITIVE_LINES;
|
||||
meshdesc.vertexBuffers = &m_vertexbuffer;
|
||||
meshdesc.numVertexBuffers = 1;
|
||||
meshdesc.firstVertex = 0;
|
||||
meshdesc.numVertices = m_numVerts;
|
||||
m_mesh = m_renderer.createMesh(meshdesc);
|
||||
PX_ASSERT(m_mesh);
|
||||
}
|
||||
m_meshContext.mesh = m_mesh;
|
||||
}
|
||||
}
|
||||
|
||||
void SampleLineDebugRender::checkLock(void)
|
||||
{
|
||||
if(m_vertexbuffer)
|
||||
{
|
||||
if(!m_lockedPositions)
|
||||
{
|
||||
m_lockedPositions = m_vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION, m_positionStride);
|
||||
PX_ASSERT(m_lockedPositions);
|
||||
}
|
||||
if(!m_lockedColors)
|
||||
{
|
||||
m_lockedColors = m_vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR, m_colorStride);
|
||||
PX_ASSERT(m_lockedColors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SampleLineDebugRender::checkUnlock(void)
|
||||
{
|
||||
if(m_vertexbuffer)
|
||||
{
|
||||
if(m_lockedPositions)
|
||||
{
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION);
|
||||
m_lockedPositions = 0;
|
||||
}
|
||||
if(m_lockedColors)
|
||||
{
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR);
|
||||
m_lockedColors = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SampleLineDebugRender::addVert(const PxVec3 &p, const SampleRenderer::RendererColor &color)
|
||||
{
|
||||
PX_ASSERT(m_maxVerts > m_numVerts);
|
||||
{
|
||||
checkLock();
|
||||
if(m_lockedPositions && m_lockedColors)
|
||||
{
|
||||
memcpy(((PxU8*)m_lockedPositions) + (m_positionStride*m_numVerts), &p, sizeof(PxVec3));
|
||||
memcpy(((PxU8*)m_lockedColors) + (m_colorStride*m_numVerts), &color, sizeof(SampleRenderer::RendererColor));
|
||||
m_numVerts++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,308 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include <SampleMaterialAsset.h>
|
||||
|
||||
#include <Renderer.h>
|
||||
#include <RendererMaterial.h>
|
||||
#include <RendererMaterialDesc.h>
|
||||
#include <RendererMaterialInstance.h>
|
||||
|
||||
#include <SampleAssetManager.h>
|
||||
#include <SampleTextureAsset.h>
|
||||
|
||||
#include "SampleXml.h"
|
||||
#include <ctype.h>
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
static SampleRenderer::RendererMaterial::BlendFunc
|
||||
getBlendFunc(const char* nodeValue,
|
||||
SampleRenderer::RendererMaterial::BlendFunc defaultBlendFunc = SampleRenderer::RendererMaterial::BLEND_ONE)
|
||||
{
|
||||
using SampleRenderer::RendererMaterial;
|
||||
RendererMaterial::BlendFunc blendFunc = defaultBlendFunc;
|
||||
if( !strcmp(nodeValue, "ZERO")) blendFunc = RendererMaterial::BLEND_ZERO;
|
||||
else if(!strcmp(nodeValue, "ONE")) blendFunc = RendererMaterial::BLEND_ONE;
|
||||
else if(!strcmp(nodeValue, "SRC_COLOR")) blendFunc = RendererMaterial::BLEND_SRC_COLOR;
|
||||
else if(!strcmp(nodeValue, "ONE_MINUS_SRC_COLOR")) blendFunc = RendererMaterial::BLEND_ONE_MINUS_SRC_COLOR;
|
||||
else if(!strcmp(nodeValue, "SRC_ALPHA")) blendFunc = RendererMaterial::BLEND_SRC_ALPHA;
|
||||
else if(!strcmp(nodeValue, "ONE_MINUS_SRC_ALPHA")) blendFunc = RendererMaterial::BLEND_ONE_MINUS_SRC_ALPHA;
|
||||
else if(!strcmp(nodeValue, "DST_COLOR")) blendFunc = RendererMaterial::BLEND_DST_COLOR;
|
||||
else if(!strcmp(nodeValue, "ONE_MINUS_DST_COLOR")) blendFunc = RendererMaterial::BLEND_ONE_MINUS_DST_COLOR;
|
||||
else if(!strcmp(nodeValue, "DST_ALPHA")) blendFunc = RendererMaterial::BLEND_DST_ALPHA;
|
||||
else if(!strcmp(nodeValue, "ONE_MINUS_DST_ALPHA")) blendFunc = RendererMaterial::BLEND_ONE_MINUS_DST_ALPHA;
|
||||
else if(!strcmp(nodeValue, "SRC_ALPHA_SATURATE")) blendFunc = RendererMaterial::BLEND_SRC_ALPHA_SATURATE;
|
||||
else PX_ASSERT(0); // Unknown blend func!
|
||||
|
||||
return blendFunc;
|
||||
}
|
||||
|
||||
static void readFloats(const char *str, float *floats, unsigned int numFloats)
|
||||
{
|
||||
PxU32 fcount = 0;
|
||||
while(*str && !((*str>='0'&&*str<='9') || *str=='.')) str++;
|
||||
for(PxU32 i=0; i<numFloats; i++)
|
||||
{
|
||||
if(*str)
|
||||
{
|
||||
floats[i] = (float)atof(str);
|
||||
while(*str && ((*str>='0'&&*str<='9') || *str=='.')) str++;
|
||||
while(*str && !((*str>='0'&&*str<='9') || *str=='.')) str++;
|
||||
fcount++;
|
||||
}
|
||||
}
|
||||
PX_ASSERT(fcount==numFloats);
|
||||
}
|
||||
|
||||
SampleMaterialAsset::SampleMaterialAsset(SampleAssetManager &assetManager, FAST_XML::xml_node &xmlroot, const char *path) :
|
||||
SampleAsset(ASSET_MATERIAL, path),
|
||||
m_assetManager(assetManager)
|
||||
{
|
||||
|
||||
std::vector<const char*> mVertexShaderPaths;
|
||||
//m_material = 0;
|
||||
//m_materialInstance = 0;
|
||||
|
||||
SampleRenderer::Renderer &renderer = assetManager.getRenderer();
|
||||
|
||||
SampleRenderer::RendererMaterialDesc matdesc;
|
||||
const char *materialTypeName = xmlroot.getXMLAttribute("type");
|
||||
if(materialTypeName && !strcmp(materialTypeName, "lit"))
|
||||
{
|
||||
matdesc.type = SampleRenderer::RendererMaterial::TYPE_LIT;
|
||||
}
|
||||
else if(materialTypeName && !strcmp(materialTypeName, "unlit"))
|
||||
{
|
||||
matdesc.type = SampleRenderer::RendererMaterial::TYPE_UNLIT;
|
||||
}
|
||||
for(FAST_XML::xml_node *child=xmlroot.first_node(); child; child=child->next_sibling())
|
||||
{
|
||||
const char *nodeName = child->name();
|
||||
const char *nodeValue = child->value();
|
||||
const char *name = child->getXMLAttribute("name");
|
||||
if(nodeName && nodeValue)
|
||||
{
|
||||
while(isspace(*nodeValue)) nodeValue++; // skip leading spaces.
|
||||
if(!strcmp(nodeName, "shader"))
|
||||
{
|
||||
if(name && !strcmp(name, "vertex"))
|
||||
{
|
||||
//matdesc.vertexShaderPath = nodeValue;
|
||||
mVertexShaderPaths.push_back(nodeValue);
|
||||
}
|
||||
else if(name && !strcmp(name, "fragment"))
|
||||
{
|
||||
matdesc.fragmentShaderPath = nodeValue;
|
||||
}
|
||||
else if(name && !strcmp(name, "geometry"))
|
||||
{
|
||||
matdesc.geometryShaderPath = nodeValue;
|
||||
}
|
||||
else if(name && !strcmp(name, "hull"))
|
||||
{
|
||||
matdesc.hullShaderPath = nodeValue;
|
||||
}
|
||||
else if(name && !strcmp(name, "domain"))
|
||||
{
|
||||
matdesc.domainShaderPath = nodeValue;
|
||||
}
|
||||
}
|
||||
else if(!strcmp(nodeName, "alphaTestFunc"))
|
||||
{
|
||||
if( !strcmp(nodeValue, "EQUAL")) matdesc.alphaTestFunc = SampleRenderer::RendererMaterial::ALPHA_TEST_EQUAL;
|
||||
else if(!strcmp(nodeValue, "NOT_EQUAL")) matdesc.alphaTestFunc = SampleRenderer::RendererMaterial::ALPHA_TEST_NOT_EQUAL;
|
||||
else if(!strcmp(nodeValue, "LESS")) matdesc.alphaTestFunc = SampleRenderer::RendererMaterial::ALPHA_TEST_LESS;
|
||||
else if(!strcmp(nodeValue, "LESS_EQUAL")) matdesc.alphaTestFunc = SampleRenderer::RendererMaterial::ALPHA_TEST_LESS_EQUAL;
|
||||
else if(!strcmp(nodeValue, "GREATER")) matdesc.alphaTestFunc = SampleRenderer::RendererMaterial::ALPHA_TEST_GREATER;
|
||||
else if(!strcmp(nodeValue, "GREATER_EQUAL")) matdesc.alphaTestFunc = SampleRenderer::RendererMaterial::ALPHA_TEST_GREATER_EQUAL;
|
||||
else PX_ASSERT(0); // Unknown alpha test func!
|
||||
}
|
||||
else if(!strcmp(nodeName, "alphaTestRef"))
|
||||
{
|
||||
matdesc.alphaTestRef = PxClamp((float)atof(nodeValue), 0.0f, 1.0f);
|
||||
}
|
||||
else if(!strcmp(nodeName, "blending") && strstr(nodeValue, "true"))
|
||||
{
|
||||
matdesc.blending = true;
|
||||
|
||||
static const PxU32 numBlendFuncs = 2;
|
||||
static const char* blendFuncNames[numBlendFuncs] =
|
||||
{
|
||||
"srcBlendFunc",
|
||||
"dstBlendFunc"
|
||||
};
|
||||
static const SampleRenderer::RendererMaterial::BlendFunc blendFuncDefaults[numBlendFuncs] =
|
||||
{
|
||||
SampleRenderer::RendererMaterial::BLEND_SRC_ALPHA,
|
||||
SampleRenderer::RendererMaterial::BLEND_ONE_MINUS_SRC_ALPHA
|
||||
};
|
||||
SampleRenderer::RendererMaterial::BlendFunc* blendFuncs[numBlendFuncs] =
|
||||
{
|
||||
&matdesc.srcBlendFunc,
|
||||
&matdesc.dstBlendFunc
|
||||
};
|
||||
|
||||
// Parse optional src/dst blend funcs
|
||||
for (PxU32 i = 0; i < numBlendFuncs; ++i)
|
||||
{
|
||||
FAST_XML::xml_node *blendNode = child->first_node(blendFuncNames[i]);
|
||||
if (blendNode && blendNode->value())
|
||||
*blendFuncs[i] = getBlendFunc(blendNode->value(), blendFuncDefaults[i]);
|
||||
else
|
||||
*blendFuncs[i] = blendFuncDefaults[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t materialIndex = 0; materialIndex < mVertexShaderPaths.size(); materialIndex++)
|
||||
{
|
||||
MaterialStruct materialStruct;
|
||||
|
||||
matdesc.vertexShaderPath = mVertexShaderPaths[materialIndex];
|
||||
materialStruct.m_material = NULL;
|
||||
materialStruct.m_materialInstance = NULL;
|
||||
materialStruct.m_maxBones = 0;
|
||||
if (strstr(mVertexShaderPaths[materialIndex], "skeletalmesh") != NULL)
|
||||
materialStruct.m_maxBones = RENDERER_MAX_BONES;
|
||||
|
||||
materialStruct.m_material = renderer.createMaterial(matdesc);
|
||||
PX_ASSERT(materialStruct.m_material);
|
||||
if(materialStruct.m_material)
|
||||
{
|
||||
FAST_XML::xml_node *varsnode = xmlroot.first_node("variables");
|
||||
if(varsnode)
|
||||
{
|
||||
materialStruct.m_materialInstance = new SampleRenderer::RendererMaterialInstance(*materialStruct.m_material);
|
||||
for(FAST_XML::xml_node *child=varsnode->first_node(); child; child=child->next_sibling())
|
||||
{
|
||||
const char *nodename = child->name();
|
||||
const char *varname = child->getXMLAttribute("name");
|
||||
const char *value = child->value();
|
||||
|
||||
if(!strcmp(nodename, "float"))
|
||||
{
|
||||
float f = (float)atof(value);
|
||||
const SampleRenderer::RendererMaterial::Variable *var = materialStruct.m_materialInstance->findVariable(varname, SampleRenderer::RendererMaterial::VARIABLE_FLOAT);
|
||||
//PX_ASSERT(var);
|
||||
if(var) materialStruct.m_materialInstance->writeData(*var, &f);
|
||||
}
|
||||
else if(!strcmp(nodename, "float2"))
|
||||
{
|
||||
float f[2];
|
||||
readFloats(value, f, 2);
|
||||
const SampleRenderer::RendererMaterial::Variable *var = materialStruct.m_materialInstance->findVariable(varname, SampleRenderer::RendererMaterial::VARIABLE_FLOAT2);
|
||||
//PX_ASSERT(var);
|
||||
if(var) materialStruct.m_materialInstance->writeData(*var, f);
|
||||
}
|
||||
else if(!strcmp(nodename, "float3"))
|
||||
{
|
||||
float f[3];
|
||||
readFloats(value, f, 3);
|
||||
const SampleRenderer::RendererMaterial::Variable *var = materialStruct.m_materialInstance->findVariable(varname, SampleRenderer::RendererMaterial::VARIABLE_FLOAT3);
|
||||
//PX_ASSERT(var);
|
||||
if(var) materialStruct.m_materialInstance->writeData(*var, f);
|
||||
}
|
||||
else if(!strcmp(nodename, "float4"))
|
||||
{
|
||||
float f[4];
|
||||
readFloats(value, f, 4);
|
||||
const SampleRenderer::RendererMaterial::Variable *var = materialStruct.m_materialInstance->findVariable(varname, SampleRenderer::RendererMaterial::VARIABLE_FLOAT4);
|
||||
//PX_ASSERT(var);
|
||||
if(var) materialStruct.m_materialInstance->writeData(*var, f);
|
||||
}
|
||||
else if(!strcmp(nodename, "sampler2D") || !strcmp(nodename, "sampler3D"))
|
||||
{
|
||||
SampleTextureAsset *textureAsset = static_cast<SampleTextureAsset*>(assetManager.getAsset(value, ASSET_TEXTURE));
|
||||
PX_ASSERT(textureAsset);
|
||||
if(textureAsset)
|
||||
{
|
||||
m_assets.push_back(textureAsset);
|
||||
SampleRenderer::RendererMaterial::VariableType vartype = (0 == strcmp(nodename, "sampler2D")) ? SampleRenderer::RendererMaterial::VARIABLE_SAMPLER2D : SampleRenderer::RendererMaterial::VARIABLE_SAMPLER3D;
|
||||
const SampleRenderer::RendererMaterial::Variable *var = materialStruct.m_materialInstance->findVariable(varname, vartype);
|
||||
//PX_ASSERT(var);
|
||||
if(var)
|
||||
{
|
||||
SampleRenderer::RendererTexture *texture = textureAsset->getTexture();
|
||||
materialStruct.m_materialInstance->writeData(*var, &texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
m_vertexShaders.push_back(materialStruct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SampleFramework::SampleMaterialAsset::SampleMaterialAsset(SampleAssetManager &assetManager, Type type, const char *path)
|
||||
: SampleAsset(type, path),
|
||||
m_assetManager(assetManager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SampleMaterialAsset::~SampleMaterialAsset(void)
|
||||
{
|
||||
PxU32 numAssets = (PxU32)m_assets.size();
|
||||
for(PxU32 i=0; i<numAssets; i++)
|
||||
{
|
||||
m_assetManager.returnAsset(*m_assets[i]);
|
||||
}
|
||||
for (size_t index = 0; index < m_vertexShaders.size(); index++)
|
||||
{
|
||||
if(m_vertexShaders[index].m_materialInstance) delete m_vertexShaders[index].m_materialInstance;
|
||||
if(m_vertexShaders[index].m_material) m_vertexShaders[index].m_material->release();
|
||||
}
|
||||
}
|
||||
|
||||
size_t SampleMaterialAsset::getNumVertexShaders() const
|
||||
{
|
||||
return m_vertexShaders.size();
|
||||
}
|
||||
|
||||
SampleRenderer::RendererMaterial *SampleMaterialAsset::getMaterial(size_t vertexShaderIndex)
|
||||
{
|
||||
return m_vertexShaders[vertexShaderIndex].m_material;
|
||||
}
|
||||
|
||||
SampleRenderer::RendererMaterialInstance *SampleMaterialAsset::getMaterialInstance(size_t vertexShaderIndex)
|
||||
{
|
||||
return m_vertexShaders[vertexShaderIndex].m_materialInstance;
|
||||
}
|
||||
|
||||
bool SampleMaterialAsset::isOk(void) const
|
||||
{
|
||||
return !m_vertexShaders.empty();
|
||||
}
|
||||
|
||||
unsigned int SampleMaterialAsset::getMaxBones(size_t vertexShaderIndex) const
|
||||
{
|
||||
return m_vertexShaders[vertexShaderIndex].m_maxBones;
|
||||
}
|
||||
@ -0,0 +1,207 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include <SamplePointDebugRender.h>
|
||||
#include <Renderer.h>
|
||||
#include <RendererVertexBuffer.h>
|
||||
#include <RendererVertexBufferDesc.h>
|
||||
#include <RendererMesh.h>
|
||||
#include <RendererMeshDesc.h>
|
||||
#include <SampleAssetManager.h>
|
||||
#include <SampleMaterialAsset.h>
|
||||
#include <RendererMemoryMacros.h>
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
SamplePointDebugRender::SamplePointDebugRender(SampleRenderer::Renderer &renderer, SampleAssetManager &assetmanager) :
|
||||
m_renderer(renderer),
|
||||
m_assetmanager(assetmanager)
|
||||
{
|
||||
m_material = static_cast<SampleMaterialAsset*>(m_assetmanager.getAsset("materials/simple_unlit.xml", SampleAsset::ASSET_MATERIAL));
|
||||
PX_ASSERT(m_material);
|
||||
PX_ASSERT(m_material->getNumVertexShaders() == 1);
|
||||
m_meshContext.material = m_material ? m_material->getMaterial(0) : 0;
|
||||
|
||||
m_maxVerts = 0;
|
||||
m_numVerts = 0;
|
||||
m_vertexbuffer = 0;
|
||||
m_mesh = 0;
|
||||
m_lockedPositions = 0;
|
||||
m_positionStride = 0;
|
||||
m_lockedColors = 0;
|
||||
m_colorStride = 0;
|
||||
}
|
||||
|
||||
SamplePointDebugRender::~SamplePointDebugRender(void)
|
||||
{
|
||||
checkUnlock();
|
||||
SAFE_RELEASE(m_vertexbuffer);
|
||||
SAFE_RELEASE(m_mesh);
|
||||
if(m_material)
|
||||
{
|
||||
m_assetmanager.returnAsset(*m_material);
|
||||
}
|
||||
}
|
||||
|
||||
void SamplePointDebugRender::addPoint(const PxVec3 &p0, const SampleRenderer::RendererColor &color)
|
||||
{
|
||||
checkResizePoint(m_numVerts+1);
|
||||
addVert(p0, color);
|
||||
}
|
||||
|
||||
void SamplePointDebugRender::queueForRenderPoint(void)
|
||||
{
|
||||
if(m_meshContext.mesh)
|
||||
{
|
||||
checkUnlock();
|
||||
m_mesh->setVertexBufferRange(0, m_numVerts);
|
||||
m_renderer.queueMeshForRender(m_meshContext);
|
||||
}
|
||||
}
|
||||
|
||||
void SamplePointDebugRender::clearPoint(void)
|
||||
{
|
||||
m_numVerts = 0;
|
||||
}
|
||||
|
||||
void SamplePointDebugRender::checkResizePoint(PxU32 maxVerts)
|
||||
{
|
||||
if(maxVerts > m_maxVerts)
|
||||
{
|
||||
m_maxVerts = maxVerts + (PxU32)(maxVerts*0.2f);
|
||||
|
||||
SampleRenderer::RendererVertexBufferDesc vbdesc;
|
||||
vbdesc.hint = SampleRenderer::RendererVertexBuffer::HINT_DYNAMIC;
|
||||
vbdesc.semanticFormats[SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION] = SampleRenderer::RendererVertexBuffer::FORMAT_FLOAT3;
|
||||
vbdesc.semanticFormats[SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR] = SampleRenderer::RendererVertexBuffer::FORMAT_COLOR_NATIVE; // same as RendererColor
|
||||
vbdesc.maxVertices = m_maxVerts;
|
||||
SampleRenderer::RendererVertexBuffer *vertexbuffer = m_renderer.createVertexBuffer(vbdesc);
|
||||
PX_ASSERT(vertexbuffer);
|
||||
|
||||
if(vertexbuffer)
|
||||
{
|
||||
PxU32 positionStride = 0;
|
||||
void *positions = vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION, positionStride);
|
||||
|
||||
PxU32 colorStride = 0;
|
||||
void *colors = vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR, colorStride);
|
||||
|
||||
PX_ASSERT(positions && colors);
|
||||
if(positions && colors)
|
||||
{
|
||||
if(m_numVerts > 0)
|
||||
{
|
||||
// if we have existing verts, copy them to the new VB...
|
||||
PX_ASSERT(m_lockedPositions);
|
||||
PX_ASSERT(m_lockedColors);
|
||||
if(m_lockedPositions && m_lockedColors)
|
||||
{
|
||||
for(PxU32 i=0; i<m_numVerts; i++)
|
||||
{
|
||||
memcpy(((PxU8*)positions) + (positionStride*i), ((PxU8*)m_lockedPositions) + (m_positionStride*i), sizeof(PxVec3));
|
||||
memcpy(((PxU8*)colors) + (colorStride*i), ((PxU8*)m_lockedColors) + (m_colorStride*i), sizeof(SampleRenderer::RendererColor));
|
||||
}
|
||||
}
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR);
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION);
|
||||
}
|
||||
}
|
||||
vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR);
|
||||
vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION);
|
||||
}
|
||||
if(m_vertexbuffer)
|
||||
{
|
||||
m_vertexbuffer->release();
|
||||
m_vertexbuffer = 0;
|
||||
m_lockedPositions = 0;
|
||||
m_positionStride = 0;
|
||||
m_lockedColors = 0;
|
||||
m_colorStride = 0;
|
||||
}
|
||||
SAFE_RELEASE(m_mesh);
|
||||
if(vertexbuffer)
|
||||
{
|
||||
m_vertexbuffer = vertexbuffer;
|
||||
SampleRenderer::RendererMeshDesc meshdesc;
|
||||
meshdesc.primitives = SampleRenderer::RendererMesh::PRIMITIVE_POINTS;
|
||||
meshdesc.vertexBuffers = &m_vertexbuffer;
|
||||
meshdesc.numVertexBuffers = 1;
|
||||
meshdesc.firstVertex = 0;
|
||||
meshdesc.numVertices = m_numVerts;
|
||||
m_mesh = m_renderer.createMesh(meshdesc);
|
||||
PX_ASSERT(m_mesh);
|
||||
}
|
||||
m_meshContext.mesh = m_mesh;
|
||||
}
|
||||
}
|
||||
|
||||
void SamplePointDebugRender::checkLock(void)
|
||||
{
|
||||
if(m_vertexbuffer)
|
||||
{
|
||||
if(!m_lockedPositions)
|
||||
{
|
||||
m_lockedPositions = m_vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION, m_positionStride);
|
||||
PX_ASSERT(m_lockedPositions);
|
||||
}
|
||||
if(!m_lockedColors)
|
||||
{
|
||||
m_lockedColors = m_vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR, m_colorStride);
|
||||
PX_ASSERT(m_lockedColors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SamplePointDebugRender::checkUnlock(void)
|
||||
{
|
||||
if(m_vertexbuffer)
|
||||
{
|
||||
if(m_lockedPositions)
|
||||
{
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION);
|
||||
m_lockedPositions = 0;
|
||||
}
|
||||
if(m_lockedColors)
|
||||
{
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR);
|
||||
m_lockedColors = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SamplePointDebugRender::addVert(const PxVec3 &p, const SampleRenderer::RendererColor &color)
|
||||
{
|
||||
PX_ASSERT(m_maxVerts > m_numVerts);
|
||||
{
|
||||
checkLock();
|
||||
if(m_lockedPositions && m_lockedColors)
|
||||
{
|
||||
memcpy(((PxU8*)m_lockedPositions) + (m_positionStride*m_numVerts), &p, sizeof(PxVec3));
|
||||
memcpy(((PxU8*)m_lockedColors) + (m_colorStride*m_numVerts), &color, sizeof(SampleRenderer::RendererColor));
|
||||
m_numVerts++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,338 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include <SampleTextureAsset.h>
|
||||
|
||||
#include <Renderer.h>
|
||||
#include <RendererTexture2D.h>
|
||||
#include <RendererTexture2DDesc.h>
|
||||
#include <RendererMemoryMacros.h>
|
||||
#include "PxTkBmpLoader.h"
|
||||
|
||||
#include "nv_dds.h"
|
||||
#include "PxTkFile.h"
|
||||
|
||||
#ifdef RENDERER_ENABLE_TGA_SUPPORT
|
||||
# include <targa.h>
|
||||
#endif
|
||||
|
||||
#ifdef RENDERER_ENABLE_PVR_SUPPORT
|
||||
#include "pvrt.h"
|
||||
#endif
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
SampleTextureAsset::SampleTextureAsset(SampleRenderer::Renderer &renderer, File &file, const char *path, Type texType) :
|
||||
SampleAsset(ASSET_TEXTURE, path)
|
||||
{
|
||||
m_texture = 0;
|
||||
|
||||
switch(texType)
|
||||
{
|
||||
case DDS: loadDDS(renderer, file); break;
|
||||
case TGA: loadTGA(renderer, file); break;
|
||||
case PVR: loadPVR(renderer, file); break;
|
||||
case BMP: loadBMP(renderer, file); break;
|
||||
default: PX_ASSERT(0 && "Invalid texture type requested"); break;
|
||||
}
|
||||
}
|
||||
|
||||
SampleTextureAsset::~SampleTextureAsset(void)
|
||||
{
|
||||
SAFE_RELEASE(m_texture);
|
||||
}
|
||||
|
||||
void SampleTextureAsset::loadDDS(SampleRenderer::Renderer &renderer, File &file)
|
||||
{
|
||||
nv_dds::CDDSImage ddsimage;
|
||||
bool ok = ddsimage.load(&file, false);
|
||||
PX_ASSERT(ok);
|
||||
if(ok)
|
||||
{
|
||||
SampleRenderer::RendererTexture2DDesc tdesc;
|
||||
nv_dds::TextureFormat ddsformat = ddsimage.get_format();
|
||||
switch(ddsformat)
|
||||
{
|
||||
case nv_dds::TextureBGRA: tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_B8G8R8A8; break;
|
||||
case nv_dds::TextureDXT1: tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_DXT1; break;
|
||||
case nv_dds::TextureDXT3: tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_DXT3; break;
|
||||
case nv_dds::TextureDXT5: tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_DXT5; break;
|
||||
default: break;
|
||||
}
|
||||
tdesc.width = ddsimage.get_width();
|
||||
tdesc.height = ddsimage.get_height();
|
||||
// if there is 1 mipmap, nv_dds reports 0
|
||||
tdesc.numLevels = ddsimage.get_num_mipmaps()+1;
|
||||
PX_ASSERT(tdesc.isValid());
|
||||
m_texture = renderer.createTexture2D(tdesc);
|
||||
PX_ASSERT(m_texture);
|
||||
if(m_texture)
|
||||
{
|
||||
PxU32 pitch = 0;
|
||||
void *buffer = m_texture->lockLevel(0, pitch);
|
||||
PX_ASSERT(buffer);
|
||||
if(buffer)
|
||||
{
|
||||
//PxU32 size = ddsimage.get_size();
|
||||
|
||||
PxU8 *levelDst = (PxU8*)buffer;
|
||||
const PxU8 *levelSrc = (PxU8*)(unsigned char*)ddsimage;
|
||||
const PxU32 levelWidth = m_texture->getWidthInBlocks();
|
||||
const PxU32 levelHeight = m_texture->getHeightInBlocks();
|
||||
const PxU32 rowSrcSize = levelWidth * m_texture->getBlockSize();
|
||||
PX_ASSERT(rowSrcSize <= pitch); // the pitch can't be less than the source row size.
|
||||
for(PxU32 row=0; row<levelHeight; row++)
|
||||
{
|
||||
memcpy(levelDst, levelSrc, rowSrcSize);
|
||||
levelDst += pitch;
|
||||
levelSrc += rowSrcSize;
|
||||
}
|
||||
}
|
||||
m_texture->unlockLevel(0);
|
||||
|
||||
for(PxU32 i=1; i<tdesc.numLevels; i++)
|
||||
{
|
||||
void *buffer = m_texture->lockLevel(i, pitch);
|
||||
PX_ASSERT(buffer);
|
||||
if(buffer && pitch )
|
||||
{
|
||||
const nv_dds::CSurface &surface = ddsimage.get_mipmap(i-1);
|
||||
//PxU32 size = surface.get_size();
|
||||
|
||||
PxU8 *levelDst = (PxU8*)buffer;
|
||||
const PxU8 *levelSrc = (PxU8*)(unsigned char*)surface;
|
||||
const PxU32 levelWidth = SampleRenderer::RendererTexture2D::getFormatNumBlocks(surface.get_width(), m_texture->getFormat());
|
||||
const PxU32 levelHeight = SampleRenderer::RendererTexture2D::getFormatNumBlocks(surface.get_height(), m_texture->getFormat());
|
||||
const PxU32 rowSrcSize = levelWidth * m_texture->getBlockSize();
|
||||
PX_ASSERT(rowSrcSize <= pitch); // the pitch can't be less than the source row size.
|
||||
for(PxU32 row=0; row<levelHeight; row++)
|
||||
{
|
||||
memcpy(levelDst, levelSrc, rowSrcSize);
|
||||
levelDst += pitch;
|
||||
levelSrc += rowSrcSize;
|
||||
}
|
||||
}
|
||||
m_texture->unlockLevel(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SampleTextureAsset::loadPVR(SampleRenderer::Renderer& renderer, File& file)
|
||||
{
|
||||
#ifdef RENDERER_ENABLE_PVR_SUPPORT
|
||||
fseek(&file, 0, SEEK_END);
|
||||
size_t size = ftell(&file);
|
||||
fseek(&file, 0, SEEK_SET);
|
||||
char* fileBuffer = new char[size+1];
|
||||
fread(fileBuffer, 1, size, &file);
|
||||
fclose(&file);
|
||||
fileBuffer[size] = '\0';
|
||||
|
||||
const PVRTextureInfo info(fileBuffer);
|
||||
PX_ASSERT(info.data);
|
||||
|
||||
SampleRenderer::RendererTexture2DDesc tdesc;
|
||||
if (info.glFormat == GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG)
|
||||
{
|
||||
tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_PVR_4BPP;
|
||||
}
|
||||
else
|
||||
{
|
||||
tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_PVR_2BPP;
|
||||
}
|
||||
|
||||
tdesc.width = info.width;
|
||||
tdesc.height = info.height;
|
||||
tdesc.numLevels = info.mipCount + 1;
|
||||
tdesc.data = NULL;
|
||||
|
||||
PX_ASSERT(tdesc.isValid());
|
||||
m_texture = renderer.createTexture2D(tdesc);
|
||||
PX_ASSERT(m_texture);
|
||||
if (!info.data)
|
||||
{
|
||||
delete[] fileBuffer;
|
||||
return;
|
||||
}
|
||||
|
||||
PxU32 pitch = 0;
|
||||
PxU8* levelDst = (PxU8*)m_texture->lockLevel(0, pitch);
|
||||
const PxU8* levelSrc = (PxU8*)info.data;
|
||||
|
||||
PX_ASSERT(levelDst && levelSrc);
|
||||
{
|
||||
PxU32 levelWidth = tdesc.width;
|
||||
PxU32 levelHeight = tdesc.height;
|
||||
const PxU32 levelSize = m_texture->computeImageByteSize(levelWidth, levelHeight, 1, tdesc.format);
|
||||
memcpy(levelDst, levelSrc, levelSize);
|
||||
levelSrc += levelSize;
|
||||
}
|
||||
m_texture->unlockLevel(0);
|
||||
|
||||
for(PxU32 i=1; i<tdesc.numLevels; i++)
|
||||
{
|
||||
PxU8* levelDst = (PxU8*)m_texture->lockLevel(i, pitch);
|
||||
PX_ASSERT(levelDst);
|
||||
{
|
||||
const PxU32 levelWidth = m_texture->getLevelDimension(tdesc.width, i);
|
||||
const PxU32 levelHeight = m_texture->getLevelDimension(tdesc.height, i);
|
||||
const PxU32 levelSize = m_texture->computeImageByteSize(levelWidth, levelHeight, 1, tdesc.format);
|
||||
memcpy(levelDst, levelSrc, levelSize);
|
||||
levelSrc += levelSize;
|
||||
}
|
||||
m_texture->unlockLevel(i);
|
||||
}
|
||||
|
||||
delete[] fileBuffer;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void SampleTextureAsset::loadTGA(SampleRenderer::Renderer &renderer, File &file)
|
||||
{
|
||||
#ifdef RENDERER_ENABLE_TGA_SUPPORT
|
||||
tga_image* image = new tga_image();
|
||||
bool ok = (TGA_NOERR == tga_read_from_FILE( image, &file ));
|
||||
|
||||
// flip it to make it look correct in the SampleFramework's renderer
|
||||
tga_flip_vert( image );
|
||||
|
||||
PX_ASSERT(ok);
|
||||
if( ok )
|
||||
{
|
||||
SampleRenderer::RendererTexture2DDesc tdesc;
|
||||
int componentCount = image->pixel_depth/8;
|
||||
if( componentCount == 3 || componentCount == 4 )
|
||||
{
|
||||
tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_B8G8R8A8;
|
||||
|
||||
tdesc.width = image->width;
|
||||
tdesc.height = image->height;
|
||||
|
||||
tdesc.numLevels = 1;
|
||||
PX_ASSERT(tdesc.isValid());
|
||||
m_texture = renderer.createTexture2D(tdesc);
|
||||
PX_ASSERT(m_texture);
|
||||
|
||||
if(m_texture)
|
||||
{
|
||||
PxU32 pitch = 0;
|
||||
void *buffer = m_texture->lockLevel(0, pitch);
|
||||
PX_ASSERT(buffer);
|
||||
if(buffer)
|
||||
{
|
||||
PxU8 *levelDst = (PxU8*)buffer;
|
||||
const PxU8 *levelSrc = (PxU8*)image->image_data;
|
||||
const PxU32 levelWidth = m_texture->getWidthInBlocks();
|
||||
const PxU32 levelHeight = m_texture->getHeightInBlocks();
|
||||
const PxU32 rowSrcSize = levelWidth * m_texture->getBlockSize();
|
||||
PX_ASSERT(rowSrcSize <= pitch); // the pitch can't be less than the source row size.
|
||||
for(PxU32 row=0; row<levelHeight; row++)
|
||||
{
|
||||
if( componentCount == 3 )
|
||||
{
|
||||
// copy per pixel to handle RBG case, based on component count
|
||||
for(PxU32 col=0; col<levelWidth; col++)
|
||||
{
|
||||
*levelDst++ = levelSrc[0];
|
||||
*levelDst++ = levelSrc[1];
|
||||
*levelDst++ = levelSrc[2];
|
||||
*levelDst++ = 0xFF; //alpha
|
||||
levelSrc += componentCount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(levelDst, levelSrc, rowSrcSize);
|
||||
levelDst += pitch == 0xFFFFFFFF ? rowSrcSize : pitch;
|
||||
levelSrc += rowSrcSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_texture->unlockLevel(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
tga_free_buffers(image);
|
||||
delete image;
|
||||
|
||||
#endif /* RENDERER_ENABLE_TGA_SUPPORT */
|
||||
}
|
||||
|
||||
void SampleTextureAsset::loadBMP(SampleRenderer::Renderer &renderer, File &file)
|
||||
{
|
||||
PxToolkit::BmpLoader loader;
|
||||
bool ok = loader.loadBmp(&file);
|
||||
PX_ASSERT(ok);
|
||||
if(ok)
|
||||
{
|
||||
SampleRenderer::RendererTexture2DDesc tdesc;
|
||||
tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_B8G8R8A8;
|
||||
tdesc.width = loader.mWidth;
|
||||
tdesc.height = loader.mHeight;
|
||||
tdesc.numLevels = 1;
|
||||
PX_ASSERT(tdesc.isValid());
|
||||
m_texture = renderer.createTexture2D(tdesc);
|
||||
PX_ASSERT(m_texture);
|
||||
if(m_texture)
|
||||
{
|
||||
PxU32 pitch = 0;
|
||||
void *buffer = m_texture->lockLevel(0, pitch);
|
||||
PX_ASSERT(buffer);
|
||||
if(buffer)
|
||||
{
|
||||
const PxU32 levelWidth = m_texture->getWidthInBlocks();
|
||||
const PxU32 levelHeight = m_texture->getHeightInBlocks();
|
||||
SampleRenderer::RendererColor* levelDst = (SampleRenderer::RendererColor*)buffer + levelWidth * levelHeight;
|
||||
const PxU8* levelSrc = (PxU8*)loader.mRGB;
|
||||
for(PxU32 row=0; row<levelHeight; row++)
|
||||
{
|
||||
levelDst -= levelWidth;
|
||||
// copy per pixel to handle RBG case
|
||||
for(PxU32 col=0; col<levelWidth; col++)
|
||||
{
|
||||
levelDst[col].r = *levelSrc++;
|
||||
levelDst[col].g = *levelSrc++;
|
||||
levelDst[col].b = *levelSrc++;
|
||||
levelDst[col].a = loader.mHasAlpha ? *levelSrc++ : 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_texture->unlockLevel(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SampleRenderer::RendererTexture2D *SampleTextureAsset::getTexture(void)
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
bool SampleTextureAsset::isOk(void) const
|
||||
{
|
||||
return m_texture ? true : false;
|
||||
}
|
||||
70
physx/samples/sampleframework/framework/src/SampleTree.cpp
Normal file
70
physx/samples/sampleframework/framework/src/SampleTree.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#include "SampleTree.h"
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
bool Tree::Node::appendChild(Node& node)
|
||||
{
|
||||
if (!node.isRoot() || isOffspringOf(node))
|
||||
return false;
|
||||
|
||||
node.mParent = this;
|
||||
node.mPrev = mTail;
|
||||
|
||||
if (NULL == mTail)
|
||||
mHead = &node;
|
||||
else
|
||||
mTail->mNext = &node;
|
||||
|
||||
mTail = &node;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tree::Node::removeChild(Node& node)
|
||||
{
|
||||
if (this != node.mParent)
|
||||
return false;
|
||||
|
||||
Node* prev = node.mPrev;
|
||||
Node* next = node.mNext;
|
||||
|
||||
if (NULL == prev)
|
||||
mHead = next;
|
||||
else
|
||||
prev->mNext = next;
|
||||
|
||||
if (NULL == next)
|
||||
mTail = prev;
|
||||
else
|
||||
next->mPrev = prev;
|
||||
|
||||
node.mParent = NULL;
|
||||
return true;
|
||||
}
|
||||
@ -0,0 +1,244 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include <SampleTriangleDebugRender.h>
|
||||
#include <Renderer.h>
|
||||
#include <RendererVertexBuffer.h>
|
||||
#include <RendererVertexBufferDesc.h>
|
||||
#include <RendererMesh.h>
|
||||
#include <RendererMeshDesc.h>
|
||||
#include <SampleAssetManager.h>
|
||||
#include <SampleMaterialAsset.h>
|
||||
#include <RendererMemoryMacros.h>
|
||||
|
||||
using namespace SampleFramework;
|
||||
|
||||
SampleTriangleDebugRender::SampleTriangleDebugRender(SampleRenderer::Renderer &renderer, SampleAssetManager &assetmanager) :
|
||||
m_renderer(renderer),
|
||||
m_assetmanager(assetmanager)
|
||||
{
|
||||
m_material = static_cast<SampleMaterialAsset*>(m_assetmanager.getAsset("materials/simple_lit_color.xml", SampleAsset::ASSET_MATERIAL));
|
||||
PX_ASSERT(m_material);
|
||||
PX_ASSERT(m_material->getNumVertexShaders() == 1);
|
||||
m_meshContext.material = m_material ? m_material->getMaterial(0) : 0;
|
||||
|
||||
m_maxVerts = 0;
|
||||
m_numVerts = 0;
|
||||
m_vertexbuffer = 0;
|
||||
m_mesh = 0;
|
||||
m_lockedPositions = 0;
|
||||
m_positionStride = 0;
|
||||
m_lockedNormals = 0;
|
||||
m_normalStride = 0;
|
||||
m_lockedColors = 0;
|
||||
m_colorStride = 0;
|
||||
}
|
||||
|
||||
SampleTriangleDebugRender::~SampleTriangleDebugRender(void)
|
||||
{
|
||||
checkUnlock();
|
||||
SAFE_RELEASE(m_vertexbuffer);
|
||||
SAFE_RELEASE(m_mesh);
|
||||
if(m_material)
|
||||
{
|
||||
m_assetmanager.returnAsset(*m_material);
|
||||
}
|
||||
}
|
||||
|
||||
void SampleTriangleDebugRender::addTriangle(const PxVec3 &p0, const PxVec3 &p1, const PxVec3 &p2, const SampleRenderer::RendererColor &color)
|
||||
{
|
||||
checkResizeTriangle(m_numVerts+3);
|
||||
PxVec3 normal = (p1-p0).cross(p2-p0);
|
||||
normal.normalize();
|
||||
addVert(p0, normal, color);
|
||||
addVert(p1, normal, color);
|
||||
addVert(p2, normal, color);
|
||||
}
|
||||
|
||||
void SampleTriangleDebugRender::addTriangle(const PxVec3 &p0, const PxVec3 &p1, const PxVec3 &p2, const PxVec3& n0, const PxVec3& n1, const PxVec3& n2, const SampleRenderer::RendererColor &color)
|
||||
{
|
||||
checkResizeTriangle(m_numVerts+3);
|
||||
addVert(p0, n0, color);
|
||||
addVert(p1, n1, color);
|
||||
addVert(p2, n2, color);
|
||||
}
|
||||
|
||||
void SampleTriangleDebugRender::queueForRenderTriangle(void)
|
||||
{
|
||||
if(m_meshContext.mesh)
|
||||
{
|
||||
checkUnlock();
|
||||
m_mesh->setVertexBufferRange(0, m_numVerts);
|
||||
m_renderer.queueMeshForRender(m_meshContext);
|
||||
}
|
||||
}
|
||||
|
||||
void SampleTriangleDebugRender::clearTriangle(void)
|
||||
{
|
||||
m_numVerts = 0;
|
||||
}
|
||||
|
||||
void SampleTriangleDebugRender::checkResizeTriangle(PxU32 maxVerts)
|
||||
{
|
||||
if(maxVerts > m_maxVerts)
|
||||
{
|
||||
m_maxVerts = maxVerts + (PxU32)(maxVerts*0.2f);
|
||||
|
||||
SampleRenderer::RendererVertexBufferDesc vbdesc;
|
||||
vbdesc.hint = SampleRenderer::RendererVertexBuffer::HINT_DYNAMIC;
|
||||
vbdesc.semanticFormats[SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION] = SampleRenderer::RendererVertexBuffer::FORMAT_FLOAT3;
|
||||
vbdesc.semanticFormats[SampleRenderer::RendererVertexBuffer::SEMANTIC_NORMAL] = SampleRenderer::RendererVertexBuffer::FORMAT_FLOAT3;
|
||||
vbdesc.semanticFormats[SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR] = SampleRenderer::RendererVertexBuffer::FORMAT_COLOR_NATIVE; // Same format as RendererColor
|
||||
vbdesc.maxVertices = m_maxVerts;
|
||||
SampleRenderer::RendererVertexBuffer *vertexbuffer = m_renderer.createVertexBuffer(vbdesc);
|
||||
PX_ASSERT(vertexbuffer);
|
||||
|
||||
if(vertexbuffer)
|
||||
{
|
||||
PxU32 positionStride = 0;
|
||||
void *positions = vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION, positionStride);
|
||||
|
||||
PxU32 normalStride = 0;
|
||||
void *normals = vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_NORMAL, normalStride);
|
||||
|
||||
PxU32 colorStride = 0;
|
||||
void *colors = vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR, colorStride);
|
||||
|
||||
PX_ASSERT(positions && colors);
|
||||
if(positions && colors)
|
||||
{
|
||||
if(m_numVerts > 0)
|
||||
{
|
||||
// if we have existing verts, copy them to the new VB...
|
||||
PX_ASSERT(m_lockedPositions);
|
||||
PX_ASSERT(m_lockedNormals);
|
||||
PX_ASSERT(m_lockedColors);
|
||||
if(m_lockedPositions && m_lockedNormals && m_lockedColors)
|
||||
{
|
||||
for(PxU32 i=0; i<m_numVerts; i++)
|
||||
{
|
||||
memcpy(((PxU8*)positions) + (positionStride*i), ((PxU8*)m_lockedPositions) + (m_positionStride*i), sizeof(PxVec3));
|
||||
memcpy(((PxU8*)normals) + (normalStride*i), ((PxU8*)m_lockedNormals) + (m_normalStride*i), sizeof(PxVec3));
|
||||
memcpy(((PxU8*)colors) + (colorStride*i), ((PxU8*)m_lockedColors) + (m_colorStride*i), sizeof(SampleRenderer::RendererColor));
|
||||
}
|
||||
}
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR);
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_NORMAL);
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION);
|
||||
}
|
||||
}
|
||||
vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR);
|
||||
vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_NORMAL);
|
||||
vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION);
|
||||
}
|
||||
if(m_vertexbuffer)
|
||||
{
|
||||
m_vertexbuffer->release();
|
||||
m_vertexbuffer = 0;
|
||||
m_lockedPositions = 0;
|
||||
m_positionStride = 0;
|
||||
m_lockedNormals = 0;
|
||||
m_normalStride = 0;
|
||||
m_lockedColors = 0;
|
||||
m_colorStride = 0;
|
||||
}
|
||||
SAFE_RELEASE(m_mesh);
|
||||
if(vertexbuffer)
|
||||
{
|
||||
m_vertexbuffer = vertexbuffer;
|
||||
SampleRenderer::RendererMeshDesc meshdesc;
|
||||
meshdesc.primitives = SampleRenderer::RendererMesh::PRIMITIVE_TRIANGLES;
|
||||
meshdesc.vertexBuffers = &m_vertexbuffer;
|
||||
meshdesc.numVertexBuffers = 1;
|
||||
meshdesc.firstVertex = 0;
|
||||
meshdesc.numVertices = m_numVerts;
|
||||
m_mesh = m_renderer.createMesh(meshdesc);
|
||||
PX_ASSERT(m_mesh);
|
||||
}
|
||||
m_meshContext.mesh = m_mesh;
|
||||
m_meshContext.cullMode = SampleRenderer::RendererMeshContext::NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void SampleTriangleDebugRender::checkLock(void)
|
||||
{
|
||||
if(m_vertexbuffer)
|
||||
{
|
||||
if(!m_lockedPositions)
|
||||
{
|
||||
m_lockedPositions = m_vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION, m_positionStride);
|
||||
PX_ASSERT(m_lockedPositions);
|
||||
}
|
||||
if(!m_lockedNormals)
|
||||
{
|
||||
m_lockedNormals = m_vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_NORMAL, m_normalStride);
|
||||
PX_ASSERT(m_lockedNormals);
|
||||
}
|
||||
if(!m_lockedColors)
|
||||
{
|
||||
m_lockedColors = m_vertexbuffer->lockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR, m_colorStride);
|
||||
PX_ASSERT(m_lockedColors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SampleTriangleDebugRender::checkUnlock(void)
|
||||
{
|
||||
if(m_vertexbuffer)
|
||||
{
|
||||
if(m_lockedPositions)
|
||||
{
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_POSITION);
|
||||
m_lockedPositions = 0;
|
||||
}
|
||||
if (m_lockedNormals)
|
||||
{
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_NORMAL);
|
||||
m_lockedNormals = 0;
|
||||
}
|
||||
if(m_lockedColors)
|
||||
{
|
||||
m_vertexbuffer->unlockSemantic(SampleRenderer::RendererVertexBuffer::SEMANTIC_COLOR);
|
||||
m_lockedColors = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SampleTriangleDebugRender::addVert(const PxVec3 &p, const PxVec3 &n, const SampleRenderer::RendererColor &color)
|
||||
{
|
||||
PX_ASSERT(m_maxVerts > m_numVerts);
|
||||
{
|
||||
checkLock();
|
||||
if(m_lockedPositions && m_lockedNormals && m_lockedColors)
|
||||
{
|
||||
*(PxVec3*)(((PxU8*)m_lockedPositions) + (m_positionStride*m_numVerts)) = p;
|
||||
*(PxVec3*)(((PxU8*)m_lockedNormals) + (m_normalStride*m_numVerts)) = n;
|
||||
*(SampleRenderer::RendererColor*)(((PxU8*)m_lockedColors) + (m_colorStride*m_numVerts)) = color;
|
||||
|
||||
m_numVerts++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include <SampleAssetManager.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
bool SampleFramework::searchForPath(const char* path, char* buffer, int bufferSize, bool isReadOnly, int maxRecursion)
|
||||
{
|
||||
struct stat sb;
|
||||
char* tmpBuffer = (char*)alloca(bufferSize);
|
||||
sprintf(buffer, "%s", path);
|
||||
for(int i = 0; i < maxRecursion; i++)
|
||||
{
|
||||
if(stat(buffer, &sb))
|
||||
{
|
||||
sprintf(tmpBuffer, "../%s", buffer);
|
||||
strcpy(buffer, tmpBuffer);
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
1118
physx/samples/sampleframework/framework/src/nv_dds.cpp
Normal file
1118
physx/samples/sampleframework/framework/src/nv_dds.cpp
Normal file
File diff suppressed because it is too large
Load Diff
372
physx/samples/sampleframework/framework/src/nv_dds.h
Normal file
372
physx/samples/sampleframework/framework/src/nv_dds.h
Normal file
@ -0,0 +1,372 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
// PHYSX-CHANGES:
|
||||
// - Removed dependency on OpenGL. -jdolan
|
||||
// - MACOS does not always equate to BIG_ENDIAN... fixed it for all platforms. -jdolan
|
||||
// - 64 bit fix for unix based platforms (replaced unsigned long with unsigned int) -sschirm
|
||||
|
||||
#ifndef NV_DDS_H
|
||||
#define NV_DDS_H
|
||||
|
||||
#include <string>
|
||||
#include <deque>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <RendererConfig.h>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#define NV_DDS_BIG_ENDIAN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace nv_dds
|
||||
{
|
||||
// surface description flags
|
||||
const unsigned int DDSF_CAPS = 0x00000001l;
|
||||
const unsigned int DDSF_HEIGHT = 0x00000002l;
|
||||
const unsigned int DDSF_WIDTH = 0x00000004l;
|
||||
const unsigned int DDSF_PITCH = 0x00000008l;
|
||||
const unsigned int DDSF_PIXELFORMAT = 0x00001000l;
|
||||
const unsigned int DDSF_MIPMAPCOUNT = 0x00020000l;
|
||||
const unsigned int DDSF_LINEARSIZE = 0x00080000l;
|
||||
const unsigned int DDSF_DEPTH = 0x00800000l;
|
||||
|
||||
// pixel format flags
|
||||
const unsigned int DDSF_ALPHAPIXELS = 0x00000001l;
|
||||
const unsigned int DDSF_FOURCC = 0x00000004l;
|
||||
const unsigned int DDSF_RGB = 0x00000040l;
|
||||
const unsigned int DDSF_RGBA = 0x00000041l;
|
||||
|
||||
// dwCaps1 flags
|
||||
const unsigned int DDSF_COMPLEX = 0x00000008l;
|
||||
const unsigned int DDSF_TEXTURE = 0x00001000l;
|
||||
const unsigned int DDSF_MIPMAP = 0x00400000l;
|
||||
|
||||
// dwCaps2 flags
|
||||
const unsigned int DDSF_CUBEMAP = 0x00000200l;
|
||||
const unsigned int DDSF_CUBEMAP_POSITIVEX = 0x00000400l;
|
||||
const unsigned int DDSF_CUBEMAP_NEGATIVEX = 0x00000800l;
|
||||
const unsigned int DDSF_CUBEMAP_POSITIVEY = 0x00001000l;
|
||||
const unsigned int DDSF_CUBEMAP_NEGATIVEY = 0x00002000l;
|
||||
const unsigned int DDSF_CUBEMAP_POSITIVEZ = 0x00004000l;
|
||||
const unsigned int DDSF_CUBEMAP_NEGATIVEZ = 0x00008000l;
|
||||
const unsigned int DDSF_CUBEMAP_ALL_FACES = 0x0000FC00l;
|
||||
const unsigned int DDSF_VOLUME = 0x00200000l;
|
||||
|
||||
// compressed texture types
|
||||
const unsigned int FOURCC_DXT1 = 0x31545844l; //(MAKEFOURCC('D','X','T','1'))
|
||||
const unsigned int FOURCC_DXT3 = 0x33545844l; //(MAKEFOURCC('D','X','T','3'))
|
||||
const unsigned int FOURCC_DXT5 = 0x35545844l; //(MAKEFOURCC('D','X','T','5'))
|
||||
|
||||
struct DXTColBlock
|
||||
{
|
||||
unsigned short col0;
|
||||
unsigned short col1;
|
||||
|
||||
unsigned char row[4];
|
||||
};
|
||||
|
||||
struct DXT3AlphaBlock
|
||||
{
|
||||
unsigned short row[4];
|
||||
};
|
||||
|
||||
struct DXT5AlphaBlock
|
||||
{
|
||||
unsigned char alpha0;
|
||||
unsigned char alpha1;
|
||||
|
||||
unsigned char row[6];
|
||||
};
|
||||
|
||||
struct DDS_PIXELFORMAT
|
||||
{
|
||||
unsigned int dwSize;
|
||||
unsigned int dwFlags;
|
||||
unsigned int dwFourCC;
|
||||
unsigned int dwRGBBitCount;
|
||||
unsigned int dwRBitMask;
|
||||
unsigned int dwGBitMask;
|
||||
unsigned int dwBBitMask;
|
||||
unsigned int dwABitMask;
|
||||
};
|
||||
|
||||
struct DDS_HEADER
|
||||
{
|
||||
unsigned int dwSize;
|
||||
unsigned int dwFlags;
|
||||
unsigned int dwHeight;
|
||||
unsigned int dwWidth;
|
||||
unsigned int dwPitchOrLinearSize;
|
||||
unsigned int dwDepth;
|
||||
unsigned int dwMipMapCount;
|
||||
unsigned int dwReserved1[11];
|
||||
DDS_PIXELFORMAT ddspf;
|
||||
unsigned int dwCaps1;
|
||||
unsigned int dwCaps2;
|
||||
unsigned int dwReserved2[3];
|
||||
};
|
||||
|
||||
enum TextureType
|
||||
{
|
||||
TextureNone,
|
||||
TextureFlat, // 1D, 2D, and rectangle textures
|
||||
Texture3D,
|
||||
TextureCubemap
|
||||
};
|
||||
|
||||
enum TextureFormat
|
||||
{
|
||||
TextureUnknown=0,
|
||||
TextureBGRA,
|
||||
TextureBGR,
|
||||
TextureLuminance,
|
||||
TextureDXT1,
|
||||
TextureDXT3,
|
||||
TextureDXT5,
|
||||
};
|
||||
|
||||
class CSurface
|
||||
{
|
||||
public:
|
||||
CSurface();
|
||||
CSurface(unsigned int w, unsigned int h, unsigned int d, unsigned int imgsize, const unsigned char *pixels);
|
||||
CSurface(const CSurface ©);
|
||||
CSurface &operator= (const CSurface &rhs);
|
||||
virtual ~CSurface();
|
||||
|
||||
operator unsigned char*() const;
|
||||
|
||||
virtual void create(unsigned int w, unsigned int h, unsigned int d, unsigned int imgsize, const unsigned char *pixels);
|
||||
virtual void clear();
|
||||
|
||||
inline unsigned int get_width() const { return m_width; }
|
||||
inline unsigned int get_height() const { return m_height; }
|
||||
inline unsigned int get_depth() const { return m_depth; }
|
||||
inline unsigned int get_size() const { return m_size; }
|
||||
|
||||
private:
|
||||
unsigned int m_width;
|
||||
unsigned int m_height;
|
||||
unsigned int m_depth;
|
||||
unsigned int m_size;
|
||||
|
||||
unsigned char *m_pixels;
|
||||
};
|
||||
|
||||
class CTexture : public CSurface
|
||||
{
|
||||
friend class CDDSImage;
|
||||
|
||||
public:
|
||||
CTexture();
|
||||
CTexture(unsigned int w, unsigned int h, unsigned int d, unsigned int imgsize, const unsigned char *pixels);
|
||||
CTexture(const CTexture ©);
|
||||
CTexture &operator= (const CTexture &rhs);
|
||||
~CTexture();
|
||||
|
||||
void create(unsigned int w, unsigned int h, unsigned int d, unsigned int imgsize, const unsigned char *pixels);
|
||||
void clear();
|
||||
|
||||
inline const CSurface &get_mipmap(unsigned int index) const
|
||||
{
|
||||
assert(!m_mipmaps.empty());
|
||||
assert(index < m_mipmaps.size());
|
||||
|
||||
return m_mipmaps[index];
|
||||
}
|
||||
|
||||
inline void add_mipmap(const CSurface &mipmap)
|
||||
{
|
||||
m_mipmaps.push_back(mipmap);
|
||||
}
|
||||
|
||||
inline unsigned int get_num_mipmaps() const { return (unsigned int)m_mipmaps.size(); }
|
||||
|
||||
protected:
|
||||
inline CSurface &get_mipmap(unsigned int index)
|
||||
{
|
||||
assert(!m_mipmaps.empty());
|
||||
assert(index < m_mipmaps.size());
|
||||
|
||||
return m_mipmaps[index];
|
||||
}
|
||||
|
||||
private:
|
||||
std::deque<CSurface> m_mipmaps;
|
||||
};
|
||||
|
||||
class CDDSImage
|
||||
{
|
||||
public:
|
||||
CDDSImage();
|
||||
~CDDSImage();
|
||||
|
||||
void create_textureFlat(TextureFormat format, unsigned int components, const CTexture &baseImage);
|
||||
void create_texture3D(TextureFormat format, unsigned int components, const CTexture &baseImage);
|
||||
void create_textureCubemap(TextureFormat format, unsigned int components,
|
||||
const CTexture &positiveX, const CTexture &negativeX,
|
||||
const CTexture &positiveY, const CTexture &negativeY,
|
||||
const CTexture &positiveZ, const CTexture &negativeZ);
|
||||
|
||||
void clear();
|
||||
bool load(std::string filename, bool flipImage = true);
|
||||
bool load(SampleRenderer::File* fp, bool flipImage = true);
|
||||
bool save(std::string filename, bool flipImage = true);
|
||||
bool save(SampleRenderer::File* fp, bool flipImage = true);
|
||||
|
||||
inline operator unsigned char*()
|
||||
{
|
||||
assert(m_valid);
|
||||
assert(!m_images.empty());
|
||||
|
||||
return m_images[0];
|
||||
}
|
||||
|
||||
inline unsigned int get_width()
|
||||
{
|
||||
assert(m_valid);
|
||||
assert(!m_images.empty());
|
||||
|
||||
return m_images[0].get_width();
|
||||
}
|
||||
|
||||
inline unsigned int get_height()
|
||||
{
|
||||
assert(m_valid);
|
||||
assert(!m_images.empty());
|
||||
|
||||
return m_images[0].get_height();
|
||||
}
|
||||
|
||||
inline unsigned int get_depth()
|
||||
{
|
||||
assert(m_valid);
|
||||
assert(!m_images.empty());
|
||||
|
||||
return m_images[0].get_depth();
|
||||
}
|
||||
|
||||
inline unsigned int get_size()
|
||||
{
|
||||
assert(m_valid);
|
||||
assert(!m_images.empty());
|
||||
|
||||
return m_images[0].get_size();
|
||||
}
|
||||
|
||||
inline unsigned int get_num_mipmaps()
|
||||
{
|
||||
assert(m_valid);
|
||||
assert(!m_images.empty());
|
||||
|
||||
return m_images[0].get_num_mipmaps();
|
||||
}
|
||||
|
||||
inline const CSurface &get_mipmap(unsigned int index) const
|
||||
{
|
||||
assert(m_valid);
|
||||
assert(!m_images.empty());
|
||||
assert(index < m_images[0].get_num_mipmaps());
|
||||
|
||||
return m_images[0].get_mipmap(index);
|
||||
}
|
||||
|
||||
inline const CTexture &get_cubemap_face(unsigned int face) const
|
||||
{
|
||||
assert(m_valid);
|
||||
assert(!m_images.empty());
|
||||
assert(m_images.size() == 6);
|
||||
assert(m_type == TextureCubemap);
|
||||
assert(face < 6);
|
||||
|
||||
return m_images[face];
|
||||
}
|
||||
|
||||
inline unsigned int get_components() { return m_components; }
|
||||
inline TextureFormat get_format() { return m_format; }
|
||||
inline TextureType get_type() { return m_type; }
|
||||
|
||||
inline bool is_compressed()
|
||||
{
|
||||
if ((m_format == TextureDXT1) ||
|
||||
(m_format == TextureDXT3) ||
|
||||
(m_format == TextureDXT5))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool is_cubemap() { return (m_type == TextureCubemap); }
|
||||
inline bool is_volume() { return (m_type == Texture3D); }
|
||||
inline bool is_valid() { return m_valid; }
|
||||
|
||||
inline bool is_dword_aligned()
|
||||
{
|
||||
assert(m_valid);
|
||||
|
||||
int dwordLineSize = get_dword_aligned_linesize(get_width(), m_components*8);
|
||||
int curLineSize = get_width() * m_components;
|
||||
|
||||
return (dwordLineSize == curLineSize);
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int clamp_size(unsigned int size);
|
||||
unsigned int size_dxtc(unsigned int width, unsigned int height);
|
||||
unsigned int size_rgb(unsigned int width, unsigned int height);
|
||||
inline void swap_endian(void *val);
|
||||
|
||||
// calculates 4-byte aligned width of image
|
||||
inline unsigned int get_dword_aligned_linesize(unsigned int width, unsigned int bpp)
|
||||
{
|
||||
return ((width * bpp + 31) & (unsigned int)(-32)) >> 3;
|
||||
}
|
||||
|
||||
void flip(CSurface &surface);
|
||||
void flip_texture(CTexture &texture);
|
||||
|
||||
void swap(void *byte1, void *byte2, unsigned int size);
|
||||
void flip_blocks_dxtc1(DXTColBlock *line, unsigned int numBlocks);
|
||||
void flip_blocks_dxtc3(DXTColBlock *line, unsigned int numBlocks);
|
||||
void flip_blocks_dxtc5(DXTColBlock *line, unsigned int numBlocks);
|
||||
void flip_dxt5_alpha(DXT5AlphaBlock *block);
|
||||
|
||||
void write_texture(const CTexture &texture, SampleRenderer::File *fp);
|
||||
|
||||
TextureFormat m_format;
|
||||
unsigned int m_components;
|
||||
TextureType m_type;
|
||||
bool m_valid;
|
||||
|
||||
std::deque<CTexture> m_images;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@ -0,0 +1,48 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
#include <SampleAssetManager.h>
|
||||
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
bool SampleFramework::searchForPath(const char* path, char* buffer, int bufferSize, bool isReadOnly, int maxRecursion)
|
||||
{
|
||||
char* tmpBuffer = (char*)alloca(bufferSize);
|
||||
strcpy_s(buffer, bufferSize, path);
|
||||
for(int i = 0; i < maxRecursion; i++)
|
||||
{
|
||||
if(GetFileAttributes(buffer) == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
sprintf_s(tmpBuffer, bufferSize, "../%s", buffer);
|
||||
strcpy_s(buffer, bufferSize, tmpBuffer);
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
BIN
physx/samples/sampleframework/media/fonts/arial_black.bin
Normal file
BIN
physx/samples/sampleframework/media/fonts/arial_black.bin
Normal file
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/GrayRock_Tileable_D.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,9 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="vertex">vertex/skeletalmesh_4bone.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse_uniform_color.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/debug_pattern.dds</sampler2D>
|
||||
<float4 name="diffuseColor">1.0 1.0 1.0 1.0</float4>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/skeletalmesh_1bone.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse_normal.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/MoistConcrete01D.dds</sampler2D>
|
||||
<sampler2D name="normalTexture">textures/MoistConcrete01N.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/skeletalmesh_1bone.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse_normal.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/GTC_Wall_D.dds</sampler2D>
|
||||
<sampler2D name="normalTexture">textures/GTC_Wall_N.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,7 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/skeletalmesh_1bone.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/Plaster_Tileable.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/skeletalmesh_1bone.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse_normal.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/GTC_Wall_D.dds</sampler2D>
|
||||
<sampler2D name="normalTexture">textures/GTC_Wall_N.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/skeletalmesh_1bone.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse_normal.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/GrayRock_Tileable_D.dds</sampler2D>
|
||||
<sampler2D name="normalTexture">textures/GrayRock_Tileable_N.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/skeletalmesh_1bone.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse_normal.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/OldPineWoodD.dds</sampler2D>
|
||||
<sampler2D name="normalTexture">textures/OldPineWoodN.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/skeletalmesh_1bone.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse_normal.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/GTC_Wall_D.dds</sampler2D>
|
||||
<sampler2D name="normalTexture">textures/GTC_Wall_N.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,7 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/skeletalmesh_1bone.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/Wood_Tileable.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,10 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/fancy_cloth_diffuse.cg</shader>
|
||||
<alphaTestFunc>GREATER</alphaTestFunc>
|
||||
<alphaTestRef>0.9</alphaTestRef>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/knit_1d.dds</sampler2D>
|
||||
<sampler2D name="normalTexture">textures/knit_1n.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,9 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/turbulencesprites.cg</shader>
|
||||
<shader name="fragment">fragment/simple_turbulence.cg</shader>
|
||||
<alphaTestFunc>GREATER_EQUAL</alphaTestFunc>
|
||||
<alphaTestRef>0.5</alphaTestRef>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">APEX/0.9/turbulence/textures/smoke.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/mouse.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse.cg</shader>
|
||||
<blending>true</blending>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/mouse.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/outlinetext.cg</shader>
|
||||
<blending>true</blending>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/test.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,9 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/pointsprite.cg</shader>
|
||||
<shader name="fragment">fragment/pointsprite_diffuse.cg</shader>
|
||||
<blending>true</blending>
|
||||
<variables>
|
||||
<float name="particleSize">1.5</float>
|
||||
<sampler2D name="diffuseTexture">textures/SoftParticle.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/particle_fog.cg</shader>
|
||||
<shader name="fragment">fragment/particle_fog.cg</shader>
|
||||
<blending>true</blending>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/SoftParticle.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,9 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/pointsprite.cg</shader>
|
||||
<shader name="fragment">fragment/pointsprite_diffuse2.cg</shader>
|
||||
<blending>true</blending>
|
||||
<variables>
|
||||
<float name="particleSize">3.5</float>
|
||||
<sampler2D name="diffuseTexture">textures/smoke.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,10 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/pointsprite.cg</shader>
|
||||
<shader name="fragment">fragment/pointsprite_normal.cg</shader>
|
||||
<alphaTestFunc>GREATER</alphaTestFunc>
|
||||
<alphaTestRef>0.5</alphaTestRef>
|
||||
<variables>
|
||||
<float name="particleSize">0.1</float>
|
||||
<sampler2D name="normalTexture">textures/billboard_sphere_normals.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,12 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/pointsprite.cg</shader>
|
||||
<shader name="fragment">fragment/pointsprite_diffuse2.cg</shader>
|
||||
<blending>true</blending>
|
||||
<variables>
|
||||
<float name="particleSize">2.0</float>
|
||||
<sampler2D name="diffuseTexture">textures/SoftParticle.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/knit_1d.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/simple_alpha.cg</shader>
|
||||
<blending>true</blending>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/test.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,7 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="vertex">vertex/skeletalmesh_1bone.cg</shader>
|
||||
<shader name="fragment">fragment/simple.cg</shader>
|
||||
<variables>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,11 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/simple.cg</shader>
|
||||
<blending>
|
||||
true
|
||||
<srcBlendFunc>ONE</srcBlendFunc>
|
||||
<dstBlendFunc>ONE</dstBlendFunc>
|
||||
</blending>
|
||||
<variables>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,6 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/simple_color.cg</shader>
|
||||
<variables>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,13 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/simple_uniform_colors.cg</shader>
|
||||
<blending>
|
||||
true
|
||||
<srcBlendFunc>ONE</srcBlendFunc>
|
||||
<dstBlendFunc>ONE</dstBlendFunc>
|
||||
</blending>
|
||||
<variables>
|
||||
<float4 name="diffuseColor">0.5 0.5 0.5 1.0</float4>
|
||||
<float4 name="specularColor">0.2 0.2 0.2 64.0</float4>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/simple_uniform_colors.cg</shader>
|
||||
<variables>
|
||||
<float4 name="diffuseColor">0.6 0.6 0.6 1.0</float4>
|
||||
<float4 name="specularColor">0.2 0.2 0.2 64.0</float4>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,6 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/simple_color.cg</shader>
|
||||
<variables>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,7 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/tablet_buttons.cg</shader>
|
||||
<shader name="fragment">fragment/tablet_buttons.cg</shader>
|
||||
<blending>true</blending>
|
||||
<variables>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,8 @@
|
||||
<material type="unlit">
|
||||
<shader name="vertex">vertex/tablet_sticks.cg</shader>
|
||||
<shader name="fragment">fragment/tablet_sticks.cg</shader>
|
||||
<blending>true</blending>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/ui_knob_dxt3.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,7 @@
|
||||
<material type="lit">
|
||||
<shader name="vertex">vertex/staticmesh.cg</shader>
|
||||
<shader name="fragment">fragment/simple_diffuse.cg</shader>
|
||||
<variables>
|
||||
<sampler2D name="diffuseTexture">textures/Wood_Tileable.dds</sampler2D>
|
||||
</variables>
|
||||
</material>
|
||||
@ -0,0 +1,82 @@
|
||||
::
|
||||
:: Redistribution and use in source and binary forms, with or without
|
||||
:: modification, are permitted provided that the following conditions
|
||||
:: are met:
|
||||
:: * Redistributions of source code must retain the above copyright
|
||||
:: notice, this list of conditions and the following disclaimer.
|
||||
:: * Redistributions in binary form must reproduce the above copyright
|
||||
:: notice, this list of conditions and the following disclaimer in the
|
||||
:: documentation and/or other materials provided with the distribution.
|
||||
:: * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
:: contributors may be used to endorse or promote products derived
|
||||
:: from this software without specific prior written permission.
|
||||
::
|
||||
:: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
:: EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
:: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
:: PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
:: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
:: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
:: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
:: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
:: OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
:: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
:: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
::
|
||||
:: Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
cd ../../
|
||||
mkdir compiledshaders
|
||||
cd compiledshaders
|
||||
mkdir dx11feature11
|
||||
cd dx11feature11
|
||||
mkdir fragment
|
||||
cd ..
|
||||
mkdir dx11feature9
|
||||
cd dx11feature9
|
||||
mkdir fragment
|
||||
cd ../../shaders/fragment
|
||||
|
||||
CALL :SHADER fancy_cloth_diffuse
|
||||
CALL :SHADER material_diffuse
|
||||
CALL :SHADER outlinetext
|
||||
CALL :SHADER particle_fog
|
||||
CALL :SHADER pointsprite_diffuse
|
||||
CALL :SHADER pointsprite_diffuse2
|
||||
CALL :SHADER pointsprite_normal
|
||||
CALL :SHADER sample_diffuse_and_texture
|
||||
CALL :SHADER sample_diffuse_no_texture
|
||||
CALL :SHADER screenquad
|
||||
CALL :SHADER simple
|
||||
CALL :SHADER simple_alpha
|
||||
CALL :SHADER simple_color
|
||||
CALL :SHADER simple_diffuse
|
||||
CALL :SHADER simple_diffuse_multitex_heightmap
|
||||
CALL :SHADER simple_diffuse_normal
|
||||
CALL :SHADER simple_diffuse_tiled
|
||||
CALL :SHADER simple_diffuse_uniform_color
|
||||
CALL :SHADER simple_test
|
||||
CALL :SHADER simple_turbulence
|
||||
CALL :SHADER simple_uniform_color
|
||||
CALL :SHADER simple_unlit_normals
|
||||
CALL :SHADER simple_unlit_tangents
|
||||
CALL :SHADER text
|
||||
exit /b
|
||||
|
||||
:SHADER
|
||||
CALL :COMPILE %1 UNLIT
|
||||
CALL :COMPILE %1 DIRECTIONAL_LIGHT
|
||||
CALL :COMPILE %1 AMBIENT_LIGHT
|
||||
CALL :COMPILE %1 POINT_LIGHT
|
||||
CALL :COMPILE %1 SPOT_LIGHT_NO_SHADOW
|
||||
CALL :COMPILE %1 SPOT_LIGHT
|
||||
CALL :COMPILE %1 NORMALS
|
||||
CALL :COMPILE %1 DEPTH
|
||||
exit /b
|
||||
|
||||
:COMPILE
|
||||
set fragmentdefines9=/DRENDERER_FRAGMENT=1 /DRENDERER_D3D11=1 /DNO_SUPPORT_DDX_DDY=1 /DENABLE_VFACE=0 /DENABLE_VFACE_SCALE=0 /DRENDERER_WIN8ARM=1 /DPX_WINDOWS=1 /DENABLE_SHADOWS=0
|
||||
set fragmentdefines11=/DRENDERER_FRAGMENT=1 /DRENDERER_D3D11=1 /DENABLE_VFACE=1 /DENABLE_VFACE_SCALE=1 /DPX_WINDOWS=1 /DENABLE_SHADOWS=0
|
||||
|
||||
"fxc.exe" /E"fmain" /Zpr /Gec /I"../include" %fragmentdefines9% /DPASS_%2 /Fo"../../compiledshaders/dx11feature9/fragment/%1.cg.PASS_%2.cso" /T ps_4_0_level_9_1 /nologo %1.cg
|
||||
"fxc.exe" /E"fmain" /Zpr /Gec /I"../include" %fragmentdefines11% /DPASS_%2 /Fo"../../compiledshaders/dx11feature11/fragment/%1.cg.PASS_%2.cso" /T ps_4_0 /nologo %1.cg
|
||||
@ -0,0 +1,21 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
DECLARE_TEXTURE(normalTexture)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
half4 diffuseTextureColor = tex2D(diffuseTexture, params.texcoord0.xy);
|
||||
half4 normalTextureColor = tex2D(normalTexture, params.texcoord0.xy);
|
||||
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = diffuseTextureColor.rgb;
|
||||
mout.alpha = lerp(normalTextureColor.a, 1, params.texcoord1.r);
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = diffuseTextureColor.a;
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = normalTextureColor.xyz*2-1;
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
uniform lowp vec4 diffuseColor;
|
||||
|
||||
varying lowp vec4 lighting;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = diffuseColor * lighting;
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
uniform sampler2D diffuseTexture;
|
||||
uniform sampler2D normalTexture;
|
||||
varying highp vec2 texcoord0;
|
||||
varying highp vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
highp vec2 uv = vec2(texcoord0.x, 1.0-texcoord0.y);
|
||||
highp float tcos = color.z;
|
||||
highp float tsin = color.w;
|
||||
|
||||
uv -= 0.5;
|
||||
highp vec2 tempuv;
|
||||
tempuv.x = uv.x*tcos - uv.y*tsin;
|
||||
tempuv.y = uv.x*tsin + uv.y*tcos;
|
||||
uv = tempuv;
|
||||
uv += 0.5;
|
||||
|
||||
uv = clamp(uv, 0.0, 1.0);
|
||||
uv *= 0.5;
|
||||
uv += color.xy;
|
||||
|
||||
if (texture2D(normalTexture, uv.xy).a <= 0.5)
|
||||
discard;
|
||||
gl_FragColor.rgb = texture2D(diffuseTexture, uv.xy).rgb;
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
uniform sampler2D diffuseTexture;
|
||||
uniform highp vec4 diffuseColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = diffuseColor * texture2D(diffuseTexture, gl_PointCoord);
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
varying lowp vec4 color;
|
||||
varying lowp vec2 texcoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = color;
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
uniform sampler2D diffuseTexture;
|
||||
|
||||
varying highp vec2 texcoord0;
|
||||
varying lowp vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(diffuseTexture, texcoord0.xy);
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
uniform sampler2D diffuseTexture;
|
||||
|
||||
varying lowp vec2 texcoord0;
|
||||
varying lowp vec4 lighting;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(diffuseTexture, texcoord0.xy) * lighting;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
uniform sampler2D diffuseTexture0;
|
||||
uniform sampler2D diffuseTexture1;
|
||||
|
||||
varying lowp vec2 texcoord0;
|
||||
varying lowp vec4 lighting;
|
||||
varying lowp vec4 normal;
|
||||
|
||||
void main()
|
||||
{
|
||||
// selects texture depending on world normal steepness of height map
|
||||
lowp float tex0weight = max(0.0, min(1.0, (normal.y - 0.5) * 3.0));
|
||||
gl_FragColor = (texture2D(diffuseTexture0, texcoord0.xy) * tex0weight + texture2D(diffuseTexture1, texcoord0.xy) * (1.0 - tex0weight)) * lighting;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
|
||||
uniform sampler2D diffuseTexture;
|
||||
uniform sampler2D normalTexture;
|
||||
|
||||
varying highp vec2 texcoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
lowp vec4 diffuseTextureColor = texture2D(diffuseTexture, texcoord0.xy);
|
||||
lowp vec4 normalTextureColor = texture2D(normalTexture, texcoord0.xy);
|
||||
|
||||
gl_FragColor = clamp(normalTextureColor.z, 0.2, 1.0) * diffuseTextureColor;
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
uniform sampler2D diffuseTexture;
|
||||
|
||||
varying lowp vec2 texcoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(diffuseTexture, texcoord0.xy);
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
uniform lowp vec4 diffuseColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = diffuseColor;
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
uniform sampler2D diffuseTexture;
|
||||
varying lowp vec2 texcoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(diffuseTexture, texcoord0.xy);
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
struct FragmentParameters
|
||||
{
|
||||
#if !defined(GLSL_COMPILER)
|
||||
half4 screenSpacePosition : SV_POSITION;
|
||||
#else
|
||||
half4 screenSpacePosition : POSITION;
|
||||
#endif
|
||||
half4 color : COLOR;
|
||||
};
|
||||
|
||||
half4 fmain(FragmentParameters params) : COLOR0
|
||||
{
|
||||
return params.color;
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
// fragment shader that takes in a diffuse texture and some material parameters.
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
|
||||
BEGIN_CBUFFER(cbMaterialDiffuse)
|
||||
CONST_TYPE float4 diffuseColor;
|
||||
CONST_TYPE float3 emissiveColor;
|
||||
CONST_TYPE float3 specularColor;
|
||||
CONST_TYPE float specularPower;
|
||||
END_CBUFFER(cbMaterialDiffuse)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
half4 diffuseTextureColor = (half4)tex2D(diffuseTexture, params.texcoord0.xy);
|
||||
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = diffuseTextureColor.rgb * (half3)diffuseColor.rgb;
|
||||
mout.alpha = diffuseTextureColor.a * (half)diffuseColor.a;
|
||||
|
||||
//float3 eyeToSurf = normalize(g_eyePosition-params.worldSpacePosition);
|
||||
|
||||
//mout.emissiveColor = 1-pow(saturate(dot(normalize(g_eyePosition-params.worldSpacePosition),2)), params.worldSpaceNormal);//emissiveColor * saturate(dot(-g_eyeDirection, params.worldSpaceNormal));
|
||||
mout.emissiveColor = (half3)emissiveColor;
|
||||
|
||||
mout.specularColor = (half3)specularColor;
|
||||
mout.specularPower = (half)specularPower;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
|
||||
uniform const float3 outlineColor = {0.0, 0.0, 0.0};
|
||||
uniform const float invTexWidth = 1.0/1024.0;
|
||||
uniform const float invTexHeight = 1.0/1024.0;
|
||||
|
||||
// should replace the blur with a separable version or some such
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
half4 diffuseTextureColor = tex2D(diffuseTexture, params.texcoord0.xy);
|
||||
|
||||
half coeffs[9]= { 1.0/16.0, 2.0/16.0, 1.0/16.0,
|
||||
2.0/16.0, 4.0/16.0, 2.0/16.0,
|
||||
1.0/16.0, 2.0/16.0, 1.0/16.0 };
|
||||
|
||||
float accum = 0.0;
|
||||
accum += tex2D(diffuseTexture, params.texcoord0.xy + half2(-invTexWidth, -invTexHeight)).a * coeffs[0];
|
||||
accum += tex2D(diffuseTexture, params.texcoord0.xy + half2( 0, -invTexHeight)).a * coeffs[1];
|
||||
accum += tex2D(diffuseTexture, params.texcoord0.xy + half2(invTexWidth, -invTexHeight)).a * coeffs[2];
|
||||
accum += tex2D(diffuseTexture, params.texcoord0.xy + half2(-invTexWidth, 0 )).a * coeffs[3];
|
||||
accum += diffuseTextureColor.a * coeffs[4];
|
||||
accum += tex2D(diffuseTexture, params.texcoord0.xy + half2(invTexWidth, 0 )).a * coeffs[5];
|
||||
accum += tex2D(diffuseTexture, params.texcoord0.xy + half2(-invTexWidth, invTexHeight)).a * coeffs[6];
|
||||
accum += tex2D(diffuseTexture, params.texcoord0.xy + half2( 0, invTexHeight)).a * coeffs[7];
|
||||
accum += tex2D(diffuseTexture, params.texcoord0.xy + half2(invTexWidth, invTexHeight)).a * coeffs[8];
|
||||
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = lerp(outlineColor, params.color.rgb, diffuseTextureColor.a);
|
||||
mout.alpha = diffuseTextureColor.a*params.color.a + accum;
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(1,1,1); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
#if defined(PX_X360) && defined(RENDERER_FRAGMENT)
|
||||
half4 diffuseTextureColor = tex2D(diffuseTexture, params.spriteTexCoord.xy);
|
||||
#else
|
||||
half4 diffuseTextureColor = tex2D(diffuseTexture, params.texcoord0.xy);
|
||||
#endif
|
||||
float density = params.color.r;
|
||||
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = lerp(1, 0.4, density);
|
||||
mout.alpha = diffuseTextureColor.a*(density*0.1);
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(1,1,1); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
SurfaceMaterial mout;
|
||||
#if defined(PX_X360) && defined(RENDERER_FRAGMENT)
|
||||
half4 diffuseTextureColor = tex2D(diffuseTexture, float2(params.spriteTexCoord.x, params.spriteTexCoord.y));
|
||||
#else
|
||||
half4 diffuseTextureColor = (half4)tex2D(diffuseTexture, float2(params.texcoord0.x, params.texcoord0.y));
|
||||
#endif
|
||||
|
||||
mout.alpha = diffuseTextureColor.a * params.color.a;
|
||||
mout.diffuseColor = diffuseTextureColor.rgb * params.color.rgb;
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(1,1,1);
|
||||
mout.specularPower = 0;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
BEGIN_CBUFFER(cbDiffuse)
|
||||
CONST_TYPE float4 diffuseColor;
|
||||
END_CBUFFER(cbDiffuse)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
SurfaceMaterial mout;
|
||||
#if defined(PX_X360) && defined(RENDERER_FRAGMENT)
|
||||
half4 diffuseTextureColor = tex2D(diffuseTexture, float2(params.spriteTexCoord.x, params.spriteTexCoord.y));
|
||||
#else
|
||||
#if defined (RENDERER_GXM)
|
||||
half4 diffuseTextureColor = (half4)tex2D(diffuseTexture, float2(params.spriteTexCoord.x, params.spriteTexCoord.y));
|
||||
#else
|
||||
half4 diffuseTextureColor = (half4)tex2D(diffuseTexture, float2(params.texcoord0.x, params.texcoord0.y));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mout.alpha = half(diffuseTextureColor.a * diffuseColor.a * params.color.a);
|
||||
mout.diffuseColor = half3(diffuseTextureColor.rgb * diffuseColor.rgb);
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(1,1,1);
|
||||
mout.specularPower = 0;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(normalTexture)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
SurfaceMaterial mout;
|
||||
|
||||
#if defined(PX_X360) && defined(RENDERER_FRAGMENT)
|
||||
half4 normalTextureColor = tex2D(normalTexture, float2(params.spriteTexCoord.x, 1-params.spriteTexCoord.y));
|
||||
#else
|
||||
half4 normalTextureColor = (half4)tex2D(normalTexture, float2(params.texcoord0.x, 1-params.texcoord0.y));
|
||||
#endif
|
||||
mout.alpha = normalTextureColor.a;
|
||||
mout.diffuseColor = params.color.rgb;
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(1,1,1); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = normalTextureColor.rgb*2-1;
|
||||
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
struct FragmentParameters
|
||||
{
|
||||
#if !defined(GLSL_COMPILER)
|
||||
half4 screenSpacePosition : SV_POSITION;
|
||||
#else
|
||||
half4 screenSpacePosition : POSITION;
|
||||
#endif
|
||||
half4 color : COLOR;
|
||||
};
|
||||
|
||||
half4 fmain(FragmentParameters params) : COLOR0
|
||||
{
|
||||
return params.color;
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
#include <globals.cg>
|
||||
|
||||
struct FragmentParameters
|
||||
{
|
||||
#if !defined(GLSL_COMPILER)
|
||||
half4 screenSpacePosition : SV_POSITION;
|
||||
#else
|
||||
half4 screenSpacePosition : POSITION;
|
||||
#endif
|
||||
half3 worldSpacePosition : TEXCOORD1;
|
||||
half3 worldSpaceNormal : TEXCOORD2;
|
||||
half4 color : COLOR;
|
||||
};
|
||||
|
||||
half4 fmain(FragmentParameters params) : COLOR0
|
||||
{
|
||||
half3 lightColor = (half3)g_lightColor * (half)g_lightIntensity;
|
||||
half3 diffuseColor = (half)saturate(dot(params.worldSpaceNormal, -g_lightDirection)) * lightColor;
|
||||
float3 surfToEye = normalize(params.worldSpacePosition - g_eyePosition);
|
||||
float specularPower = 5.0;
|
||||
half3 specularColor = (half)pow(saturate(dot(reflect(-g_lightDirection, params.worldSpaceNormal), surfToEye)), specularPower) * lightColor;
|
||||
return params.color * half4(diffuseColor + specularColor, 1);
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
BEGIN_CBUFFER(cbDiffuse)
|
||||
CONST_TYPE float4 diffuseColor;
|
||||
END_CBUFFER(cbDiffuse)
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
half4 diffuseTextureColor = half4(tex2D(diffuseTexture, params.texcoord0.xy));
|
||||
|
||||
SurfaceMaterial mout;
|
||||
// mout.diffuseColor = diffuseTextureColor.rgb * diffuseColor;
|
||||
mout.diffuseColor = diffuseTextureColor.rgb;
|
||||
mout.alpha = half(diffuseColor.a);
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(0.2,0.2,0.2); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
BEGIN_CBUFFER(cbDiffuse)
|
||||
CONST_TYPE float4 diffuseColor;
|
||||
END_CBUFFER(cbDiffuse)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = half3(diffuseColor.rgb);
|
||||
mout.alpha = half(diffuseColor.a);
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(0.2,0.2,0.2); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
|
||||
struct FragmentParameters
|
||||
{
|
||||
float4 worldSpacePosition : TEXCOORD4;
|
||||
float2 texcoord0 : TEXCOORD0;
|
||||
half4 color : COLOR;
|
||||
};
|
||||
|
||||
struct Fragment
|
||||
{
|
||||
half4 color : COLOR0;
|
||||
};
|
||||
|
||||
//uniform const sampler2D diffuseTexture;
|
||||
|
||||
Fragment fmain(FragmentParameters params)
|
||||
{
|
||||
Fragment fout;
|
||||
// half4 diffuseTextureColor = tex2D(diffuseTexture, params.texcoord0.xy);
|
||||
// fout.color = diffuseTextureColor * params.color;
|
||||
fout.color = params.color;
|
||||
return fout;
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = 0.5;
|
||||
mout.alpha = 1;
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(0.2,0.2,0.2); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
half4 diffuseTextureColor = (half4)tex2D(diffuseTexture, params.texcoord0.xy);
|
||||
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = params.color.rgb;
|
||||
mout.alpha = diffuseTextureColor.a*params.color.a;
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(1,1,1); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = params.color.rgb;
|
||||
mout.alpha = 1;
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(0.2,0.2,0.2); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
half4 diffuseTextureColor = (half4)tex2D(diffuseTexture, params.texcoord0.xy);
|
||||
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = diffuseTextureColor.rgb;
|
||||
mout.alpha = diffuseTextureColor.a;
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(0.2,0.2,0.2); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
half4 diffuseTextureColor = (half4)tex2D(diffuseTexture, params.texcoord0.xy);
|
||||
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = diffuseTextureColor.rgb*params.color.rgb;
|
||||
mout.alpha = diffuseTextureColor.a *params.color.a;
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(1,1,1); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry_fog.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
half4 diffuseTextureColor = (half4)tex2D(diffuseTexture, params.texcoord0.xy);
|
||||
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = diffuseTextureColor.rgb;
|
||||
mout.alpha = diffuseTextureColor.a;
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(0.2,0.2,0.2); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
|
||||
return mout;
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
|
||||
#include <phong_lighting.cg>
|
||||
#include <fragment_entry.cg>
|
||||
|
||||
DECLARE_TEXTURE(diffuseTexture0)
|
||||
DECLARE_TEXTURE(diffuseTexture1)
|
||||
|
||||
SurfaceMaterial computeSurfaceMaterial(const FragmentParameters params)
|
||||
{
|
||||
half4 diffuseTextureColor0 = (half4)tex2D(diffuseTexture0, params.texcoord0.xy);
|
||||
half4 diffuseTextureColor1 = (half4)tex2D(diffuseTexture1, params.texcoord1.xy);
|
||||
|
||||
// selects texture depending on world normal steepness of height map
|
||||
half4 diffuseTextureColor = half4(diffuseTextureColor0*0.75 + diffuseTextureColor1*0.25);
|
||||
|
||||
SurfaceMaterial mout;
|
||||
mout.diffuseColor = diffuseTextureColor.rgb;
|
||||
mout.alpha = diffuseTextureColor.a;
|
||||
mout.emissiveColor = 0;
|
||||
mout.specularColor = half3(0.2,0.2,0.2); // TODO: make this a constant parameter set by the material.
|
||||
mout.specularPower = 16;
|
||||
mout.tangentSpaceNormal = half3(0,0,1);
|
||||
return mout;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user