This commit is contained in:
romkazvo
2023-08-07 19:29:24 +08:00
commit 34d6c5d489
4832 changed files with 1389451 additions and 0 deletions

View File

@@ -0,0 +1,369 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _cg_h
#define _cg_h
#define CG_VERSION_1_2 1
#define CG_VERSION_NUM 1200
//
// This #define foreces the old API for now. This will be removed soon, but
// the user will still have the ability to enable it.
//
// #define CG_DEPRECATED_1_1_API 1
// Set up for either Win32 import/export/lib.
#ifndef CGDLL_API
#ifdef WIN32
#ifdef CGDLL_EXPORTS
#define CGDLL_API __declspec(dllexport)
#elif defined (CG_LIB)
#define CGDLL_API
#else
#define CGDLL_API __declspec(dllimport)
#endif
#else
#define CGDLL_API
#endif
#endif
/*************************************************************************/
/*** CG Run-Time Library API ***/
/*************************************************************************/
/*************************************************************************/
/*** Data types and enumerants ***/
/*************************************************************************/
typedef int CGbool;
#define CG_FALSE ((CGbool)0)
#define CG_TRUE ((CGbool)1)
typedef struct _CGcontext *CGcontext;
typedef struct _CGprogram *CGprogram;
typedef struct _CGparameter *CGparameter;
//!!! PREPROCESS BEGIN
typedef enum
{
CG_UNKNOWN_TYPE,
CG_STRUCT,
CG_ARRAY,
CG_TYPE_START_ENUM = 1024,
# define CG_DATATYPE_MACRO(name, compiler_name, enum_name, ncols, nrows) \
enum_name ,
#include "Cg/cg_datatypes.h"
} CGtype;
typedef enum
{
# define CG_BINDLOCATION_MACRO(name,enum_name,compiler_name,\
enum_int,addressable,param_type) \
enum_name = enum_int,
#include "Cg/cg_bindlocations.h"
CG_UNDEFINED,
} CGresource;
typedef enum
{
CG_PROFILE_START = 6144,
CG_PROFILE_UNKNOWN,
# define CG_PROFILE_MACRO(name, compiler_id, compiler_id_caps, compiler_opt,int_id,vertex_profile) \
CG_PROFILE_##compiler_id_caps = int_id,
#include "Cg/cg_profiles.h"
CG_PROFILE_MAX = 7100,
} CGprofile;
typedef enum
{
# define CG_ERROR_MACRO(code, enum_name, message) \
enum_name = code,
# include "Cg/cg_errors.h"
} CGerror;
//!!! PREPROCESS END
typedef enum
{
# define CG_ENUM_MACRO(enum_name, enum_val) \
enum_name = enum_val,
# include "Cg/cg_enums.h"
} CGenum;
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*CGerrorCallbackFunc)(void);
/*************************************************************************/
/*** Functions ***/
/*************************************************************************/
#ifndef CG_EXPLICIT
/*** Context functions ***/
CGDLL_API CGcontext cgCreateContext(void);
CGDLL_API void cgDestroyContext(CGcontext ctx);
CGDLL_API CGbool cgIsContext(CGcontext ctx);
CGDLL_API const char *cgGetLastListing(CGcontext ctx);
CGDLL_API void cgSetAutoCompile(CGcontext ctx, CGenum flag);
/*** Program functions ***/
CGDLL_API CGprogram cgCreateProgram(CGcontext ctx,
CGenum program_type,
const char *program,
CGprofile profile,
const char *entry,
const char **args);
CGDLL_API CGprogram cgCreateProgramFromFile(CGcontext ctx,
CGenum program_type,
const char *program_file,
CGprofile profile,
const char *entry,
const char **args);
CGDLL_API CGprogram cgCopyProgram(CGprogram program);
CGDLL_API void cgDestroyProgram(CGprogram program);
CGDLL_API CGprogram cgGetFirstProgram(CGcontext ctx);
CGDLL_API CGprogram cgGetNextProgram(CGprogram current);
CGDLL_API CGcontext cgGetProgramContext(CGprogram prog);
CGDLL_API CGbool cgIsProgram(CGprogram program);
CGDLL_API void cgCompileProgram(CGprogram program);
CGDLL_API CGbool cgIsProgramCompiled(CGprogram program);
CGDLL_API const char *cgGetProgramString(CGprogram prog, CGenum pname);
CGDLL_API CGprofile cgGetProgramProfile(CGprogram prog);
/*** Parameter functions ***/
CGDLL_API CGparameter cgCreateParameter(CGcontext ctx, CGtype type);
CGDLL_API CGparameter cgCreateParameterArray(CGcontext ctx,
CGtype type,
int length);
CGDLL_API CGparameter cgCreateParameterMultiDimArray(CGcontext ctx,
CGtype type,
int dim,
const int *lengths);
CGDLL_API void cgDestroyParameter(CGparameter param);
CGDLL_API void cgConnectParameter(CGparameter from, CGparameter to);
CGDLL_API void cgDisconnectParameter(CGparameter param);
CGDLL_API CGparameter cgGetConnectedParameter(CGparameter param);
CGDLL_API int cgGetNumConnectedToParameters(CGparameter param);
CGDLL_API CGparameter cgGetConnectedToParameter(CGparameter param, int index);
CGDLL_API CGparameter cgGetNamedParameter(CGprogram prog, const char *name);
CGDLL_API CGparameter cgGetNamedProgramParameter(CGprogram prog,
CGenum name_space,
const char *name);
CGDLL_API CGparameter cgGetFirstParameter(CGprogram prog, CGenum name_space);
CGDLL_API CGparameter cgGetNextParameter(CGparameter current);
CGDLL_API CGparameter cgGetFirstLeafParameter(CGprogram prog, CGenum name_space);
CGDLL_API CGparameter cgGetNextLeafParameter(CGparameter current);
CGDLL_API CGparameter cgGetFirstStructParameter(CGparameter param);
CGDLL_API CGparameter cgGetNamedStructParameter(CGparameter param,
const char *name);
CGDLL_API CGparameter cgGetFirstDependentParameter(CGparameter param);
CGDLL_API CGparameter cgGetArrayParameter(CGparameter aparam, int index);
CGDLL_API int cgGetArrayDimension(CGparameter param);
CGDLL_API CGtype cgGetArrayType(CGparameter param);
CGDLL_API int cgGetArraySize(CGparameter param, int dimension);
CGDLL_API void cgSetArraySize(CGparameter param, int size);
CGDLL_API void cgSetMultiDimArraySize(CGparameter param, const int *sizes);
CGDLL_API CGprogram cgGetParameterProgram(CGparameter param);
CGDLL_API CGcontext cgGetParameterContext(CGparameter param);
CGDLL_API CGbool cgIsParameter(CGparameter param);
CGDLL_API const char *cgGetParameterName(CGparameter param);
CGDLL_API CGtype cgGetParameterType(CGparameter param);
CGDLL_API CGtype cgGetParameterNamedType(CGparameter param);
CGDLL_API const char *cgGetParameterSemantic(CGparameter param);
CGDLL_API CGresource cgGetParameterResource(CGparameter param);
CGDLL_API CGresource cgGetParameterBaseResource(CGparameter param);
CGDLL_API unsigned long cgGetParameterResourceIndex(CGparameter param);
CGDLL_API CGenum cgGetParameterVariability(CGparameter param);
CGDLL_API CGenum cgGetParameterDirection(CGparameter param);
CGDLL_API CGbool cgIsParameterReferenced(CGparameter param);
CGDLL_API const double *cgGetParameterValues(CGparameter param,
CGenum value_type,
int *nvalues);
CGDLL_API int cgGetParameterOrdinalNumber(CGparameter param);
CGDLL_API CGbool cgIsParameterGlobal(CGparameter param);
CGDLL_API int cgGetParameterIndex(CGparameter param);
CGDLL_API void cgSetParameterVariability(CGparameter param, CGenum vary);
CGDLL_API void cgSetParameterSemantic(CGparameter param, const char *semantic);
CGDLL_API void cgSetParameter1f(CGparameter param, float x);
CGDLL_API void cgSetParameter2f(CGparameter param, float x, float y);
CGDLL_API void cgSetParameter3f(CGparameter param, float x, float y, float z);
CGDLL_API void cgSetParameter4f(CGparameter param,
float x,
float y,
float z,
float w);
CGDLL_API void cgSetParameter1d(CGparameter param, double x);
CGDLL_API void cgSetParameter2d(CGparameter param, double x, double y);
CGDLL_API void cgSetParameter3d(CGparameter param,
double x,
double y,
double z);
CGDLL_API void cgSetParameter4d(CGparameter param,
double x,
double y,
double z,
double w);
CGDLL_API void cgSetParameter1fv(CGparameter param, const float *v);
CGDLL_API void cgSetParameter2fv(CGparameter param, const float *v);
CGDLL_API void cgSetParameter3fv(CGparameter param, const float *v);
CGDLL_API void cgSetParameter4fv(CGparameter param, const float *v);
CGDLL_API void cgSetParameter1dv(CGparameter param, const double *v);
CGDLL_API void cgSetParameter2dv(CGparameter param, const double *v);
CGDLL_API void cgSetParameter3dv(CGparameter param, const double *v);
CGDLL_API void cgSetParameter4dv(CGparameter param, const double *v);
CGDLL_API void cgSetMatrixParameterdr(CGparameter param, const double *matrix);
CGDLL_API void cgSetMatrixParameterfr(CGparameter param, const float *matrix);
CGDLL_API void cgSetMatrixParameterdc(CGparameter param, const double *matrix);
CGDLL_API void cgSetMatrixParameterfc(CGparameter param, const float *matrix);
/*** Type Functions ***/
CGDLL_API const char *cgGetTypeString(CGtype type);
CGDLL_API CGtype cgGetType(const char *type_string);
CGDLL_API CGtype cgGetNamedUserType(CGprogram program, const char *name);
CGDLL_API int cgGetNumUserTypes(CGprogram program);
CGDLL_API CGtype cgGetUserType(CGprogram program, int index);
CGDLL_API int cgGetNumParentTypes(CGtype type);
CGDLL_API CGtype cgGetParentType(CGtype type, int index);
CGDLL_API CGbool cgIsParentType(CGtype parent, CGtype child);
CGDLL_API CGbool cgIsInterfaceType(CGtype type);
/*** Resource Functions ***/
CGDLL_API const char *cgGetResourceString(CGresource resource);
CGDLL_API CGresource cgGetResource(const char *resource_string);
/*** Enum Functions ***/
CGDLL_API const char *cgGetEnumString(CGenum en);
CGDLL_API CGenum cgGetEnum(const char *enum_string);
/*** Profile Functions ***/
CGDLL_API const char *cgGetProfileString(CGprofile profile);
CGDLL_API CGprofile cgGetProfile(const char *profile_string);
/*** Error Functions ***/
CGDLL_API CGerror cgGetError(void);
CGDLL_API const char *cgGetErrorString(CGerror error);
CGDLL_API const char *cgGetLastErrorString(CGerror *error);
CGDLL_API void cgSetErrorCallback(CGerrorCallbackFunc func);
CGDLL_API CGerrorCallbackFunc cgGetErrorCallback(void);
/*** Misc Functions ***/
CGDLL_API const char *cgGetString(CGenum sname);
/*** Support for deprecated Cg 1.1 API ***/
CGDLL_API CGparameter cgGetNextParameter_depr1_1(CGparameter current);
CGDLL_API CGparameter cgGetNextLeafParameter_depr1_1(CGparameter current);
#ifdef CG_DEPRECATED_1_1_API
#define cgGetNextParameter cgGetNextParameter_depr1_1
#define cgGetNextLeafParameter cgGetNextLeafParameter_depr1_1
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,200 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*********************************************************************NVMH2****
File: cgContextManager.h
Copyright (C) 1999, 2000 NVIDIA Corporation
This file is provided without support, instruction, or implied warranty of any
kind. NVIDIA makes no guarantee of its fitness for a particular purpose and is
not liable under any circumstances for any damages or loss whatsoever arising
from the use or inability to use this file or items derived from it.
Comments:
cgContextManager - a class for loading various cg programs,
******************************************************************************/
#ifndef __NV_CG_MANAGER_H
#define __NV_CG_MANAGER_H
#if WIN32
#pragma warning (disable:4786) // identifier was truncated to '255' characters in the browser information
#include <windows.h>
#include <d3d8.h>
#include <d3dx8.h>
#include <Cg/cgTemplates.h>
#include <Cg/cg.h>
#include <Cg/cgProgramManager.h>
class cgContextManager;
class cgContextContainer
{
public:
// retrieve the listing file for the last compile
const char *GetLastListing();
// loads and compiles the cg program
cgProgramContainer * LoadCGProgramFromFile(
const char * filename, // filename of the Cg program
const char * title, // title of the program
cgProfileType type, // profile of the program
cgVertexDefinition * va = 0, // optionally, set streams or allow different vetex definitions
DWORD * outIndex = 0,
const char * entry = 0);
cgProgramContainer * LoadCGProgramFromMemory(
const char * memory, // memory location that contain the cg program
const char * title, // name of the program
cgProfileType type, // profile of the program
cgVertexDefinition * va = 0, // optionally, set the streams for each vertex entry
DWORD * outIndex = 0,
const char * entry = 0);
// use outIndex returned from LoadCGProgramFrom to retriece the program iterator
cgProgramContainer * GetProgramIterator(DWORD index);
// program operators (for multiple programs(vertex, pixel) in one cg
// pass NULL to get first program
cgProgramIter *GetNextProgram(cgProgramIter *iter);
// get a specific program
cgProgramIter *ProgramByName(const char *name);
// get the vertexshader or pixel shader handle that is passed to
// SetVertexShader and SetPixelShader
DWORD GetShaderHandle(cgProfileType type)
{
return pm.GetShaderHandle( type);
}
~cgContextContainer( );
friend class cgContextManager;
protected:
cgContextContainer( LPDIRECT3DDEVICE8 pd3dDevice, cgContext * context);
private:
cgProgramContainer * CreateProgramContainer(DWORD * outIndex = 0);
cgProgramContainer * CreateProgramContainer(
cgProgramIter *ProgramIter,
LPDIRECT3DDEVICE8 pd3dDevice,
DWORD * outIndex = 0); // index of this
// loads and compiles the cg program
HRESULT AddProgramFromFile(const char * filename, const char * name, cgProfileType type, const char * entry = 0);
HRESULT AddProgramFromMemory(const char * memory, const char * name, cgProfileType type, const char * entry = 0);
void Free();
cgProgramManager pm; // manage the vertex or pixel shader that is derived from this
cgContext * m_Context;
cg_string m_ContextDefinition;
LPDIRECT3DDEVICE8 m_pd3dDevice;
};
class cgContextManager
{
private:
cg_vector < cgContextContainer *> m_ContextContainers;
cg_vector < DWORD > m_ContextIndices; // indirection to m_Shaders
// Programs hold an index to this array for
// their shaders. The array int at that index
// holds the index into the m_Shaders array.
// each context has a list of programs (up to one for each profile)
public:
cgContextManager();
~cgContextManager();
cgError Free();
cgContextContainer *CreateContextContainer(LPDIRECT3DDEVICE8 pd3dDevice, DWORD * outIndex);
};
#endif // WIN32
#endif

View File

@@ -0,0 +1,158 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _cgD3D_h
#define _cgD3D_h
#if WIN32
#include <Cg/cg.h>
#include <assert.h>
#ifndef STRICT
#define STRICT
#endif
#include <windows.h>
#include <commdlg.h>
#include <tchar.h>
#include <stdio.h>
#include <d3d8.h>
#include <d3dx8.h>
#define MAX_STREAMS 16
#include <Cg/cgProgramManager.h>
#include <Cg/cgContextManager.h>
////////////////////////////////////////////////
//
// cgDX8Vertex and cgDX8Pixel are defined with
// macros:
//
// CG_PROFILE_MACRO(DX8Vertex,dx8vs,"dx8vs")
// CG_PROFILE_MACRO(DX8Pixel,dx8ps,"dx8ps")
//
// cgDX8VertexProfile
class cgDirect3D
{
public:
cgDirect3D();
~cgDirect3D();
// add a path to locate the cg programs
// do not add the trailing '\\'
void AddFilePath(const char * dirpath);
void AddFilePath(cg_string & path);
void NotePad(const char * title, const char * listing )
{
cg_string text;
text = title;
if(listing != NULL)
text += listing;
else
text += "*** NO LISTING ***\n";
char * TmpLstFile = tmpnam(0);
FILE * fpLst = fopen(TmpLstFile, "w");
fputs(text.c_str(), fpLst);
fclose(fpLst);
char Cmd[1000];
sprintf(Cmd, "notepad %s", TmpLstFile);
int Ret = system(Cmd);
unlink(TmpLstFile);
}
cgContextContainer * CreateContextContainer(LPDIRECT3DDEVICE8 pd3dDevice, DWORD * outIndex = 0)
{
return cm.CreateContextContainer(pd3dDevice, outIndex);
}
private:
cgContextManager cm;
LPDIRECT3DDEVICE8 m_pd3dDevice;
};
#define CGRTERR_ILLEGAL_PROFILE -1
#define CGRTERR_VERTEX_ATTRIBUTES_NOT_SET -2
#endif // WIN32
#endif

View File

@@ -0,0 +1,275 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef CGD3D8_INCLUDED
#define CGD3D8_INCLUDED
#if WIN32
#pragma once
#include "cg.h"
#include <d3d8.h>
#include <d3dx8.h>
// Set up for either Win32 import/export/lib.
#if WIN32
# include <windows.h>
#ifdef CGD3D8DLL_EXPORTS
#define CGD3D8DLL_API __declspec(dllexport)
#elif defined (CG_LIB)
#define CGD3D8DLL_API
#else
#define CGD3D8DLL_API __declspec(dllimport)
#endif
#else
#define CGD3D8DLL_API
#endif
/*---------------------------------------------------------------------------
// CGerrors that will be fed to cgSetError
// Use cgD3D8TranslateCGerror() to translate these errors into strings.
---------------------------------------------------------------------------*/
enum cgD3D8Errors
{
cgD3D8Failed = 1000,
cgD3D8DebugTrace = 1001,
};
/*---------------------------------------------------------------------------
// HRESULTs specific to cgD3D8. When the CGerror is set to cgD3D8Failed
// cgD3D8GetLastError will return an HRESULT that could be one these.
// Use cgD3D8TranslateHRESULT() to translate these errors into strings.
---------------------------------------------------------------------------*/
const HRESULT CGD3D8ERR_NOTLOADED = MAKE_HRESULT(1, 0x877, 1);
const HRESULT CGD3D8ERR_NODEVICE = MAKE_HRESULT(1, 0x877, 2);
const HRESULT CGD3D8ERR_NOTSAMPLER = MAKE_HRESULT(1, 0x877, 3);
const HRESULT CGD3D8ERR_INVALIDPROFILE = MAKE_HRESULT(1, 0x877, 4);
const HRESULT CGD3D8ERR_NULLVALUE = MAKE_HRESULT(1, 0x877, 5);
const HRESULT CGD3D8ERR_OUTOFRANGE = MAKE_HRESULT(1, 0x877, 6);
const HRESULT CGD3D8ERR_NOTUNIFORM = MAKE_HRESULT(1, 0x877, 7);
const HRESULT CGD3D8ERR_NOTMATRIX = MAKE_HRESULT(1, 0x877, 8);
const HRESULT CGD3D8ERR_INVALIDPARAM = MAKE_HRESULT(1, 0x877, 9);
const HRESULT CGD3D8ERR_INVALIDSAMPLERSTATE = MAKE_HRESULT(1, 0x877, 100);
const HRESULT CGD3D8ERR_INVALIDVEREXDECL = MAKE_HRESULT(1, 0x877, 101);
/*---------------------------------------------------------------------------
// Other error return values
---------------------------------------------------------------------------*/
const DWORD CGD3D8_INVALID_REG = 0xFFFFFFFF;
#ifdef __cplusplus
extern "C"
{
#endif
/*---------------------------------------------------------------------------
// Minimal Interface
---------------------------------------------------------------------------*/
CGD3D8DLL_API
DWORD cgD3D8TypeToSize(
CGtype type
);
CGD3D8DLL_API
DWORD cgD3D8ResourceToInputRegister(
CGresource resource
);
CGD3D8DLL_API
CGbool cgD3D8GetVertexDeclaration(
CGprogram prog,
DWORD decl[MAX_FVF_DECL_SIZE]
);
CGD3D8DLL_API
CGbool cgD3D8ValidateVertexDeclaration(
CGprogram prog,
const DWORD* decl
);
/*---------------------------------------------------------------------------
// Expanded Interface
---------------------------------------------------------------------------*/
/* ----- D3D Device Control ----------- */
CGD3D8DLL_API
IDirect3DDevice8* cgD3D8GetDevice();
CGD3D8DLL_API
HRESULT cgD3D8SetDevice(
IDirect3DDevice8* pDevice
);
/* ----- Shader Management ----------- */
CGD3D8DLL_API
HRESULT cgD3D8LoadProgram(
CGprogram prog,
CGbool paramShadowing,
DWORD assemFlags,
DWORD vshaderUsage,
const DWORD* vertexDecl
);
CGD3D8DLL_API
HRESULT cgD3D8UnloadProgram(
CGprogram prog
);
CGD3D8DLL_API
CGbool cgD3D8IsProgramLoaded(
CGprogram prog
);
CGD3D8DLL_API
HRESULT cgD3D8BindProgram(
CGprogram prog
);
/* ----- Parameter Management ----------- */
CGD3D8DLL_API
HRESULT cgD3D8SetUniform(
CGparameter param,
const void* floats
);
CGD3D8DLL_API
HRESULT cgD3D8SetUniformArray(
CGparameter param,
DWORD offset,
DWORD numItems,
const void* values
);
CGD3D8DLL_API
HRESULT cgD3D8SetUniformMatrix(
CGparameter param,
const D3DMATRIX* matrix
);
CGD3D8DLL_API
HRESULT cgD3D8SetUniformMatrixArray(
CGparameter param,
DWORD offset,
DWORD numItems,
const D3DMATRIX* matrices
);
CGD3D8DLL_API
HRESULT cgD3D8SetTexture(
CGparameter param,
IDirect3DBaseTexture8* tex
);
CGD3D8DLL_API
HRESULT cgD3D8SetTextureStageState(
CGparameter param,
D3DTEXTURESTAGESTATETYPE type,
DWORD value
);
CGD3D8DLL_API
HRESULT cgD3D8SetTextureWrapMode(
CGparameter param,
DWORD value
);
/* ----- Parameter Management (Shadowing) ----------- */
CGD3D8DLL_API
HRESULT cgD3D8EnableParameterShadowing(
CGprogram prog,
CGbool enable
);
CGD3D8DLL_API
CGbool cgD3D8IsParameterShadowingEnabled(
CGprogram prog
);
/* --------- Profile Options ----------------- */
CGD3D8DLL_API
CGprofile cgD3D8GetLatestVertexProfile();
CGD3D8DLL_API
CGprofile cgD3D8GetLatestPixelProfile();
CGD3D8DLL_API
char const* cgD3D8GetOptimalOptions(
CGprofile profile
);
/* --------- Error reporting ----------------- */
CGD3D8DLL_API
HRESULT cgD3D8GetLastError();
CGD3D8DLL_API
const char* cgD3D8TranslateCGerror(
CGerror error
);
CGD3D8DLL_API
const char* cgD3D8TranslateHRESULT(
HRESULT hr
);
CGD3D8DLL_API
void cgD3D8EnableDebugTracing(
CGbool enable
);
#ifdef __cplusplus
};
#endif
#endif // WIN32
#endif

View File

@@ -0,0 +1,271 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef CGD3D9_INCLUDED
#define CGD3D9_INCLUDED
#if WIN32
#pragma once
#include "cg.h"
#include <d3d9.h>
#include <d3dx9.h>
// Set up for either Win32 import/export/lib.
#if WIN32
# include <windows.h>
#ifdef CGD3D9DLL_EXPORTS
#define CGD3D9DLL_API __declspec(dllexport)
#elif defined (CG_LIB)
#define CGD3D9DLL_API
#else
#define CGD3D9DLL_API __declspec(dllimport)
#endif
#else
#define CGD3D9DLL_API
#endif
/*---------------------------------------------------------------------------
// CGerrors that will be fed to cgSetError
// Use cgD3D9TranslateCGerror() to translate these errors into strings.
---------------------------------------------------------------------------*/
enum cgD3D9Errors
{
cgD3D9Failed = 1000,
cgD3D9DebugTrace = 1001,
};
/*---------------------------------------------------------------------------
// HRESULTs specific to cgD3D9. When the CGerror is set to cgD3D9Failed
// cgD3D9GetLastError will return an HRESULT that could be one these.
// Use cgD3D9TranslateHRESULT() to translate these errors into strings.
---------------------------------------------------------------------------*/
static const HRESULT CGD3D9ERR_NOTLOADED = MAKE_HRESULT(1, 0x877, 1);
static const HRESULT CGD3D9ERR_NODEVICE = MAKE_HRESULT(1, 0x877, 2);
static const HRESULT CGD3D9ERR_NOTSAMPLER = MAKE_HRESULT(1, 0x877, 3);
static const HRESULT CGD3D9ERR_INVALIDPROFILE = MAKE_HRESULT(1, 0x877, 4);
static const HRESULT CGD3D9ERR_NULLVALUE = MAKE_HRESULT(1, 0x877, 5);
static const HRESULT CGD3D9ERR_OUTOFRANGE = MAKE_HRESULT(1, 0x877, 6);
static const HRESULT CGD3D9ERR_NOTUNIFORM = MAKE_HRESULT(1, 0x877, 7);
static const HRESULT CGD3D9ERR_NOTMATRIX = MAKE_HRESULT(1, 0x877, 8);
static const HRESULT CGD3D9ERR_INVALIDPARAM = MAKE_HRESULT(1, 0x877, 9);
/*---------------------------------------------------------------------------
// Other error return values
---------------------------------------------------------------------------*/
static const DWORD CGD3D9_INVALID_USAGE = 0xFF;
#ifdef __cplusplus
extern "C"
{
#endif
/*---------------------------------------------------------------------------
// Minimal Interface
---------------------------------------------------------------------------*/
CGD3D9DLL_API
DWORD cgD3D9TypeToSize(
CGtype type
);
CGD3D9DLL_API
BYTE cgD3D9ResourceToDeclUsage(
CGresource resource
);
CGD3D9DLL_API
CGbool cgD3D9GetVertexDeclaration(
CGprogram prog,
D3DVERTEXELEMENT9 decl[MAXD3DDECLLENGTH]
);
CGD3D9DLL_API
CGbool cgD3D9ValidateVertexDeclaration(
CGprogram prog,
const D3DVERTEXELEMENT9* decl
);
/*---------------------------------------------------------------------------
// Expanded Interface
---------------------------------------------------------------------------*/
/* ----- D3D Device Control ----------- */
CGD3D9DLL_API
IDirect3DDevice9* cgD3D9GetDevice();
CGD3D9DLL_API
HRESULT cgD3D9SetDevice(
IDirect3DDevice9* pDevice
);
/* ----- Shader Management ----------- */
CGD3D9DLL_API
HRESULT cgD3D9LoadProgram(
CGprogram prog,
CGbool paramShadowing,
DWORD assemFlags
);
CGD3D9DLL_API
HRESULT cgD3D9UnloadProgram(
CGprogram prog
);
CGD3D9DLL_API
CGbool cgD3D9IsProgramLoaded(
CGprogram prog
);
CGD3D9DLL_API
HRESULT cgD3D9BindProgram(
CGprogram prog
);
/* ----- Parameter Management ----------- */
CGD3D9DLL_API
HRESULT cgD3D9SetUniform(
CGparameter param,
const void* floats
);
CGD3D9DLL_API
HRESULT cgD3D9SetUniformArray(
CGparameter param,
DWORD offset,
DWORD numItems,
const void* values
);
CGD3D9DLL_API
HRESULT cgD3D9SetUniformMatrix(
CGparameter param,
const D3DMATRIX* matrix
);
CGD3D9DLL_API
HRESULT cgD3D9SetUniformMatrixArray(
CGparameter param,
DWORD offset,
DWORD numItems,
const D3DMATRIX* matrices
);
CGD3D9DLL_API
HRESULT cgD3D9SetTexture(
CGparameter param,
IDirect3DBaseTexture9* tex
);
CGD3D9DLL_API
HRESULT cgD3D9SetSamplerState(
CGparameter param,
D3DSAMPLERSTATETYPE type,
DWORD value
);
CGD3D9DLL_API
HRESULT cgD3D9SetTextureWrapMode(
CGparameter param,
DWORD value
);
/* ----- Parameter Management (Shadowing) ----------- */
CGD3D9DLL_API
HRESULT cgD3D9EnableParameterShadowing(
CGprogram prog,
CGbool enable
);
CGD3D9DLL_API
CGbool cgD3D9IsParameterShadowingEnabled(
CGprogram prog
);
/* --------- Profile Options ----------------- */
CGD3D9DLL_API
CGprofile cgD3D9GetLatestVertexProfile();
CGD3D9DLL_API
CGprofile cgD3D9GetLatestPixelProfile();
CGD3D9DLL_API
char const* cgD3D9GetOptimalOptions(
CGprofile profile
);
/* --------- Error reporting ----------------- */
CGD3D9DLL_API
HRESULT cgD3D9GetLastError();
CGD3D9DLL_API
const char* cgD3D9TranslateCGerror(
CGerror error
);
CGD3D9DLL_API
const char* cgD3D9TranslateHRESULT(
HRESULT hr
);
CGD3D9DLL_API
void cgD3D9EnableDebugTracing(
CGbool enable
);
#ifdef __cplusplus
};
#endif
#endif // WIN32
#endif

View File

@@ -0,0 +1,62 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
CG_PROFILE_MACRO(Vertex,vp20,VP20,"vp20",6146,1)
CG_PROFILE_MACRO(Fragment20,fp20,FP20,"fp20",6147,0)
CG_PROFILE_MACRO(Vertex30,vp30,VP30,"vp30",6148,1)
CG_PROFILE_MACRO(Fragment,fp30,FP30,"fp30",6149,0)
CG_PROFILE_MACRO(ARBVertex,arbvp1,ARBVP1,"arbvp1",6150,1)
CG_PROFILE_MACRO(ARBFragment,arbfp1,ARBFP1,"arbfp1",7000,0)
#ifndef CG_IN_PROFILES_INCLUDE
# undef CG_PROFILE_MACRO
#endif

View File

@@ -0,0 +1,326 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*********************************************************************NVMH2****
File: cgProgramManager.h
Copyright (C) 1999, 2000 NVIDIA Corporation
This file is provided without support, instruction, or implied warranty of any
kind. NVIDIA makes no guarantee of its fitness for a particular purpose and is
not liable under any circumstances for any damages or loss whatsoever arising
from the use or inability to use this file or items derived from it.
Comments:
cgProgramManager - a class for loading various pixel & vertex shaders
******************************************************************************/
#ifndef __NV_PROGRAM_MANAGER_H
#define __NV_PROGRAM_MANAGER_H
#if WIN32
#pragma warning (disable:4786) // identifier was truncated to '255' characters in the browser information
#include <windows.h>
#include <d3d8.h>
#include <d3dx8.h>
#include <Cg/cgTemplates.h>
#include <Cg/cg.h>
// to allow multiple streams and user specifed vertex type
// D3DVSDT_FLOAT1 0x00 // 1D float expanded to (value, 0., 0., 1.)
// D3DVSDT_FLOAT2 0x01 // 2D float expanded to (value, value, 0., 1.)
// D3DVSDT_FLOAT3 0x02 // 3D float expanded to (value, value, value, 1.)
// D3DVSDT_FLOAT4 0x03 // 4D float
// D3DVSDT_D3DCOLOR 0x04 // 4D packed unsigned bytes mapped to 0. to 1. range
// // Input is in D3DCOLOR format (ARGB) expanded to (R, G, B, A)
// D3DVSDT_UBYTE4 0x05 // 4D unsigned byte
// D3DVSDT_SHORT2 0x06 // 2D signed short expanded to (value, value, 0., 1.)
// D3DVSDT_SHORT4 0x07 // 4D signed short
// was cgVertexAttribute
typedef struct cgVertexDefinition
{
int D3DVSDT_type; // one of D3DVSDT_*
char * name; // name of the entry
int stream; // stream to put the vertex in
} cgVertexDefinition;
#define CGVERTEXDEFINITIONEND {-1, 0, 0}
// internal cgDirect3D data structure
typedef struct cgiVertexAttribute
{
char name[64];
int D3DVSDT_type;
int bind_location;
cgBindIter * BindIter;
} cgiVertexAttribute;
typedef cg_vector<cgiVertexAttribute> cgiVertexAttributeList;
typedef cg_list<cgBindIter *> cgBindIterList;
class cgProgramManager;
class cgContextContainer;
class cgProgramContainer
{
public:
// get a text definition of what the runtime expects for the vertex
const char * GetVertexDeclaration();
/*
Example: returns string containing
"struct stream0
{
D3DXVECTOR3 position;
D3DXVECTOR2 tex0;
};"
*/
// convert D3DXMATRIX class to type specified in cg program
// even if your cg program uses 3x3, you can use this to pass a matrix to it
// upper left hand part of D3DXMATRIX is used to fill the cg matrix
HRESULT SetShaderConstantD3DXMATRIX(cgBindIter * iter, const D3DXMATRIX *, int nArrayElements = 0, int ArrayOffset = 0);
// All other data formats use this interface
// The D3D runtime records the size of your data and puts that in the constant fields
HRESULT SetShaderConstant(cgBindIter * iter, void * data, int nArrayElements = 0, int ArrayOffset = 0);
// for arrays:
// if nArrayElements is specified, write this number of elements rather than the whole array
// if ArrayOffset is specified, start writing at this array element
// otherwise nArrayElements and ArrayOffset are not specified
// returns texture position 0-8 for the iterator
// -1 is failure
int GetTexturePosition(cgBindIter * BindIter);
int GetTexturePosition(const char * name);
// set the texture via name (needs to search bindings by name, so this is the slowest
// not recommended
HRESULT SetTexture(const char * name, LPDIRECT3DBASETEXTURE8 pTexture);
// does a GetTexturePosition, then settexture(n, nTexture)
HRESULT SetTexture(cgBindIter * BindIter, LPDIRECT3DBASETEXTURE8 pTexture);
// does a GetTexturePosition, then SetTextureStageState(n, nTexture, Value)
HRESULT SetTextureStageState(cgBindIter * BindIter, D3DTEXTURESTAGESTATETYPE Type,DWORD Value);
// Direct3D hardcodes wrap state, D3DRS_WRAP1, D3DWRAPCOORD_0 | D3DWRAPCOORD_1
// WrapCoords : 0, D3DWRAPCOORD_0, D3DWRAPCOORD_1 or'd together
HRESULT SetTextureWrapMode(cgBindIter * BindIter, DWORD WrapCoords);
// activate this shader (SetVertexShader or SetPixelShader)
HRESULT SetShaderActive();
// locate a binding within a program by parameter name
// it is recommended to do this once and use the cgBindIter to reference data
cgBindIter *GetVertexBindByName(const char *vertex_attr_name);
cgBindIter *GetTextureBindByName(const char *texture_name);
cgBindIter *GetParameterBindByName(const char *parameter_name);
void FreeBindIter(cgBindIter *);
// Get the type for this bind iterator
cgValueType GetBindValueType(const cgBindIter *BindIter, int *array_size)
{
return cgGetBindValueType(BindIter, array_size);
}
// locate and bindinf iterator by full name
// e.g. appdata.texcoord0
cgBindIter *GetBindByFullName(const char *parameter_name);
// from the iterator, get the name of the program
const char *GetProgramName();
const char *GetProgramObjectCode();
cgProfileType GetProgramProfile() { return m_ProfileType;}
// get the shader handle passed to Direct3D
DWORD GetShaderHandle() {return m_dwShaderHandle;}
private:
cgBindIter *AllocBind();
void SaveBind(cgBindIter * BindIter); // for deleting
cgBindIterList m_BindIterList;
void GetParameterConstantPosition(cgBindIter * iter, int * pos, int *width, int * num4vectors, int *nArrayElements);
void GetParameterConstantPosition(const char * name, int * pos, int *width, int * num4vectors, int *nArrayElements);
HRESULT CreateProgramShader();
HRESULT CreateVertexShader();
HRESULT CreatePixelShader();
// take asm code, assembles it and create a handle
HRESULT CreateShaderHandleFromFile(
const cg_string & strFilePath,
const cg_string & strSourceFile,
const DWORD * pDeclaration,
DWORD Usage);
HRESULT CreateShaderHandleFromMemory(
const char * pShaderText,
const DWORD * pDeclaration,
DWORD Usage);
HRESULT Free();
// cgDX8VertexProfile or cgDX8PixelProfile (cg_profiles.h)
// These types are defined with macros:
// CG_PROFILE_MACRO(DX8Vertex,dx8vs,"dx8vs")
// CG_PROFILE_MACRO(DX8Pixel,dx8ps,"dx8ps")
friend cgProgramManager;
friend cgContextContainer;
DWORD m_dwShaderHandle; // DWORD handle returned by DX8 runtime
cgProfileType m_ProfileType; // profile for this program
HRESULT SetVertexDefinition(cgVertexDefinition * streams);
cgProgramContainer(LPDIRECT3DDEVICE8 pDev, cgProgramIter *m_ProgramIter,
cgProfileType ProfileType);
~cgProgramContainer();
HRESULT LoadShaderConstants();
cg_string m_ProgramSourceFile; // text file name
cg_string m_ProgramObjectFile; // compiled shader object file (.vso, .pso)
// for declaration of vertex positions
cgiVertexAttributeList m_VertexAttributes[MAX_STREAMS];
cgProgramIter *m_ProgramIter;
LPDIRECT3DDEVICE8 m_pd3dDevice;
};
class cgProgramManager
{
private:
cg_vector < cgProgramContainer * > m_ProgramContainers; // m_Shaders[0] is always = 0
cg_vector < DWORD > m_ProgramIndices; // indirection to m_Shaders
// Programs hold an index to this array for
// their shaders. The array int at that index
// holds the index into the m_Shaders array.
public:
cgProgramManager(LPDIRECT3DDEVICE8 pDev);
~cgProgramManager();
HRESULT Free();
cgProgramContainer * CreateProgramContainer(LPDIRECT3DDEVICE8 pDev,
cgProgramIter * ProgramIter,
DWORD Usage,
cgProfileType ProfileType,
DWORD * outIndex );
DWORD GetShaderHandle( DWORD Index );
DWORD GetShaderHandle( cgProfileType ProfileType );
//
cgProgramContainer * GetProgramIterator(DWORD index);
private:
// for creating programs
LPDIRECT3DDEVICE8 m_pd3dDevice;
};
#endif // WIN32
#endif

View File

@@ -0,0 +1,363 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*********************************************************************NVMH2****
File: cgTemplates.h
Copyright (C) 1999, 2000 NVIDIA Corporation
This file is provided without support, instruction, or implied warranty of any
kind. NVIDIA makes no guarantee of its fitness for a particular purpose and is
not liable under any circumstances for any damages or loss whatsoever arising
from the use or inability to use this file or items derived from it.
Comments:
cgTemplates - cg utility templates
******************************************************************************/
#ifndef CG_TEMPLATE_H
#define CG_TEMPLATE_H
#include <stdlib.h>
//////////////////////////////////////////
//
// templated cg_vector class
//
//////////////////////////////////////////
template <class T>
class cg_vector{
public:
typedef int size_type;
cg_vector();
cg_vector( cg_vector<T>& v );
~cg_vector();
void clear();
int size() const;
T& operator [] ( int i );
void push_back( const T& t );
private:
T* data;
int num;
int capacity;
const static int initSize;
};
//definitions of cg_vector methods
template <class T>
const int cg_vector<T>::initSize = 16;
template <class T>
cg_vector<T>::cg_vector(){
data = NULL;
clear();
}
template <class T>
cg_vector<T>::cg_vector( cg_vector<T>& v ){
data = NULL;
clear();
for( int i=0; i<v.size(); i++ ){
push_back( v[i] );
}
}
template <class T>
cg_vector<T>::~cg_vector(){
delete[] data;
}
template <class T>
void cg_vector<T>::clear(){
if( data ){
delete[] data;
}
data = (T*)new T[initSize];
num = 0;
capacity = initSize;
}
template <class T>
int cg_vector<T>::size() const{
return num;
}
template <class T>
void cg_vector<T>::push_back( const T& t ){
if( num >= capacity ){
T* temp = new T[ 2 * capacity ];
for( int i = 0; i < num; i++ ){
temp[i] = data[i];
}
delete[] data;
data = temp;
capacity *= 2;
}
data[num] = t;
num++;
}
template <class T>
T& cg_vector<T>::operator [] ( int i ){
if( i>=0 && i < num ){
return data[i];
}else{
return data[0];
}
}
//////////////////////////////////////////
//
// templated cg_list class
//
//////////////////////////////////////////
template <class T>
class cg_list{
public:
class Node{
public:
Node( const T& _data, Node* _next, Node* _prev ){
data = _data;
next = _next;
prev = _prev;
}
T data;
Node* next;
Node* prev;
};
class iterator{
public:
iterator( Node* _node ){
node = _node;
}
iterator(){
node = NULL;
}
bool operator == ( const iterator& it ) const{
return node == it.node;
}
bool operator != ( const iterator& it ) const{
return !( *this == it );
}
T& operator * (){
return node -> data;
}
void operator ++ (){
node = node -> next;
}
void operator ++ (int){
node = node -> next;
}
Node* node;
};
cg_list();
cg_list( const cg_list<T>& l );
~cg_list();
iterator begin();
iterator end();
void push_back( const T& t );
void clear();
void remove( const T& value );
private:
Node* head;
Node* tail;
void insert( const T& t, Node* node );
void remove( Node* node );
};
// definitions of cg_list methods
template <class T>
cg_list<T>::cg_list(){
head = tail = new Node( T(), NULL, NULL );
}
template <class T>
cg_list<T>::~cg_list(){
clear();
delete head;
}
template <class T>
cg_list<T>::cg_list( const cg_list<T>& l ){
head = tail = new Node( T(), NULL, NULL );
cg_list<T>::iterator it = l.begin();
while( it != l.end() ){
push_back( *it );
it++;
}
}
template <class T>
cg_list<T>::iterator cg_list<T>::begin(){
return head;
}
template <class T>
cg_list<T>::iterator cg_list<T>::end(){
return tail;
}
template <class T>
void cg_list<T>::push_back( const T& t ){
insert( t, tail );
}
template <class T>
void cg_list<T>::clear(){
while( head != tail ){
remove( head );
}
}
template <class T>
void cg_list<T>::remove( const T& value ){
Node* curr = head;
Node* temp;
while( curr != tail ){
temp = curr;
curr = curr -> next;
if( temp -> data == value ){
remove( temp );
}
}
}
template <class T>
void cg_list<T>::insert( const T& t, cg_list<T>::Node* node ){
Node* newNode = new Node( t, node, node -> prev );
if( node -> prev == NULL ){
head = newNode;
}else{
node -> prev -> next = newNode;
}
node -> prev = newNode;
}
template <class T>
void cg_list<T>::remove( cg_list<T>::Node* node ){
if( node == tail ){
return;
}
node -> next -> prev = node -> prev;
if( node -> prev == NULL ){
head = node -> next;
}else{
node -> prev -> next = node -> next;
}
delete node;
}
//////////////////////////////////////////
//
// cg_string class
//
//////////////////////////////////////////
class cg_string{
public:
typedef int size_type;
cg_string();
cg_string( const char* s);
cg_string( const cg_string& s );
~cg_string();
int size() const;
const char* c_str() const;
void resize( int n, char c = '\0' );
cg_string& erase( int pos = 0, int n = npos );
int find_last_of( const cg_string& s, int pos = npos ) const;
cg_string substr( int pos = 0, int len = npos ) const;
char& operator [] ( int i );
const char& operator [] ( int i ) const;
cg_string& operator = ( const cg_string& s );
cg_string& operator += ( const cg_string& s );
cg_string operator + ( const cg_string& s ) const;
const static int npos;
private:
char* data;
int num; //length of the string, not counting the trailing '\0'.
int capacity;
const static int initSize;
void set( const char* s, int n );
};
#endif

View File

@@ -0,0 +1,332 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* The following macro invocations define the supported CG basic hardware
* bind locations.
*
* The macros have the form :
*
* CG_BINDLOCATION_MACRO(name, compiler_name, enum_int)
*
* name : The name of the location.
* enum_name : The C enumerant.
* compiler_name : The name of the location within the compiler syntax.
* int_id : Integer enumerant associated with this bind location.
* addressable : The bind location must have an integer address
* associated with it.
* ParamType : the cgParamType of this register.
*
*/
CG_BINDLOCATION_MACRO(TexUnit0,CG_TEXUNIT0,"texunit 0",2048,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit1,CG_TEXUNIT1,"texunit 1",2049,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit2,CG_TEXUNIT2,"texunit 2",2050,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit3,CG_TEXUNIT3,"texunit 3",2051,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit4,CG_TEXUNIT4,"texunit 4",2052,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit5,CG_TEXUNIT5,"texunit 5",2053,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit6,CG_TEXUNIT6,"texunit 6",2054,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit7,CG_TEXUNIT7,"texunit 7",2055,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit8,CG_TEXUNIT8,"texunit 8",2056,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit9,CG_TEXUNIT9,"texunit 9",2057,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit10,CG_TEXUNIT10,"texunit 10",2058,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit11,CG_TEXUNIT11,"texunit 11",2059,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit12,CG_TEXUNIT12,"texunit 12",2060,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit13,CG_TEXUNIT13,"texunit 13",2061,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit14,CG_TEXUNIT14,"texunit 14",2062,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(TexUnit15,CG_TEXUNIT15,"texunit 15",2063,0,CG_TEXOBJ_PARAM)
CG_BINDLOCATION_MACRO(Attr0,CG_ATTR0,"ATTR0",2113,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr1,CG_ATTR1,"ATTR1",2114,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr2,CG_ATTR2,"ATTR2",2115,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr3,CG_ATTR3,"ATTR3",2116,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr4,CG_ATTR4,"ATTR4",2117,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr5,CG_ATTR5,"ATTR5",2118,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr6,CG_ATTR6,"ATTR6",2119,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr7,CG_ATTR7,"ATTR7",2120,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr8,CG_ATTR8,"ATTR8",2121,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr9,CG_ATTR9,"ATTR9",2122,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr10,CG_ATTR10,"ATTR10",2123,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr11,CG_ATTR11,"ATTR11",2124,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr12,CG_ATTR12,"ATTR12",2125,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr13,CG_ATTR13,"ATTR13",2126,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr14,CG_ATTR14,"ATTR14",2127,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Attr15,CG_ATTR15,"ATTR15",2128,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(VertUniform,CG_C,"c",2178,1,CGI_UNIFORM_PARAM)
CG_BINDLOCATION_MACRO(Tex0,CG_TEX0,"TEX0",2179,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tex1,CG_TEX1,"TEX1",2180,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tex2,CG_TEX2,"TEX2",2181,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tex3,CG_TEX3,"TEX3",2192,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tex4,CG_TEX4,"TEX4",2193,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tex5,CG_TEX5,"TEX5",2194,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tex6,CG_TEX6,"TEX6",2195,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tex7,CG_TEX7,"TEX7",2196,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(HPos,CG_HPOS,"HPOS",2243,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Col0,CG_COL0,"COL0",2245,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Col1,CG_COL1,"COL1",2246,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Col2,CG_COL2,"COL2",2247,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Col3,CG_COL3,"COL3",2248,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSiz,CG_PSIZ,"PSIZ",2309,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(WPos,CG_WPOS,"WPOS",2373,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position0,CG_POSITION0,"POSITION0",2437,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position1,CG_POSITION1,"POSITION1",2438,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position2,CG_POSITION2,"POSITION2",2439,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position3,CG_POSITION3,"POSITION3",2440,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position4,CG_POSITION4,"POSITION4",2441,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position5,CG_POSITION5,"POSITION5",2442,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position6,CG_POSITION6,"POSITION6",2443,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position7,CG_POSITION7,"POSITION7",2444,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position8,CG_POSITION8,"POSITION8",2445,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position9,CG_POSITION9,"POSITION9",2446,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position10,CG_POSITION10,"POSITION10",2447,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position11,CG_POSITION11,"POSITION11",2448,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position12,CG_POSITION12,"POSITION12",2449,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position13,CG_POSITION13,"POSITION13",2450,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position14,CG_POSITION14,"POSITION14",2451,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Position15,CG_POSITION15,"POSITION15",2452,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Diffuse0,CG_DIFFUSE0,"DIFFUSE0",2501,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent0,CG_TANGENT0,"TANGENT0",2565,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent1,CG_TANGENT1,"TANGENT1",2566,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent2,CG_TANGENT2,"TANGENT2",2567,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent3,CG_TANGENT3,"TANGENT3",2568,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent4,CG_TANGENT4,"TANGENT4",2569,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent5,CG_TANGENT5,"TANGENT5",2570,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent6,CG_TANGENT6,"TANGENT6",2571,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent7,CG_TANGENT7,"TANGENT7",2572,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent8,CG_TANGENT8,"TANGENT8",2573,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent9,CG_TANGENT9,"TANGENT9",2574,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent10,CG_TANGENT10,"TANGENT10",2575,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent11,CG_TANGENT11,"TANGENT11",2576,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent12,CG_TANGENT12,"TANGENT12",2577,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent13,CG_TANGENT13,"TANGENT13",2578,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent14,CG_TANGENT14,"TANGENT14",2579,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Tangent15,CG_TANGENT15,"TANGENT15",2580,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Specular0,CG_SPECULAR0,"SPECULAR0",2629,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices0,CG_BLENDINDICES0,"BLENDINDICES0",2693,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices1,CG_BLENDINDICES1,"BLENDINDICES1",2694,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices2,CG_BLENDINDICES2,"BLENDINDICES2",2695,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices3,CG_BLENDINDICES3,"BLENDINDICES3",2696,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices4,CG_BLENDINDICES4,"BLENDINDICES4",2697,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices5,CG_BLENDINDICES5,"BLENDINDICES5",2698,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices6,CG_BLENDINDICES6,"BLENDINDICES6",2699,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices7,CG_BLENDINDICES7,"BLENDINDICES7",2700,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices8,CG_BLENDINDICES8,"BLENDINDICES8",2701,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices9,CG_BLENDINDICES9,"BLENDINDICES9",2702,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices10,CG_BLENDINDICES10,"BLENDINDICES10",2703,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices11,CG_BLENDINDICES11,"BLENDINDICES11",2704,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices12,CG_BLENDINDICES12,"BLENDINDICES12",2705,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices13,CG_BLENDINDICES13,"BLENDINDICES13",2706,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices14,CG_BLENDINDICES14,"BLENDINDICES14",2707,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendIndices15,CG_BLENDINDICES15,"BLENDINDICES15",2708,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color0,CG_COLOR0,"COLOR0",2757,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color1,CG_COLOR1,"COLOR1",2758,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color2,CG_COLOR2,"COLOR2",2759,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color3,CG_COLOR3,"COLOR3",2760,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color4,CG_COLOR4,"COLOR4",2761,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color5,CG_COLOR5,"COLOR5",2762,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color6,CG_COLOR6,"COLOR6",2763,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color7,CG_COLOR7,"COLOR7",2764,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color8,CG_COLOR8,"COLOR8",2765,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color9,CG_COLOR9,"COLOR9",2766,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color10,CG_COLOR10,"COLOR10",2767,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color11,CG_COLOR11,"COLOR11",2768,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color12,CG_COLOR12,"COLOR12",2769,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color13,CG_COLOR13,"COLOR13",2770,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color14,CG_COLOR14,"COLOR14",2771,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Color15,CG_COLOR15,"COLOR15",2772,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize0,CG_PSIZE0,"PSIZE0",2821,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize1,CG_PSIZE1,"PSIZE1",2822,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize2,CG_PSIZE2,"PSIZE2",2823,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize3,CG_PSIZE3,"PSIZE3",2824,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize4,CG_PSIZE4,"PSIZE4",2825,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize5,CG_PSIZE5,"PSIZE5",2826,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize6,CG_PSIZE6,"PSIZE6",2827,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize7,CG_PSIZE7,"PSIZE7",2828,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize8,CG_PSIZE8,"PSIZE8",2829,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize9,CG_PSIZE9,"PSIZE9",2830,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize10,CG_PSIZE10,"PSIZE10",2831,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize11,CG_PSIZE11,"PSIZE11",2832,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize12,CG_PSIZE12,"PSIZE12",2833,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize13,CG_PSIZE13,"PSIZE13",2834,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize14,CG_PSIZE14,"PSIZE14",2835,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(PSize15,CG_PSIZE15,"PSIZE15",2836,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal0,CG_BINORMAL0,"BINORMAL0",2885,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal1,CG_BINORMAL1,"BINORMAL1",2886,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal2,CG_BINORMAL2,"BINORMAL2",2887,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal3,CG_BINORMAL3,"BINORMAL3",2888,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal4,CG_BINORMAL4,"BINORMAL4",2889,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal5,CG_BINORMAL5,"BINORMAL5",2890,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal6,CG_BINORMAL6,"BINORMAL6",2891,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal7,CG_BINORMAL7,"BINORMAL7",2892,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal8,CG_BINORMAL8,"BINORMAL8",2893,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal9,CG_BINORMAL9,"BINORMAL9",2894,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal10,CG_BINORMAL10,"BINORMAL10",2895,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal11,CG_BINORMAL11,"BINORMAL11",2896,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal12,CG_BINORMAL12,"BINORMAL12",2897,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal13,CG_BINORMAL13,"BINORMAL13",2898,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal14,CG_BINORMAL14,"BINORMAL14",2899,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BiNormal15,CG_BINORMAL15,"BINORMAL15",2900,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG0,CG_FOG0,"FOG0",2917,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG1,CG_FOG1,"FOG1",2918,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG2,CG_FOG2,"FOG2",2919,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG3,CG_FOG3,"FOG3",2920,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG4,CG_FOG4,"FOG4",2921,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG5,CG_FOG5,"FOG5",2922,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG6,CG_FOG6,"FOG6",2923,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG7,CG_FOG7,"FOG7",2924,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG8,CG_FOG8,"FOG8",2925,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG9,CG_FOG9,"FOG9",2926,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG10,CG_FOG10,"FOG10",2927,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG11,CG_FOG11,"FOG11",2928,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG12,CG_FOG12,"FOG12",2929,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG13,CG_FOG13,"FOG13",2930,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG14,CG_FOG14,"FOG14",2931,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FOG15,CG_FOG15,"FOG15",2932,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH0,CG_DEPTH0,"DEPTH0",2933,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH1,CG_DEPTH1,"DEPTH1",2934,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH2,CG_DEPTH2,"DEPTH2",2935,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH3,CG_DEPTH3,"DEPTH3",2936,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH4,CG_DEPTH4,"DEPTH4",2937,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH5,CG_DEPTH5,"DEPTH5",2938,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH6,CG_DEPTH6,"DEPTH6",2939,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH7,CG_DEPTH7,"DEPTH7",2940,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH8,CG_DEPTH8,"DEPTH8",2941,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH9,CG_DEPTH9,"DEPTH9",29542,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH10,CG_DEPTH10,"DEPTH10",2943,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH11,CG_DEPTH11,"DEPTH11",2944,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH12,CG_DEPTH12,"DEPTH12",2945,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH13,CG_DEPTH13,"DEPTH13",2946,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH14,CG_DEPTH14,"DEPTH14",2947,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(DEPTH15,CG_DEPTH15,"DEPTH15",2948,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE0,CG_SAMPLE0,"SAMPLE0",2949,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE1,CG_SAMPLE1,"SAMPLE1",2950,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE2,CG_SAMPLE2,"SAMPLE2",2951,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE3,CG_SAMPLE3,"SAMPLE3",2952,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE4,CG_SAMPLE4,"SAMPLE4",2953,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE5,CG_SAMPLE5,"SAMPLE5",2954,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE6,CG_SAMPLE6,"SAMPLE6",2955,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE7,CG_SAMPLE7,"SAMPLE7",2956,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE8,CG_SAMPLE8,"SAMPLE8",2957,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE9,CG_SAMPLE9,"SAMPLE9",2958,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE10,CG_SAMPLE10,"SAMPLE10",2959,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE11,CG_SAMPLE11,"SAMPLE11",2960,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE12,CG_SAMPLE12,"SAMPLE12",2961,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE13,CG_SAMPLE13,"SAMPLE13",2962,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE14,CG_SAMPLE14,"SAMPLE14",2963,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(SAMPLE15,CG_SAMPLE15,"SAMPLE15",2964,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight0,CG_BLENDWEIGHT0,"BLENDWEIGHT0",3028,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight1,CG_BLENDWEIGHT1,"BLENDWEIGHT1",3029,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight2,CG_BLENDWEIGHT2,"BLENDWEIGHT2",3030,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight3,CG_BLENDWEIGHT3,"BLENDWEIGHT3",3031,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight4,CG_BLENDWEIGHT4,"BLENDWEIGHT4",3032,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight5,CG_BLENDWEIGHT5,"BLENDWEIGHT5",3033,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight6,CG_BLENDWEIGHT6,"BLENDWEIGHT6",3034,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight7,CG_BLENDWEIGHT7,"BLENDWEIGHT7",3035,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight8,CG_BLENDWEIGHT8,"BLENDWEIGHT8",3036,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight9,CG_BLENDWEIGHT9,"BLENDWEIGHT9",3037,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight10,CG_BLENDWEIGHT10,"BLENDWEIGHT10",3038,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight11,CG_BLENDWEIGHT11,"BLENDWEIGHT11",3039,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight12,CG_BLENDWEIGHT12,"BLENDWEIGHT12",3040,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight13,CG_BLENDWEIGHT13,"BLENDWEIGHT13",3041,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight14,CG_BLENDWEIGHT14,"BLENDWEIGHT14",3042,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(BlendWeight15,CG_BLENDWEIGHT15,"BLENDWEIGHT15",3043,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal0,CG_NORMAL0,"NORMAL0",3092,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal1,CG_NORMAL1,"NORMAL1",3093,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal2,CG_NORMAL2,"NORMAL2",3094,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal3,CG_NORMAL3,"NORMAL3",3095,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal4,CG_NORMAL4,"NORMAL4",3096,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal5,CG_NORMAL5,"NORMAL5",3097,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal6,CG_NORMAL6,"NORMAL6",3098,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal7,CG_NORMAL7,"NORMAL7",3099,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal8,CG_NORMAL8,"NORMAL8",3100,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal9,CG_NORMAL9,"NORMAL9",3101,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal10,CG_NORMAL10,"NORMAL10",3102,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal11,CG_NORMAL11,"NORMAL11",3103,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal12,CG_NORMAL12,"NORMAL12",3104,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal13,CG_NORMAL13,"NORMAL13",3105,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal14,CG_NORMAL14,"NORMAL14",3106,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(Normal15,CG_NORMAL15,"NORMAL15",3107,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(FogCoord,CG_FOGCOORD,"FOGCOORD",3156,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord0,CG_TEXCOORD0,"TEXCOORD0",3220,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord1,CG_TEXCOORD1,"TEXCOORD1",3221,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord2,CG_TEXCOORD2,"TEXCOORD2",3222,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord3,CG_TEXCOORD3,"TEXCOORD3",3223,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord4,CG_TEXCOORD4,"TEXCOORD4",3224,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord5,CG_TEXCOORD5,"TEXCOORD5",3225,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord6,CG_TEXCOORD6,"TEXCOORD6",3226,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord7,CG_TEXCOORD7,"TEXCOORD7",3227,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord8,CG_TEXCOORD8,"TEXCOORD8",3228,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord9,CG_TEXCOORD9,"TEXCOORD9",3229,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord10,CG_TEXCOORD10,"TEXCOORD10",3230,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord11,CG_TEXCOORD11,"TEXCOORD11",3231,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord12,CG_TEXCOORD12,"TEXCOORD12",3232,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord13,CG_TEXCOORD13,"TEXCOORD13",3233,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord14,CG_TEXCOORD14,"TEXCOORD14",3234,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(TexCoord15,CG_TEXCOORD15,"TEXCOORD15",3235,0,CG_VARYING_PARAM)
CG_BINDLOCATION_MACRO(CombinerConst0,CG_COMBINER_CONST0,"COMBINER_CONST0",3284,0,CGI_UNIFORM_PARAM)
CG_BINDLOCATION_MACRO(CombinerConst1,CG_COMBINER_CONST1,"COMBINER_CONST1",3285,0,CGI_UNIFORM_PARAM)
CG_BINDLOCATION_MACRO(CombinerStageConst0,CG_COMBINER_STAGE_CONST0,"COMBINER_STAGE_CONST0",3286,1,CGI_UNIFORM_PARAM)
CG_BINDLOCATION_MACRO(CombinerStageConst1,CG_COMBINER_STAGE_CONST1,"COMBINER_STAGE_CONST1",3287,1,CGI_UNIFORM_PARAM)
CG_BINDLOCATION_MACRO(OffsetTextureMatrix,CG_OFFSET_TEXTURE_MATRIX,"OFFSET_TEXTURE_MATRIX",3288,0,CGI_UNIFORM_PARAM)
CG_BINDLOCATION_MACRO(OffsetTextureScale,CG_OFFSET_TEXTURE_SCALE,"OFFSET_TEXTURE_SCALE",3289,0,CGI_UNIFORM_PARAM)
CG_BINDLOCATION_MACRO(OffsetTextureBias,CG_OFFSET_TEXTURE_BIAS,"OFFSET_TEXTURE_BIAS",3290,0,CGI_UNIFORM_PARAM)
CG_BINDLOCATION_MACRO(ConstEye,CG_CONST_EYE,"CONST_EYE",3291,0,CGI_UNIFORM_PARAM)
CG_BINDLOCATION_MACRO(TessFactor,CG_TESSFACTOR,"TESSFACTOR",3255,0,CG_VARYING_PARAM)
#undef CG_BINDLOCATION_MACRO

View File

@@ -0,0 +1,184 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* The following macro invocations define the supported CG basic data types.
*
* The macros have the form :
*
* CG_DATATYPE_MACRO(name, compiler_name, nrows, ncols)
*
* name : The name of the data type.
* compiler_name : The name of the data type within the compiler syntax.
* enum_name : The C enumerant.
* nrows : Number of rows for matrix types. Should be 0 other-wise.
* ncols : Number of columns for matrix types. Should be 0
* other-wise.
*
*/
CG_DATATYPE_MACRO(Half,half,CG_HALF,0,1)
CG_DATATYPE_MACRO(Half2,half2,CG_HALF2,0,2)
CG_DATATYPE_MACRO(Half3,half3,CG_HALF3,0,3)
CG_DATATYPE_MACRO(Half4,half4,CG_HALF4,0,4)
CG_DATATYPE_MACRO(Half1x1,half1x1,CG_HALF1x1,1,1)
CG_DATATYPE_MACRO(Half1x2,half1x2,CG_HALF1x2,1,2)
CG_DATATYPE_MACRO(Half1x3,half1x3,CG_HALF1x3,1,3)
CG_DATATYPE_MACRO(Half1x4,half1x4,CG_HALF1x4,1,4)
CG_DATATYPE_MACRO(Half2x1,half2x1,CG_HALF2x1,2,1)
CG_DATATYPE_MACRO(Half2x2,half2x2,CG_HALF2x2,2,2)
CG_DATATYPE_MACRO(Half2x3,half2x3,CG_HALF2x3,2,3)
CG_DATATYPE_MACRO(Half2x4,half2x4,CG_HALF2x4,2,4)
CG_DATATYPE_MACRO(Half3x1,half3x1,CG_HALF3x1,3,1)
CG_DATATYPE_MACRO(Half3x2,half3x2,CG_HALF3x2,3,2)
CG_DATATYPE_MACRO(Half3x3,half3x3,CG_HALF3x3,3,3)
CG_DATATYPE_MACRO(Half3x4,half3x4,CG_HALF3x4,3,4)
CG_DATATYPE_MACRO(Half4x1,half4x1,CG_HALF4x1,4,1)
CG_DATATYPE_MACRO(Half4x2,half4x2,CG_HALF4x2,4,2)
CG_DATATYPE_MACRO(Half4x3,half4x3,CG_HALF4x3,4,3)
CG_DATATYPE_MACRO(Half4x4,half4x4,CG_HALF4x4,4,4)
CG_DATATYPE_MACRO(Float,float,CG_FLOAT,0,1)
CG_DATATYPE_MACRO(Float2,float2,CG_FLOAT2,0,2)
CG_DATATYPE_MACRO(Float3,float3,CG_FLOAT3,0,3)
CG_DATATYPE_MACRO(Float4,float4,CG_FLOAT4,0,4)
CG_DATATYPE_MACRO(Float1x1,float1x1,CG_FLOAT1x1,1,1)
CG_DATATYPE_MACRO(Float1x2,float1x2,CG_FLOAT1x2,1,2)
CG_DATATYPE_MACRO(Float1x3,float1x3,CG_FLOAT1x3,1,3)
CG_DATATYPE_MACRO(Float1x4,float1x4,CG_FLOAT1x4,1,4)
CG_DATATYPE_MACRO(Float2x1,float2x1,CG_FLOAT2x1,2,1)
CG_DATATYPE_MACRO(Float2x2,float2x2,CG_FLOAT2x2,2,2)
CG_DATATYPE_MACRO(Float2x3,float2x3,CG_FLOAT2x3,2,3)
CG_DATATYPE_MACRO(Float2x4,float2x4,CG_FLOAT2x4,2,4)
CG_DATATYPE_MACRO(Float3x1,float3x1,CG_FLOAT3x1,3,1)
CG_DATATYPE_MACRO(Float3x2,float3x2,CG_FLOAT3x2,3,2)
CG_DATATYPE_MACRO(Float3x3,float3x3,CG_FLOAT3x3,3,3)
CG_DATATYPE_MACRO(Float3x4,float3x4,CG_FLOAT3x4,3,4)
CG_DATATYPE_MACRO(Float4x1,float4x1,CG_FLOAT4x1,4,1)
CG_DATATYPE_MACRO(Float4x2,float4x2,CG_FLOAT4x2,4,2)
CG_DATATYPE_MACRO(Float4x3,float4x3,CG_FLOAT4x3,4,3)
CG_DATATYPE_MACRO(Float4x4,float4x4,CG_FLOAT4x4,4,4)
CG_DATATYPE_MACRO(Sampler1D,sampler1D,CG_SAMPLER1D,0,0)
CG_DATATYPE_MACRO(Sampler2D,sampler2D,CG_SAMPLER2D,0,0)
CG_DATATYPE_MACRO(Sampler3D,sampler3D,CG_SAMPLER3D,0,0)
CG_DATATYPE_MACRO(SamplerRECT,samplerRECT,CG_SAMPLERRECT,0,0)
CG_DATATYPE_MACRO(SamplerCUBE,samplerCUBE,CG_SAMPLERCUBE,0,0)
CG_DATATYPE_MACRO(Fixed,fixed,CG_FIXED,0,1)
CG_DATATYPE_MACRO(Fixed2,fixed2,CG_FIXED2,0,2)
CG_DATATYPE_MACRO(Fixed3,fixed3,CG_FIXED3,0,3)
CG_DATATYPE_MACRO(Fixed4,fixed4,CG_FIXED4,0,4)
CG_DATATYPE_MACRO(Fixed1x1,fixed1x1,CG_FIXED1x1,1,1)
CG_DATATYPE_MACRO(Fixed1x2,fixed1x2,CG_FIXED1x2,1,2)
CG_DATATYPE_MACRO(Fixed1x3,fixed1x3,CG_FIXED1x3,1,3)
CG_DATATYPE_MACRO(Fixed1x4,fixed1x4,CG_FIXED1x4,1,4)
CG_DATATYPE_MACRO(Fixed2x1,fixed2x1,CG_FIXED2x1,2,1)
CG_DATATYPE_MACRO(Fixed2x2,fixed2x2,CG_FIXED2x2,2,2)
CG_DATATYPE_MACRO(Fixed2x3,fixed2x3,CG_FIXED2x3,2,3)
CG_DATATYPE_MACRO(Fixed2x4,fixed2x4,CG_FIXED2x4,2,4)
CG_DATATYPE_MACRO(Fixed3x1,fixed3x1,CG_FIXED3x1,3,1)
CG_DATATYPE_MACRO(Fixed3x2,fixed3x2,CG_FIXED3x2,3,2)
CG_DATATYPE_MACRO(Fixed3x3,fixed3x3,CG_FIXED3x3,3,3)
CG_DATATYPE_MACRO(Fixed3x4,fixed3x4,CG_FIXED3x4,3,4)
CG_DATATYPE_MACRO(Fixed4x1,fixed4x1,CG_FIXED4x1,4,1)
CG_DATATYPE_MACRO(Fixed4x2,fixed4x2,CG_FIXED4x2,4,2)
CG_DATATYPE_MACRO(Fixed4x3,fixed4x3,CG_FIXED4x3,4,3)
CG_DATATYPE_MACRO(Fixed4x4,fixed4x4,CG_FIXED4x4,4,4)
CG_DATATYPE_MACRO(Half1,half1,CG_HALF1,0,1)
CG_DATATYPE_MACRO(Float1,float1,CG_FLOAT1,0,1)
CG_DATATYPE_MACRO(Fixed1,fixed1,CG_FIXED1,0,1)
CG_DATATYPE_MACRO(Int,int,CG_INT,0,1)
CG_DATATYPE_MACRO(Int1,int1,CG_INT1,0,1)
CG_DATATYPE_MACRO(Int2,int2,CG_INT2,0,2)
CG_DATATYPE_MACRO(Int3,int3,CG_INT3,0,3)
CG_DATATYPE_MACRO(Int4,int4,CG_INT4,0,4)
CG_DATATYPE_MACRO(Int1x1,int1x1,CG_INT1x1,1,1)
CG_DATATYPE_MACRO(Int1x2,int1x2,CG_INT1x2,1,2)
CG_DATATYPE_MACRO(Int1x3,int1x3,CG_INT1x3,1,3)
CG_DATATYPE_MACRO(Int1x4,int1x4,CG_INT1x4,1,4)
CG_DATATYPE_MACRO(Int2x1,int2x1,CG_INT2x1,2,1)
CG_DATATYPE_MACRO(Int2x2,int2x2,CG_INT2x2,2,2)
CG_DATATYPE_MACRO(Int2x3,int2x3,CG_INT2x3,2,3)
CG_DATATYPE_MACRO(Int2x4,int2x4,CG_INT2x4,2,4)
CG_DATATYPE_MACRO(Int3x1,int3x1,CG_INT3x1,3,1)
CG_DATATYPE_MACRO(Int3x2,int3x2,CG_INT3x2,3,2)
CG_DATATYPE_MACRO(Int3x3,int3x3,CG_INT3x3,3,3)
CG_DATATYPE_MACRO(Int3x4,int3x4,CG_INT3x4,3,4)
CG_DATATYPE_MACRO(Int4x1,int4x1,CG_INT4x1,4,1)
CG_DATATYPE_MACRO(Int4x2,int4x2,CG_INT4x2,4,2)
CG_DATATYPE_MACRO(Int4x3,int4x3,CG_INT4x3,4,3)
CG_DATATYPE_MACRO(Int4x4,int4x4,CG_INT4x4,4,4)
CG_DATATYPE_MACRO(Bool,bool,CG_BOOL,0,1)
CG_DATATYPE_MACRO(Bool1,bool1,CG_BOOL1,0,1)
CG_DATATYPE_MACRO(Bool2,bool2,CG_BOOL2,0,2)
CG_DATATYPE_MACRO(Bool3,bool3,CG_BOOL3,0,3)
CG_DATATYPE_MACRO(Bool4,bool4,CG_BOOL4,0,4)
CG_DATATYPE_MACRO(Bool1x1,bool1x1,CG_BOOL1x1,1,1)
CG_DATATYPE_MACRO(Bool1x2,bool1x2,CG_BOOL1x2,1,2)
CG_DATATYPE_MACRO(Bool1x3,bool1x3,CG_BOOL1x3,1,3)
CG_DATATYPE_MACRO(Bool1x4,bool1x4,CG_BOOL1x4,1,4)
CG_DATATYPE_MACRO(Bool2x1,bool2x1,CG_BOOL2x1,2,1)
CG_DATATYPE_MACRO(Bool2x2,bool2x2,CG_BOOL2x2,2,2)
CG_DATATYPE_MACRO(Bool2x3,bool2x3,CG_BOOL2x3,2,3)
CG_DATATYPE_MACRO(Bool2x4,bool2x4,CG_BOOL2x4,2,4)
CG_DATATYPE_MACRO(Bool3x1,bool3x1,CG_BOOL3x1,3,1)
CG_DATATYPE_MACRO(Bool3x2,bool3x2,CG_BOOL3x2,3,2)
CG_DATATYPE_MACRO(Bool3x3,bool3x3,CG_BOOL3x3,3,3)
CG_DATATYPE_MACRO(Bool3x4,bool3x4,CG_BOOL3x4,3,4)
CG_DATATYPE_MACRO(Bool4x1,bool4x1,CG_BOOL4x1,4,1)
CG_DATATYPE_MACRO(Bool4x2,bool4x2,CG_BOOL4x2,4,2)
CG_DATATYPE_MACRO(Bool4x3,bool4x3,CG_BOOL4x3,4,3)
CG_DATATYPE_MACRO(Bool4x4,bool4x4,CG_BOOL4x4,4,4)
#undef CG_DATATYPE_MACRO

View File

@@ -0,0 +1,273 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _cg_deprecated_api_h
#define _cg_deprecated_api_h
// Set up for either Win32 import/export/lib.
#ifndef CGDLL_API
#ifdef WIN32
#ifdef CGDLL_EXPORTS
#define CGDLL_API __declspec(dllexport)
#elif defined (CG_LIB)
#define CGDLL_API
#else
#define CGDLL_API __declspec(dllimport)
#endif
#else
#define CGDLL_API
#endif
#endif
/*************************************************************************/
/*** CG Run-Time Library API ***/
/*************************************************************************/
/*************************************************************************/
/*** Data types and structures ***/
/*************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
# define CG_ERROR_MACRO(code, enum_name, new_enum_name, message) \
cg##enum_name = code,
# include <Cg/cg_errors.h>
} cgError;
typedef struct
{
/* Opaque structure */
void *Data;
} cgContext;
typedef struct
{
/* Opaque structure */
void *Data;
} cgProgramIter;
typedef struct
{
/* Opaque structure */
void *Data;
} cgBindIter;
typedef enum
{
cgUnknownValueType,
cgTypeStartEnum = 1024,
# define CG_DATATYPE_MACRO(name, compiler_name, enum_name, ncols, nrows) \
cg##name##ValueType,
#include <Cg/cg_datatypes.h>
} cgValueType;
typedef enum
{
cgConstParam,
cgUniformParam,
cgConnectorMemberParam,
cgVaryingParam = cgConnectorMemberParam,
cgTexObjParam,
cgAnyParam,
cgUndefinedParam,
} cgParamType;
typedef enum
{
# define CG_BINDLOCATION_MACRO(name,enum_name,compiler_name,\
enum_int,addressable,param_type) \
cgBind##name = enum_int,
#include <Cg/cg_bindlocations.h>
cgBindUndefined
} cgBindLocation;
typedef enum
{
cgProfileStart = 6144,
CG_PROFILE_UNKNOWN,
cgUnknownProfile = CG_PROFILE_UNKNOWN,
# define CG_PROFILE_MACRO(name, compiler_id, compiler_id_caps, compiler_opt,int_id,vertex_profile) \
cg##name##Profile = int_id,
# include "Cg/cg_profiles.h"
cgNProfiles,
} cgProfileType;
/*************************************************************************/
/*** Function Prototypes ***/
/*************************************************************************/
/*******************************************************************/
/*** cg Misc Functions ****/
/*******************************************************************/
CGDLL_API void cgCleanup(void);
/* This will probably be deprecated in future releases */
CGDLL_API void cgSetCompilerExe(const char *exe);
CGDLL_API const char *cgErrorMsg(cgError error);
/*******************************************************************/
/*** cgContext Functions ****/
/*******************************************************************/
CGDLL_API cgContext *cgCreateContext(void);
CGDLL_API void cgFreeContext(cgContext *context);
CGDLL_API cgError cgAddProgram(cgContext *context,
const char *text,
cgProfileType profile,
const char *entry);
CGDLL_API cgError cgAddProgramFromFile(cgContext *context,
const char *filename,
cgProfileType profile,
const char *entry);
CGDLL_API cgError cgAddProgramArgs(cgContext *context,
const char *text,
cgProfileType profile,
const char *entry,
int nargs,
const char **args);
CGDLL_API cgError cgAddProgramFromFileArgs(cgContext *context,
const char *filename,
cgProfileType profile,
const char *entry,
int nargs,
const char **args);
CGDLL_API cgError cgAddPrecompiledProgram(cgContext *context,
const char *text,
cgProfileType profile,
const char *entry);
CGDLL_API cgError cgAddPrecompiledProgramFromFile(cgContext *context,
const char *filename,
cgProfileType profile,
const char *entry);
CGDLL_API const char *cgGetLastListing(cgContext *context);
/*******************************************************************/
/*** cgProgram Functions ***/
/*******************************************************************/
CGDLL_API cgProgramIter *cgGetNextProgram(cgContext *context,
cgProgramIter *iter);
CGDLL_API cgProgramIter *cgProgramByName(cgContext *context,
const char *name);
CGDLL_API cgProgramIter *cgGetLastProgram(cgContext *context);
CGDLL_API void cgFreeProgramIter(cgProgramIter *program);
CGDLL_API const char *cgGetProgramName(const cgProgramIter *program);
CGDLL_API cgProfileType cgGetProgramProfile(const cgProgramIter *program);
CGDLL_API const char *cgGetProgramObjectCode(const cgProgramIter *program);
/*******************************************************************/
/*** Parameter and Binding Functions ****/
/*******************************************************************/
CGDLL_API cgBindIter *cgGetNextBind(cgProgramIter *program,
cgBindIter *iter);
CGDLL_API cgBindIter *cgGetBindByName(cgProgramIter *program,
const char *parameter_name);
CGDLL_API cgBindIter *cgDuplicateBindIter(cgBindIter *bind);
CGDLL_API void cgFreeBindIter(cgBindIter *iter);
CGDLL_API const char *cgGetBindParamName(const cgBindIter *bind);
CGDLL_API cgParamType cgGetBindParamType(const cgBindIter *bind);
CGDLL_API cgBindLocation cgGetBindLocation(const cgBindIter *bind);
CGDLL_API unsigned long cgGetBindAddress(const cgBindIter *bind);
CGDLL_API cgValueType cgGetBindValueType(const cgBindIter *bind,
int *array_size);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,95 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* The following macro invocations define the supported CG basic data types.
*
* The macros have the form :
*
* CG_DATATYPE_MACRO(enum_name, enum_val)
*
* enum_name : The C enumerant name.
* enum_val : The enumerant value.
*
*/
CG_ENUM_MACRO(CG_UNKNOWN, 4096)
CG_ENUM_MACRO(CG_IN, 4097)
CG_ENUM_MACRO(CG_OUT, 4098)
CG_ENUM_MACRO(CG_INOUT, 4099)
CG_ENUM_MACRO(CG_MIXED, 4100)
CG_ENUM_MACRO(CG_VARYING, 4101)
CG_ENUM_MACRO(CG_UNIFORM, 4102)
CG_ENUM_MACRO(CG_CONSTANT, 4103)
CG_ENUM_MACRO(CG_PROGRAM_SOURCE, 4104)
CG_ENUM_MACRO(CG_PROGRAM_ENTRY, 4105)
CG_ENUM_MACRO(CG_COMPILED_PROGRAM, 4106)
CG_ENUM_MACRO(CG_PROGRAM_PROFILE, 4107)
CG_ENUM_MACRO(CG_GLOBAL, 4108)
CG_ENUM_MACRO(CG_PROGRAM, 4109)
CG_ENUM_MACRO(CG_DEFAULT, 4110)
CG_ENUM_MACRO(CG_ERROR, 4111)
CG_ENUM_MACRO(CG_SOURCE, 4112)
CG_ENUM_MACRO(CG_OBJECT, 4113)
CG_ENUM_MACRO(CG_COMPILE_MANUAL, 4114)
CG_ENUM_MACRO(CG_COMPILE_IMMEDIATE, 4115)
CG_ENUM_MACRO(CG_COMPILE_LAZY, 4116)
CG_ENUM_MACRO(CG_CURRENT, 4117)
CG_ENUM_MACRO(CG_LITERAL, 4118)
CG_ENUM_MACRO(CG_VERSION, 4119)
#undef CG_ENUM_MACRO

View File

@@ -0,0 +1,235 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* The following macro invocations define error codes returned by various cg
* API functions.
*
* The macros have the form :
*
* CG_ERROR_MACRO(code, enum_name, message)
*
* code : The integer error code associated with the error.
* enum_name : The name of enumerant of the error code in the API.
* message : A description string associated with the error.
*
*/
CG_ERROR_MACRO(0,
CG_NO_ERROR,
"No error has occurred.")
CG_ERROR_MACRO(1,
CG_COMPILER_ERROR,
"The compile returned an error.")
CG_ERROR_MACRO(2,
CG_INVALID_PARAMETER_ERROR,
"The parameter used is invalid.")
CG_ERROR_MACRO(3,
CG_INVALID_PROFILE_ERROR,
"The profile is not supported.")
CG_ERROR_MACRO(4,
CG_PROGRAM_LOAD_ERROR,
"The program could not load.")
CG_ERROR_MACRO(5,
CG_PROGRAM_BIND_ERROR,
"The program could not bind.")
CG_ERROR_MACRO(6,
CG_PROGRAM_NOT_LOADED_ERROR,
"The program must be loaded before this operation may be used.")
CG_ERROR_MACRO(7,
CG_UNSUPPORTED_GL_EXTENSION_ERROR,
"An unsupported GL extension was required to perform this operation.")
CG_ERROR_MACRO(8,
CG_INVALID_VALUE_TYPE_ERROR,
"An unknown value type was assigned to a parameter.")
CG_ERROR_MACRO(9,
CG_NOT_MATRIX_PARAM_ERROR,
"The parameter is not of matrix type.")
CG_ERROR_MACRO(10,
CG_INVALID_ENUMERANT_ERROR,
"The enumerant parameter has an invalid value.")
CG_ERROR_MACRO(11,
CG_NOT_4x4_MATRIX_ERROR,
"The parameter must be a 4x4 matrix type.")
CG_ERROR_MACRO(12,
CG_FILE_READ_ERROR,
"The file could not be read.")
CG_ERROR_MACRO(13,
CG_FILE_WRITE_ERROR,
"The file could not be written.")
CG_ERROR_MACRO(14,
CG_NVPARSE_ERROR,
"nvparse could not successfully parse the output from the Cg "
"compiler backend.")
CG_ERROR_MACRO(15,
CG_MEMORY_ALLOC_ERROR,
"Memory allocation failed.")
CG_ERROR_MACRO(16,
CG_INVALID_CONTEXT_HANDLE_ERROR,
"Invalid context handle.")
CG_ERROR_MACRO(17,
CG_INVALID_PROGRAM_HANDLE_ERROR,
"Invalid program handle.")
CG_ERROR_MACRO(18,
CG_INVALID_PARAM_HANDLE_ERROR,
"Invalid parameter handle.")
CG_ERROR_MACRO(19,
CG_UNKNOWN_PROFILE_ERROR,
"The specified profile is unknown.")
CG_ERROR_MACRO(20,
CG_VAR_ARG_ERROR,
"The variable arguments were specified incorrectly.")
CG_ERROR_MACRO(21,
CG_INVALID_DIMENSION_ERROR,
"The dimension value is invalid.")
CG_ERROR_MACRO(22,
CG_ARRAY_PARAM_ERROR,
"The parameter must be an array.")
CG_ERROR_MACRO(23,
CG_OUT_OF_ARRAY_BOUNDS_ERROR,
"Index into the array is out of bounds.")
CG_ERROR_MACRO(24,
CG_CONFLICTING_TYPES_ERROR,
"A type being added to the context conflicts with an "
"existing type.")
CG_ERROR_MACRO(25,
CG_CONFLICTING_PARAMETER_TYPES_ERROR,
"The parameters being bound have conflicting types.")
CG_ERROR_MACRO(26,
CG_PARAMETER_IS_NOT_SHARED_ERROR,
"The parameter must be global.")
CG_ERROR_MACRO(27,
CG_INVALID_PARAMETER_VARIABILITY_ERROR,
"The parameter could not be changed to the given variability.")
CG_ERROR_MACRO(28,
CG_CANNOT_DESTROY_PARAMETER_ERROR,
"Cannot destroy the parameter. It is bound to other parameters "
"or is not a root parameter.")
CG_ERROR_MACRO(29,
CG_NOT_ROOT_PARAMETER_ERROR,
"The parameter is not a root parameter.")
CG_ERROR_MACRO(30,
CG_PARAMETERS_DO_NOT_MATCH_ERROR,
"The two parameters being bound do not match.")
CG_ERROR_MACRO(31,
CG_IS_NOT_PROGRAM_PARAMETER_ERROR,
"The parameter is not a program parameter.")
CG_ERROR_MACRO(32,
CG_INVALID_PARAMETER_TYPE_ERROR,
"The type of the parameter is invalid.")
CG_ERROR_MACRO(33,
CG_PARAMETER_IS_NOT_RESIZABLE_ARRAY_ERROR,
"The parameter must be a resizable array.")
CG_ERROR_MACRO(34,
CG_INVALID_SIZE_ERROR,
"The size value is invalid.")
CG_ERROR_MACRO(35,
CG_BIND_CREATES_CYCLE_ERROR,
"Cannot bind the given parameters. Binding will form a cycle.")
CG_ERROR_MACRO(36,
CG_ARRAY_TYPES_DO_NOT_MATCH_ERROR,
"Cannot bind the given parameters. Array types do not match.")
CG_ERROR_MACRO(37,
CG_ARRAY_DIMENSIONS_DO_NOT_MATCH_ERROR,
"Cannot bind the given parameters. "
"Array dimensions do not match.")
CG_ERROR_MACRO(38,
CG_ARRAY_HAS_WRONG_DIMENSION_ERROR,
"The array is has the wrong dimension.")
CG_ERROR_MACRO(39,
CG_TYPE_IS_NOT_DEFINED_IN_PROGRAM_ERROR,
"Connecting the parameters failed because The type of the "
"source parameter is not defined within the given program "
"or does not match the type with the same name in the program.")
#undef CG_ERROR_MACRO

View File

@@ -0,0 +1,90 @@
/*
*
* Copyright (c) 2002, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA<49>s copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* The following macro invocations define the supported CG profiles.
*
* The macros have the form :
*
* CG_PROFILE_MACRO(name, compiler_id, compiler_opt)
*
* name : The name of the profile. Used consistently with the API.
* compiler_id : The identifier string for the profile used by the compiler.
* compiler_id_caps : compiler_id in caps.
* compiler_opt : The command-line switch used to force compilation into
* the profile.
* int_id : Integer enumerant associated with this bind location.
* vertex_profile : Non-zero if this is a vertex profile, otherwise it
* is considered to be a fragment profile.
*
*
*/
#define CG_IN_PROFILES_INCLUDE
#include "Cg/cgGL_profiles.h"
CG_PROFILE_MACRO(DX9Vertex11,vs_1_1,VS_1_1,"vs_1_1",6153,1)
CG_PROFILE_MACRO(DX9Vertex20,vs_2_0,VS_2_0,"vs_2_0",6154,1)
CG_PROFILE_MACRO(DX9Vertex2x,vs_2_x,VS_2_X,"vs_2_x",6155,1)
CG_PROFILE_MACRO(DX9Vertex30,vs_3_0,VS_3_0,"vs_3_0",6156,1)
CG_PROFILE_MACRO(DX9Pixel11,ps_1_1,PS_1_1,"ps_1_1",6159,0)
CG_PROFILE_MACRO(DX9Pixel12,ps_1_2,PS_1_2,"ps_1_2",6160,0)
CG_PROFILE_MACRO(DX9Pixel13,ps_1_3,PS_1_3,"ps_1_3",6161,0)
CG_PROFILE_MACRO(DX9Pixel20,ps_2_0,PS_2_0,"ps_2_0",6162,0)
CG_PROFILE_MACRO(DX9Pixel2x,ps_2_x,PS_2_X,"ps_2_x",6163,0)
CG_PROFILE_MACRO(DX9Pixel30,ps_3_0,PS_3_0,"ps_3_0",6165,0)
#undef CG_PROFILE_MACRO
#undef CG_IN_PROFILES_INCLUDE

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,938 @@
/*=============================================================================
D3DCGPShader.h : Direct3D9 CG pixel shaders interface declaration.
Copyright 1999 K&M. All Rights Reserved.
Revision history:
* Created by Honitch Andrey
=============================================================================*/
#ifndef __D3DCGPSHADER_H__
#define __D3DCGPSAHDER_H__
#include "cg\cgD3D9.h"
#include <direct.h>
#define CG_FP_CACHE_VER 3.4
#define GL_OFFSET_TEXTURE_2D_MATRIX_NV 0x86E1
class CCGPShader_D3D : public CPShader
{
SCGScript *m_DeclarationsScript;
SCGScript *m_CoreScript;
SCGScript *m_InputParmsScript;
SCGScript *m_SubroutinesScript;
bool ActivateCacheItem(SShaderCacheHeaderItem *pItem);
bool CreateCacheItem(int nMask, byte *pData, int nLen);
int m_CurInst;
int m_dwFrame;
struct SCacheInstance
{
int m_Mask;
SShaderCache *m_pCache;
SCacheInstance()
{
m_Mask = 0;
m_pCache = NULL;
}
int Size()
{
int nSize = sizeof(*this);
return nSize;
}
};
struct SCGInstance
{
void *m_pHandle;
int m_Mask;
int m_LightMask;
CName m_PosScriptName;
TArray<SCGParam4f> *m_ParamsNoObj;
TArray<SCGParam4f> *m_ParamsObj;
TArray<SCGMatrix> *m_MatrixObj;
TArray<SCGBindConst> *m_BindConstants;
TArray<SCGBind> *m_BindVars;
int m_nCacheID;
SCGInstance()
{
m_Mask = 0;
m_LightMask = 0;
m_ParamsNoObj = NULL;
m_ParamsObj = NULL;
m_MatrixObj = NULL;
m_BindConstants = NULL;
m_BindVars = NULL;
m_pHandle = NULL;
m_nCacheID = -1;
}
int Size()
{
int nSize = sizeof(*this);
if (m_ParamsNoObj)
nSize += m_ParamsNoObj->GetMemoryUsage() + 12;
if (m_ParamsObj)
nSize += m_ParamsObj->GetMemoryUsage() + 12;
if (m_MatrixObj)
nSize += m_MatrixObj->GetMemoryUsage() + 12;
if (m_BindConstants)
nSize += m_BindConstants->GetMemoryUsage() + 12;
if (m_BindVars)
nSize += m_BindVars->GetMemoryUsage() + 12;
return nSize;
}
};
TArray<SCGInstance> m_Insts;
TArray<SCacheInstance> m_InstCache;
TArray<SCGParam4f> m_ParamsNoObj;
TArray<SCGParam4f> m_ParamsObj;
public:
// FX support
std::vector<SFXStruct> m_Functions;
CName m_EntryFunc;
virtual int Size()
{
int nSize = sizeof(*this);
if (m_DeclarationsScript)
nSize += m_DeclarationsScript->Size(false);
if (m_CoreScript)
nSize += m_CoreScript->Size(false);
if (m_InputParmsScript)
nSize += m_InputParmsScript->Size(false);
if (m_SubroutinesScript)
nSize += m_SubroutinesScript->Size(false);
nSize += m_ParamsNoObj.GetMemoryUsage();
nSize += m_ParamsObj.GetMemoryUsage();
for (int i=0; i<m_Insts.GetSize(); i++)
{
if (i < m_Insts.Num())
{
SCGInstance *cgi = &m_Insts[i];
nSize += cgi->Size();
}
else
nSize += sizeof(SCGInstance);
}
return nSize;
}
int mfGetCacheInstanceID(int Mask, const char *name=NULL)
{
int i;
for (i=0; i<m_InstCache.Num(); i++)
{
if (m_InstCache[i].m_Mask == Mask)
return i;
}
if (!name)
return -1;
int nNum = m_InstCache.Num();
SCacheInstance ci;
ci.m_pCache = gRenDev->m_cEF.OpenCacheFile(name, (float)CG_FP_CACHE_VER);
ci.m_Mask = Mask;
m_InstCache.AddElem(ci);
return nNum;
}
int mfGetCGInstanceID(int Type, int LightMask)
{
SCGInstance *cgi;
if (m_CurInst >= 0 && m_Insts.Num() > m_CurInst)
{
cgi = &m_Insts[m_CurInst];
if (cgi->m_Mask == Type && cgi->m_LightMask == LightMask)
return m_CurInst;
}
m_dwFrame++;
int i;
for (i=0; i<m_Insts.Num(); i++)
{
cgi = &m_Insts[i];
if (cgi->m_Mask == Type && cgi->m_LightMask == LightMask)
{
m_CurInst = i;
return i;
}
}
SCGInstance cg;
cg.m_Mask = Type;
cg.m_LightMask = LightMask;
cg.m_pHandle = NULL;
cg.m_ParamsNoObj = NULL;
cg.m_ParamsObj = NULL;
cg.m_BindConstants = NULL;
cg.m_BindVars = NULL;
cg.m_nCacheID = -1;
m_CurInst = m_Insts.Num();
m_Insts.AddElem(cg);
return m_CurInst;
}
TArray<SCGParam4f> *mfGetParams(int Type)
{
if (!Type)
return &m_ParamsNoObj;
else
return &m_ParamsObj;
}
CCGPShader_D3D(CGprofile ProfType)
{
m_CGProfileType = ProfType;
mfInit();
}
CCGPShader_D3D()
{
mfInit();
m_CGProfileType = CG_PROFILE_PS_1_1;
}
void mfSaveCGFile(const char *scr)
{
if (CRenderer::CV_r_shaderssave < 1)
return;
char name[1024];
if (m_nMaskGen)
sprintf(name, "%s$%x(%x).cg", m_Name.c_str(), m_Insts[m_CurInst].m_LightMask, m_nMaskGen);
else
sprintf(name, "%s.cg", m_Name.c_str());
FILE *fp = fopen(name, "w");
if (fp)
{
fprintf(fp, scr);
fclose (fp);
}
}
void mfInit()
{
#ifndef WIN64
// NOTE: AMD64 port: find the 64-bit CG runtime
if (!gcpRendD3D->m_CGContext)
{
cgD3D9SetDevice(gcpRendD3D->mfGetD3DDevice());
gcpRendD3D->m_CGContext = cgCreateContext();
assert(gcpRendD3D->m_CGContext);
#ifdef _DEBUG
cgD3D9EnableDebugTracing(true);
#endif
}
#endif
m_dwFrame = 1;
m_CurInst = -1;
m_CoreScript = NULL;
m_InputParmsScript = NULL;
m_SubroutinesScript = NULL;
m_DeclarationsScript = NULL;
m_bCGType = true;
}
void mfBind()
{
HRESULT hr;
if (m_Insts[m_CurInst].m_pHandle)
{
hr = gcpRendD3D->mfGetD3DDevice()->SetPixelShader((IDirect3DPixelShader9 *)m_Insts[m_CurInst].m_pHandle);
if (FAILED(hr))
return;
}
if (m_Insts[m_CurInst].m_BindConstants)
{
int i;
for (i=0; i<m_Insts[m_CurInst].m_BindConstants->Num(); i++)
{
SCGBindConst *p = &m_Insts[m_CurInst].m_BindConstants->Get(i);
gcpRendD3D->mfGetD3DDevice()->SetPixelShaderConstantF(p->m_dwBind, &p->m_Val[0], 1);
}
}
}
void mfUnbind()
{
gcpRendD3D->mfGetD3DDevice()->SetPixelShader(NULL);
}
char *mfLoadCG_Int(char *prog_text)
{
#ifndef WIN64
// NOTE: AMD64 port: find the 64-bit CG runtime
CGprofile pr = (CGprofile)m_CGProfileType;
//if (pr == CG_PROFILE_PS_1_1)
// pr = CG_PROFILE_PS_1_3;
// Use HLSL compiler for PS_2_X profile since it generates more efficient code (and bugs free)
if (pr == CG_PROFILE_PS_2_0 || pr == CG_PROFILE_PS_2_X || pr == CG_PROFILE_PS_3_0)
{
remove("$$out.cg");
// make command for execution
FILE *fp = fopen("$$in.cg", "w");
if (!fp)
return NULL;
fputs(prog_text, fp);
fclose (fp);
char szCmdLine[512];
char *sz2AProfile;
if ((gRenDev->GetFeatures() & RFT_HW_MASK) == RFT_HW_GFFX)
{
if (CRenderer::CV_r_sm2xpath == 2)
sz2AProfile = "ps_2_a";
else
sz2AProfile = "ps_2_b";
}
else
sz2AProfile = "ps_2_b";
sprintf(szCmdLine, "fxc.exe /T %s /DCGC=0 /Fc $$out.cg $$in.cg", pr == CG_PROFILE_PS_2_0 ? "ps_2_0" : pr == CG_PROFILE_PS_3_0 ? "ps_3_0" : sz2AProfile);
if (m_EntryFunc.GetIndex())
{
strcat(szCmdLine, " /E ");
strcat(szCmdLine, m_EntryFunc.c_str());
}
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
si.dwX = 100;
si.dwY = 100;
si.dwFlags = STARTF_USEPOSITION;
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
if( !CreateProcess( NULL, // No module name (use command line).
szCmdLine, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
CREATE_NO_WINDOW, // No creation flags.
NULL, // Use parent's environment block.
NULL/*szFolderName*/, // Set starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
iLog->LogError("CreateProcess failed: %s", szCmdLine);
return NULL;
}
while (WAIT_OBJECT_0 != WaitForSingleObject (pi.hProcess, 10000))
iLog->LogWarning ("CG runtime takes forever to compile.. waiting.. (last error %d)", GetLastError());
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
fp = fopen("$$out.cg", "rb");
if (!fp)
{
remove("$$in.cg");
return NULL;
}
fseek(fp, 0, SEEK_END);
int size = ftell(fp);
fseek(fp, 0, SEEK_SET);
if (size < 20)
{
remove("$$in.cg");
remove("$$out.cg");
return NULL;
}
char *pBuf = new char[size+1];
fread(pBuf, sizeof(char), size, fp);
pBuf[size] = '\0';
fclose(fp);
if (CRenderer::CV_r_shaderssave == 2)
{
_chdir("c:\\MasterCD\\TestCG");
mfSaveCGFile(prog_text);
_chdir("c:\\MasterCD");
}
remove("$$in.cg");
remove("$$out.cg");
return pBuf;
}
else
{
char szParams[256];
sprintf(szParams, "-DCGC=1");
const char *profileOpts[] =
{
szParams,
cgD3D9GetOptimalOptions(pr),
NULL,
};
CGprogram cgPr;
if (m_EntryFunc.GetIndex())
cgPr = cgCreateProgram(gcpRendD3D->m_CGContext, CG_SOURCE, prog_text, pr, m_EntryFunc.c_str(), profileOpts);
else
cgPr = cgCreateProgram(gcpRendD3D->m_CGContext, CG_SOURCE, prog_text, pr, "main", profileOpts);
CGerror err = cgGetError();
if (err != CG_NO_ERROR)
return NULL;
if (!cgPr)
{
Warning( 0,0,"Couldn't find function '%s' in CG pixel program '%s'", "main", m_Name.c_str());
return NULL;
}
if (CRenderer::CV_r_shaderssave == 2)
{
_chdir("c:\\MasterCD\\TestCG");
mfSaveCGFile(prog_text);
_chdir("c:\\MasterCD");
}
char *code = mfGetObjectCode(cgPr);
cgDestroyProgram(cgPr);
return code;
}
#else
CGprofile pr = (CGprofile)m_CGProfileType;
//if (pr == CG_PROFILE_PS_1_1)
// pr = CG_PROFILE_PS_1_3;
// Use HLSL compiler for PS_2_X profile since it generates more efficient code (and bugs free)
if (pr == CG_PROFILE_PS_2_0 || pr == CG_PROFILE_PS_2_X || pr == CG_PROFILE_PS_3_0)
{
// make command for execution
FILE *fp = fopen("$$in.cg", "w");
if (!fp)
return NULL;
fputs(prog_text, fp);
fclose (fp);
char szCmdLine[512];
char *sz2AProfile = (gRenDev->GetFeatures() & RFT_HW_MASK) == RFT_HW_GFFX ? "ps_2_a" : "ps_2_b";
sprintf(szCmdLine, "fxc.exe /T %s /DCGC=0 /Fc $$out.cg $$in.cg", pr == CG_PROFILE_PS_2_0 ? "ps_2_0" : pr == CG_PROFILE_PS_3_0 ? "ps_3_0" : sz2AProfile);
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
si.dwX = 100;
si.dwY = 100;
si.dwFlags = STARTF_USEPOSITION;
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
if( !CreateProcess( NULL, // No module name (use command line).
szCmdLine, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
CREATE_NO_WINDOW, // No creation flags.
NULL, // Use parent's environment block.
NULL/*szFolderName*/, // Set starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
iLog->LogError("CreateProcess failed: %s", szCmdLine);
return NULL;
}
while (WAIT_OBJECT_0 != WaitForSingleObject (pi.hProcess, 10000))
iLog->LogWarning ("CG runtime takes forever to compile.. waiting.. (last error %d)", GetLastError());
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
fp = fopen("$$out.cg", "rb");
if (!fp)
{
return NULL;
}
fseek(fp, 0, SEEK_END);
int size = ftell(fp);
fseek(fp, 0, SEEK_SET);
if (size < 20)
{
remove("$$in.cg");
remove("$$out.cg");
return NULL;
}
char *pBuf = new char[size+1];
fread(pBuf, sizeof(char), size, fp);
pBuf[size] = '\0';
fclose(fp);
remove("$$in.cg");
remove("$$out.cg");
return pBuf;
}
else
{
// make command for execution
FILE *fp = fopen("$$in.cg", "w");
if (!fp)
return NULL;
assert (*prog_text);
fputs(prog_text, fp);
fclose (fp);
char szCmdLine[512];
sprintf(szCmdLine, "cgc.exe -DCGC=1 -profile ps_1_1 -o $$out.cg $$in.cg");
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
si.dwX = 100;
si.dwY = 100;
si.dwFlags = STARTF_USEPOSITION;
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
if( !CreateProcess( NULL, // No module name (use command line).
szCmdLine, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
CREATE_NO_WINDOW, // No creation flags.
NULL, // Use parent's environment block.
NULL/*szFolderName*/, // Set starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
iLog->LogError("CreateProcess failed: %s", szCmdLine);
return NULL;
}
while (WAIT_OBJECT_0 != WaitForSingleObject (pi.hProcess, 10000))
iLog->LogWarning ("CG runtime takes forever to compile.. waiting.. (last error %d)", GetLastError());
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
fp = fopen("$$out.cg", "rb");
if (!fp)
{
remove("$$in.cg");
remove("$$out.cg");
return NULL;
}
fseek(fp, 0, SEEK_END);
int size = ftell(fp);
fseek(fp, 0, SEEK_SET);
if (size < 20)
{
remove("$$in.cg");
remove("$$out.cg");
return NULL;
}
char *pBuf = new char[size+1];
fread(pBuf, sizeof(char), size, fp);
pBuf[size] = '\0';
fclose(fp);
remove("$$in.cg");
remove("$$out.cg");
return pBuf;
}
#endif
}
char *mfLoadCG(char *prog_text)
{
// Test adding source text to context
char *pOut = mfLoadCG_Int(prog_text);
if (!pOut)
{
if ((m_Flags & PSFI_AUTOENUMTC) && m_CGProfileType != CG_PROFILE_PS_3_0 && m_CGProfileType != CG_PROFILE_PS_2_X)
{
if (gRenDev->GetFeatures() & RFT_HW_PS20)
{
if ((gRenDev->GetFeatures() & RFT_HW_MASK) == RFT_HW_GFFX)
m_CGProfileType = CG_PROFILE_PS_2_X;
else
m_CGProfileType = CG_PROFILE_PS_2_0;
pOut = mfLoadCG_Int(prog_text);
if (!pOut)
{
if (gRenDev->GetFeatures() & RFT_HW_PS30)
{
m_CGProfileType = CG_PROFILE_PS_3_0;
pOut = mfLoadCG_Int(prog_text);
}
}
}
}
}
if (!pOut)
{
m_nFailed++;
Warning( 0,0,"Couldn't create CG pixel program '%s'", m_Name.c_str());
mfSaveCGFile(prog_text);
}
return pOut;
}
const char *mfSkipLine(const char *prog)
{
while (*prog != 0xa) {prog++;}
prog++;
return prog;
}
const char *mfGetLine(const char *prog, char *line)
{
while (*prog == 0x20 || *prog == 0x9) {prog++;}
while (*prog != 0xa) {*line++ = *prog; prog++;}
*line = 0;
prog++;
return prog;
}
const char *mfGetTexInstruction(const char *prog, int& Op0, int& Op1)
{
Op0 = -1;
Op1 = -1;
char line[128];
const char *str = prog;
while (str = mfGetLine(str, line))
{
if (!line[0])
continue;
if (!strncmp(line, "def", 3))
continue;
if (strncmp(line, "tex", 3) != 0)
return NULL;
int n = 0;
while (line[n] != 0x20 && line[n] != 0x9 && line[n] != 0) {n++;}
if (line[n] == 0)
return str;
while (line[n] == 0x20 || line[n] == 0x9) {n++;}
if (line[n] == 0)
return str;
assert (line[n] == 't');
Op0 = atoi(&line[n+1]);
n += 2;
while (line[n] != 0x20 && line[n] != 0x9 && line[n] != 0) {n++;}
if (line[n] == 0)
return str;
while (line[n] == 0x20 || line[n] == 0x9) {n++;}
if (line[n] == 0)
return str;
assert (line[n] == 't');
Op1 = atoi(&line[n+1]);
return str;
}
return NULL;
}
LPD3DXBUFFER mfLoad(const char *prog_text)
{
// Assemble and create pixel shader
HRESULT hr;
LPD3DXBUFFER pCode;
LPD3DXBUFFER pBuffer = NULL;
char *pNewText = NULL;
if (m_Insts[m_CurInst].m_Mask & VPVST_CLIPPLANES3)
{
const char *str;
if (str=strstr(prog_text, "ps.1."))
{
int Op0, Op1;
str = mfSkipLine(str);
while (!strncmp(str, "def", 3))
{
str = mfSkipLine(str);
}
const char *sLastStr = str;
while (str=mfGetTexInstruction(str, Op0, Op1))
{
if (Op0 == 3 || Op1 == 3)
break;
sLastStr = str;
}
if (!str)
{
size_t size = strlen(prog_text)+strlen("texkill t3\n")+1;
pNewText = new char[size];
memcpy(pNewText, prog_text, sLastStr-prog_text);
strcpy(&pNewText[sLastStr-prog_text], "texkill t3\n");
strcpy(&pNewText[sLastStr-prog_text+strlen("texkill t3\n")], &prog_text[sLastStr-prog_text]);
}
}
}
if (pNewText)
hr = D3DXAssembleShader(pNewText, strlen(pNewText), NULL, NULL, 0, &pCode, &pBuffer);
else
hr = D3DXAssembleShader(prog_text, strlen(prog_text), NULL, NULL, 0, &pCode, &pBuffer);
if (FAILED(hr))
{
Warning( 0,0,"WARNING: CCGPShader_D3D::mfLoad: Could not assemble pixel shader '%s'(0x%x) (%s)\n", m_Name.c_str(), m_nMaskGen, gcpRendD3D->D3DError(hr));
if( pBuffer != NULL)
{
TCHAR* pstr;
TCHAR strOut[4096];
TCHAR* pstrOut;
// Need to replace \n with \r\n so edit box shows newlines properly
pstr = (TCHAR*)pBuffer->GetBufferPointer();
strOut[0] = '\0';
pstrOut = strOut;
for( int i = 0; i < 4096; i++ )
{
if( *pstr == '\n' )
*pstrOut++ = '\r';
*pstrOut = *pstr;
if( *pstr == '\0' )
break;
if( i == 4095 )
*pstrOut = '\0';
pstrOut++;
pstr++;
}
// remove any blank lines at the end
while( strOut[lstrlen(strOut) - 1] == '\n' || strOut[lstrlen(strOut) - 1] == '\r' )
{
strOut[lstrlen(strOut) - 1] = '\0';
}
Warning( 0,0,"WARNING: CCGPShader_D3D::mfLoad: Shader script error (%s)\n", strOut);
SAFE_RELEASE(pBuffer);
SAFE_DELETE_ARRAY(pNewText);
}
return NULL;
}
if (pCode && !(m_Flags & PSFI_PRECACHEPHASE))
hr = gcpRendD3D->mfGetD3DDevice()->CreatePixelShader((DWORD*)pCode->GetBufferPointer(), (IDirect3DPixelShader9 **)&m_Insts[m_CurInst].m_pHandle);
SAFE_RELEASE(pBuffer);
SAFE_DELETE_ARRAY(pNewText);
if (FAILED(hr))
{
Warning( 0,0,"CCGPShader_D3D::mfLoad: Could not create pixel shader '%s'(0x%x) (%s)\n", m_Name.c_str(), m_nMaskGen, gcpRendD3D->D3DError(hr));
return NULL;
}
return pCode;
}
void mfParameteri(SCGBind *ParamBind, const float *v)
{
int i;
if(!ParamBind)
return;
if (!ParamBind->m_dwBind || ParamBind->m_dwFrameCreated != m_dwFrame)
{
ParamBind->m_dwFrameCreated = m_dwFrame;
if (m_Insts[m_CurInst].m_BindVars)
{
for (i=0; i<m_Insts[m_CurInst].m_BindVars->Num(); i++)
{
SCGBind *p = &m_Insts[m_CurInst].m_BindVars->Get(i);
if (p->m_Name == ParamBind->m_Name)
{
ParamBind->m_dwBind = p->m_dwBind;
ParamBind->m_nBindComponents = p->m_nComponents;
if (!ParamBind->m_dwBind)
ParamBind->m_dwBind = 65536;
break;
}
}
if (i == m_Insts[m_CurInst].m_BindVars->Num())
ParamBind->m_dwBind = -1;
}
else
ParamBind->m_dwBind = -1;
if (ParamBind->m_dwBind == -1 && CRenderer::CV_r_shaderssave >= 2)
iLog->Log("Warning: couldn't find parameter %s for pixel shader %s (%x)", ParamBind->m_Name.c_str(), m_Name.c_str(), m_nMaskGen);
}
if ((int)ParamBind->m_dwBind == -1)
return;
int n;
int iparms[4];
if (ParamBind->m_dwBind == 65536)
n = 0;
else
n = ParamBind->m_dwBind;
if (m_CurParams[n][0] != v[0] || m_CurParams[n][1] != v[1] || m_CurParams[n][2] != v[2] || m_CurParams[n][3] != v[3])
{
m_CurParams[n][0] = v[0];
m_CurParams[n][1] = v[1];
m_CurParams[n][2] = v[2];
m_CurParams[n][3] = v[3];
iparms[0] = (int)v[0];
iparms[1] = (int)v[1];
iparms[2] = (int)v[2];
iparms[3] = (int)v[3];
gcpRendD3D->mfGetD3DDevice()->SetPixelShaderConstantI(n, iparms, 1);
}
v += 4;
}
void mfParameter(SCGBind *ParamBind, const float *v, int nComps)
{
int i;
if(!ParamBind)
return;
if (!ParamBind->m_dwBind || ParamBind->m_dwFrameCreated != m_dwFrame)
{
ParamBind->m_dwFrameCreated = m_dwFrame;
if (m_Insts[m_CurInst].m_BindVars)
{
for (i=0; i<m_Insts[m_CurInst].m_BindVars->Num(); i++)
{
SCGBind *p = &m_Insts[m_CurInst].m_BindVars->Get(i);
if (p->m_Name == ParamBind->m_Name)
{
assert(p->m_nComponents <= nComps);
ParamBind->m_dwBind = p->m_dwBind;
ParamBind->m_nBindComponents = p->m_nComponents;
if (!ParamBind->m_dwBind)
ParamBind->m_dwBind = 65536;
break;
}
}
if (i == m_Insts[m_CurInst].m_BindVars->Num())
ParamBind->m_dwBind = -1;
}
else
ParamBind->m_dwBind = -1;
if (ParamBind->m_dwBind == -1 && CRenderer::CV_r_shaderssave >= 2)
iLog->Log("Warning: couldn't find parameter %s for pixel shader %s (%x)", ParamBind->m_Name.c_str(), m_Name.c_str(), m_nMaskGen);
}
if ((int)ParamBind->m_dwBind == -1)
return;
if ((ParamBind->m_dwBind & 0xffff) == GL_OFFSET_TEXTURE_2D_MATRIX_NV)
{
int tmu = (ParamBind->m_dwBind >> 28) - 1;
float parm[4];
float fScaleX = CRenderer::CV_r_embm;
float fScaleY = CRenderer::CV_r_embm;
if (gcpRendD3D->m_bHackEMBM && gcpRendD3D->m_RP.m_TexStages[tmu].Texture && gcpRendD3D->m_RP.m_TexStages[tmu].Texture->m_eTT == eTT_Rectangle)
{
fScaleX *= (float)gcpRendD3D->GetWidth();
fScaleY *= (float)gcpRendD3D->GetHeight();
}
parm[0] = v[0] * fScaleX;
parm[1] = v[1] * fScaleX;
parm[2] = v[2] * fScaleY;
parm[3] = v[3] * fScaleY;
gcpRendD3D->mfGetD3DDevice()->SetTextureStageState(tmu, D3DTSS_BUMPENVMAT00, FLOATtoDWORD(parm[0]));
gcpRendD3D->mfGetD3DDevice()->SetTextureStageState(tmu, D3DTSS_BUMPENVMAT01, FLOATtoDWORD(parm[1]));
gcpRendD3D->mfGetD3DDevice()->SetTextureStageState(tmu, D3DTSS_BUMPENVMAT10, FLOATtoDWORD(parm[2]));
gcpRendD3D->mfGetD3DDevice()->SetTextureStageState(tmu, D3DTSS_BUMPENVMAT11, FLOATtoDWORD(parm[3]));
gcpRendD3D->mfGetD3DDevice()->SetTextureStageState(tmu, D3DTSS_BUMPENVLSCALE, FLOATtoDWORD(4.0f));
gcpRendD3D->mfGetD3DDevice()->SetTextureStageState(tmu, D3DTSS_BUMPENVLOFFSET, FLOATtoDWORD(0.0f));
}
else
{
int nR;
if (ParamBind->m_dwBind == 65536)
nR = 0;
else
nR = ParamBind->m_dwBind;
for (int i=0; i<ParamBind->m_nBindComponents; i++)
{
int n = nR+i;
if (m_CurParams[n][0] != v[0] || m_CurParams[n][1] != v[1] || m_CurParams[n][2] != v[2] || m_CurParams[n][3] != v[3])
{
m_CurParams[n][0] = v[0];
m_CurParams[n][1] = v[1];
m_CurParams[n][2] = v[2];
m_CurParams[n][3] = v[3];
gcpRendD3D->mfGetD3DDevice()->SetPixelShaderConstantF(n, v, 1);
}
v += 4;
}
}
}
void mfParameter4i(SCGBind *ParamBind, const float *v)
{
mfParameteri(ParamBind, v);
}
void mfParameter4f(SCGBind *ParamBind, const float *v)
{
mfParameter(ParamBind, v, 1);
}
SCGBind *mfGetParameterBind(const char *Name)
{
CName nm = CName(Name, eFN_Add);
if (!m_Insts[m_CurInst].m_BindVars)
m_Insts[m_CurInst].m_BindVars = new TArray<SCGBind>;
int i;
for (i=0; i<m_Insts[m_CurInst].m_BindVars->Num(); i++)
{
if (nm == m_Insts[m_CurInst].m_BindVars->Get(i).m_Name)
return &m_Insts[m_CurInst].m_BindVars->Get(i);
}
return NULL;
}
void mfParameter4f(const char *Name, const float *v)
{
SCGBind *pBind = mfGetParameterBind(Name);
if (pBind)
mfParameter4f(pBind, v);
}
virtual void mfEnable()
{
}
virtual void mfDisable()
{
}
void mfFree();
void mfDelInst()
{
if(m_Insts[m_CurInst].m_pHandle && (INT_PTR)m_Insts[m_CurInst].m_pHandle != -1)
{
if (m_Insts[m_CurInst].m_BindConstants)
delete m_Insts[m_CurInst].m_BindConstants;
if (m_Insts[m_CurInst].m_BindVars)
delete m_Insts[m_CurInst].m_BindVars;
if (m_Insts[m_CurInst].m_ParamsNoObj)
delete m_Insts[m_CurInst].m_ParamsNoObj;
IDirect3DPixelShader9 *pVS = (IDirect3DPixelShader9 *)m_Insts[m_CurInst].m_pHandle;
SAFE_RELEASE (pVS);
}
m_Insts[m_CurInst].m_pHandle = NULL;
}
void mfSetVariables(TArray<SCGParam4f>* Parms);
bool mfIsValid(int Num) const { return (m_Insts[m_CurInst].m_pHandle != NULL); }
void mfGetSrcFileName(char *srcname, int nSize);
void mfGetDstFileName(char *dstname, int nSize, bool bUseASCIICache);
void mfPrecacheLights(int nMask);
public:
char *mfGenerateScriptPS();
char *mfCreateAdditionalPS();
void mfCompileParam4f(char *scr, SShader *ef, TArray<SCGParam4f> *Params);
bool mfActivate();
void mfConstructFX(std::vector<SFXStruct>& Structs, std::vector<SPair>& Macros, char *entryFunc);
void mfAddFXParameter(SFXParam *pr, const char *ParamName, SShader *ef);
bool mfGetFXParamNameByID(int nParam, char *ParamName);
public:
virtual ~CCGPShader_D3D();
virtual void Release();
virtual bool mfCompile(char *scr);
virtual bool mfSet(bool bStat, SShaderPassHW *slw=NULL, int nFlags=0);
virtual void mfSetVariables(bool bObj, TArray<SCGParam4f>* Vars);
virtual void mfReset();
virtual void mfPrecache();
virtual bool mfIsCombiner() { return false; }
virtual void mfGatherFXParameters(const char *buf, SShaderPassHW *pSHPass, std::vector<SFXParam>& Params, std::vector<SFXSampler>& Samplers, std::vector<SFXTexture>& Textures, SShader *ef);
virtual void mfPostLoad();
char *mfGetObjectCode(CGprogram cgPr)
{
const char *code = cgGetProgramString(cgPr, CG_COMPILED_PROGRAM);
size_t size = strlen(code)+1;
char *str = new char[size];
cryMemcpy(str, code, size);
return str;
}
static vec4_t m_CurParams[32];
};
#endif // __GLCGPSHADER_H__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,995 @@
/*=============================================================================
D3DCGVProgram.h : Direct3D CG programs interface declaration.
Copyright 1999 K&M. All Rights Reserved.
Revision history:
* Created by Honitch Andrey
=============================================================================*/
#ifndef __D3DCGVPROGRAM_H__
#define __D3DCGVPROGRAM_H__
#include "cg\cgD3D9.h"
#include <direct.h>
#define CG_VP_CACHE_VER 3.4
#define VSCONST_0_025_05_1 28
#define VSCONST_FOG 29
#define PSCONST_HDR_FOGCOLOR 31
class CCGVProgram_D3D : public CVProgram
{
SCGScript *m_Script;
SCGScript *m_PosScript;
SCGScript *m_SubroutinesScript;
SCGScript *m_DeclarationsScript;
SCGScript *m_CoreScript;
SCGScript *m_InputParmsScript;
// FX support
std::vector<SFXStruct> m_Functions;
CName m_EntryFunc;
bool ActivateCacheItem(SShaderCacheHeaderItem *pItem);
bool CreateCacheItem(int nMask, byte *pData, int nLen);
TArray<SCGParam4f> m_ParamsNoObj;
TArray<SCGParam4f> m_ParamsObj;
TArray<SCGMatrix> m_MatrixObj;
TArray<SArrayPointer *> m_Pointers;
int m_CurInst;
struct SCacheInstance
{
int m_Mask;
SShaderCache *m_pCache;
SCacheInstance()
{
m_Mask = 0;
m_pCache = NULL;
}
int Size()
{
int nSize = sizeof(*this);
return nSize;
}
};
struct SCGInstance
{
int m_Mask;
int m_LightMask;
CName m_PosScriptName;
TArray<SCGParam4f> *m_ParamsNoObj;
TArray<SCGMatrix> *m_MatrixNoObj;
TArray<SCGParam4f> *m_ParamsObj;
TArray<SCGMatrix> *m_MatrixObj;
TArray<SCGBindConst> *m_BindConstants;
TArray<SCGBind> *m_BindVars;
int m_nCacheID;
union
{
CGprogram m_CGProgram;
void *m_pHandle;
};
SCGInstance()
{
m_Mask = 0;
m_LightMask = 0;
m_ParamsNoObj = NULL;
m_ParamsObj = NULL;
m_MatrixNoObj = NULL;
m_MatrixObj = NULL;
m_BindConstants = NULL;
m_BindVars = NULL;
m_pHandle = NULL;
m_nCacheID = -1;
}
int Size()
{
int nSize = sizeof(*this);
if (m_ParamsNoObj)
nSize += m_ParamsNoObj->GetMemoryUsage()+12;
if (m_ParamsObj)
nSize += m_ParamsObj->GetMemoryUsage()+12;
if (m_MatrixNoObj)
nSize += m_MatrixNoObj->GetMemoryUsage()+12;
if (m_MatrixObj)
nSize += m_MatrixObj->GetMemoryUsage()+12;
if (m_BindConstants)
nSize += m_BindConstants->GetMemoryUsage()+12;
if (m_BindVars)
nSize += m_BindVars->GetMemoryUsage()+12;
return nSize;
}
};
TArray<SCGInstance> m_Insts;
TArray<SCacheInstance> m_InstCache;
public:
int m_dwFrame;
TArray<SCGParam4f> m_Params_Inst;
virtual int Size()
{
int nSize = sizeof(*this);
for (int i=0; i<m_Insts.GetSize(); i++)
{
if (i < m_Insts.Num())
{
SCGInstance *cgi = &m_Insts[i];
nSize += cgi->Size();
}
else
nSize += sizeof(SCGInstance);
}
if (m_Script)
nSize += m_Script->Size(false);
if (m_PosScript)
nSize += m_PosScript->Size(false);
if (m_SubroutinesScript)
nSize += m_SubroutinesScript->Size(false);
if (m_DeclarationsScript)
nSize += m_DeclarationsScript->Size(false);
if (m_CoreScript)
nSize += m_CoreScript->Size(false);
if (m_InputParmsScript)
nSize += m_InputParmsScript->Size(false);
nSize += m_ParamsObj.GetMemoryUsage();
nSize += m_ParamsNoObj.GetMemoryUsage();
nSize += m_MatrixObj.GetMemoryUsage();
return nSize;
}
void mfSaveCGFile(const char *scr)
{
if (CRenderer::CV_r_shaderssave < 1)
return;
char name[1024];
if (m_nMaskGen)
sprintf(name, "%s$%x(%x).cg", m_Name.c_str(), m_Insts[m_CurInst].m_LightMask, m_nMaskGen);
else
sprintf(name, "%s.cg", m_Name.c_str());
FILE *fp = fopen(name, "w");
if (fp)
{
fprintf(fp, scr);
fclose (fp);
}
}
CCGVProgram_D3D()
{
mfInit();
m_CGProfileType = CG_PROFILE_VS_1_1;
}
void mfInit()
{
#ifndef WIN64
// NOTE: AMD64 port: find the 64-bit CG runtime
if (!gcpRendD3D->m_CGContext)
{
cgD3D9SetDevice(gcpRendD3D->mfGetD3DDevice());
gcpRendD3D->m_CGContext = cgCreateContext();
assert(gcpRendD3D->m_CGContext);
#ifdef _DEBUG
cgD3D9EnableDebugTracing(true);
#endif
}
#endif
m_dwFrame = 1;
m_CurInst = -1;
m_Script = NULL;
m_SubroutinesScript = NULL;
m_CoreScript = NULL;
m_InputParmsScript = NULL;
m_PosScript = NULL;
m_DeclarationsScript = NULL;
m_bCGType = true;
}
void mfFree();
void mfGetSrcFileName(char *srcname, int nSize);
void mfGetDstFileName(char *dstname, int nSize, bool bUseASCIICache);
TArray<SCGParam4f> *mfGetParams(int Type)
{
if (!Type)
return &m_ParamsNoObj;
else
return &m_ParamsObj;
}
void mfUnbind()
{
gcpRendD3D->mfGetD3DDevice()->SetVertexShader(NULL);
}
void mfBind()
{
HRESULT hr;
if (m_Insts[m_CurInst].m_pHandle)
{
hr = gcpRendD3D->mfGetD3DDevice()->SetVertexShader((IDirect3DVertexShader9 *)m_Insts[m_CurInst].m_pHandle);
if (FAILED(hr))
return;
}
if (m_Insts[m_CurInst].m_BindConstants)
{
int i;
for (i=0; i<m_Insts[m_CurInst].m_BindConstants->Num(); i++)
{
SCGBindConst *p = &m_Insts[m_CurInst].m_BindConstants->Get(i);
int n = p->m_dwBind;
if (m_CurParams[n][0] != p->m_Val[0] || m_CurParams[n][1] != p->m_Val[1] || m_CurParams[n][2] != p->m_Val[2] || m_CurParams[n][3] != p->m_Val[3])
{
m_CurParams[n][0] = p->m_Val[0];
m_CurParams[n][1] = p->m_Val[1];
m_CurParams[n][2] = p->m_Val[2];
m_CurParams[n][3] = p->m_Val[3];
gcpRendD3D->mfGetD3DDevice()->SetVertexShaderConstantF(n, &p->m_Val[0], 1);
}
}
}
}
int mfGetCacheInstanceID(int Mask, const char *name=NULL)
{
int i;
for (i=0; i<m_InstCache.Num(); i++)
{
if (m_InstCache[i].m_Mask == Mask)
return i;
}
if (!name)
return -1;
int nNum = m_InstCache.Num();
SCacheInstance ci;
ci.m_pCache = gRenDev->m_cEF.OpenCacheFile(name, (float)CG_VP_CACHE_VER);
ci.m_Mask = Mask;
m_InstCache.AddElem(ci);
return nNum;
}
int mfGetCGInstanceID(int Type, CVProgram *pPosVP, int LightMask)
{
CCGVProgram_D3D *pVP = (CCGVProgram_D3D *)pPosVP;
SCGInstance *cgc;
CName PosName;
SCGScript *posScr = pVP->m_PosScript;
if (posScr)
PosName = posScr->m_Name;
else
PosName = CName("None");
if (m_CurInst >= 0 && m_Insts.Num() > m_CurInst)
{
cgc = &m_Insts[m_CurInst];
if (cgc->m_Mask == Type && cgc->m_LightMask == LightMask)
{
if (!pVP || !posScr || PosName == cgc->m_PosScriptName)
return m_CurInst;
}
}
m_dwFrame++;
int i;
for (i=0; i<m_Insts.Num(); i++)
{
cgc = &m_Insts[i];
if (cgc->m_Mask == Type && cgc->m_LightMask == LightMask && (!pVP || !posScr || PosName == cgc->m_PosScriptName))
{
m_CurInst = i;
return i;
}
}
SCGInstance cg;
cg.m_Mask = Type;
cg.m_LightMask = LightMask;
cg.m_BindConstants = NULL;
cg.m_BindVars = NULL;
cg.m_pHandle = 0;
cg.m_CGProgram = NULL;
cg.m_ParamsNoObj = NULL;
cg.m_MatrixNoObj = NULL;
cg.m_ParamsObj = NULL;
cg.m_MatrixObj = NULL;
if (Type & VPVST_CLIPPLANES3)
{
if (!cg.m_ParamsNoObj)
cg.m_ParamsNoObj = new TArray<SCGParam4f>;
SCGParam4f pr;
pr.m_nComponents = 1;
pr.m_Name = "ClipPlane";
SParamComp_ClipPlane p;
pr.m_Flags = PF_CANMERGED;
pr.m_Comps[0] = SParamComp::mfAdd(&p);
cg.m_ParamsNoObj->AddElem(pr);
}
if (Type & VPVST_TCMASK)
{
if (!cg.m_ParamsNoObj)
cg.m_ParamsNoObj = new TArray<SCGParam4f>;
int nm = VPVST_TCM0;
int ngol = VPVST_TCGOL0;
int ngrm = VPVST_TCGRM0;
int ngsm = VPVST_TCGSM0;
int ngnm = VPVST_TCGNM0;
for (int i=0; i<4; i++)
{
char str[128];
if (Type & (ngol<<i))
{
SCGParam4f pr;
pr.m_nComponents = 4;
pr.m_dwBind = 0;
sprintf(str, "MatrixTCG%d", i);
pr.m_Name = str;
SParamComp_MatrixTCG p;
pr.m_Flags = PF_CANMERGED;
p.m_Stage = i;
p.m_Row = 0;
pr.m_Comps[0] = SParamComp::mfAdd(&p);
cg.m_ParamsNoObj->AddElem(pr);
p.m_Row = 1;
pr.m_Comps[0] = SParamComp::mfAdd(&p);
cg.m_ParamsNoObj->AddElem(pr);
p.m_Row = 2;
pr.m_Comps[0] = SParamComp::mfAdd(&p);
cg.m_ParamsNoObj->AddElem(pr);
p.m_Row = 3;
pr.m_Comps[0] = SParamComp::mfAdd(&p);
cg.m_ParamsNoObj->AddElem(pr);
}
if (Type & ((ngrm|ngsm)<<i))
{
SCGParam4f pr;
pr.m_nComponents = 1;
pr.m_dwBind = 0;
pr.m_Name = "CameraPos";
SParamComp_OSCameraPos p;
pr.m_Flags = PF_CANMERGED;
pr.m_Comps[0] = SParamComp::mfAdd(&p);
cg.m_ParamsNoObj->AddElem(pr);
if (!cg.m_MatrixNoObj)
cg.m_MatrixNoObj = new TArray<SCGMatrix>;
SCGMatrix m;
m.m_eCGParamType = ECGP_Matr_View;
m.m_Name = "ModelView";
cg.m_MatrixNoObj->AddElem(m);
m.m_eCGParamType = ECGP_Matr_View_IT;
m.m_Name = "ModelViewIT";
cg.m_MatrixNoObj->AddElem(m);
}
if (Type & (ngnm<<i))
{
if (!cg.m_MatrixNoObj)
cg.m_MatrixNoObj = new TArray<SCGMatrix>;
SCGMatrix m;
m.m_eCGParamType = ECGP_Matr_View_IT;
m.m_Name = "ModelViewIT";
cg.m_MatrixNoObj->AddElem(m);
}
if (Type & (nm<<i))
{
SCGParam4f pr;
pr.m_nComponents = 4;
pr.m_dwBind = 0;
sprintf(str, "MatrixTCM%d", i);
pr.m_Name = str;
SParamComp_MatrixTCM p;
pr.m_Flags = PF_CANMERGED;
p.m_Stage = i;
p.m_Row = 0;
pr.m_Comps[0] = SParamComp::mfAdd(&p);
cg.m_ParamsNoObj->AddElem(pr);
p.m_Row = 1;
pr.m_Comps[0] = SParamComp::mfAdd(&p);
cg.m_ParamsNoObj->AddElem(pr);
p.m_Row = 2;
pr.m_Comps[0] = SParamComp::mfAdd(&p);
cg.m_ParamsNoObj->AddElem(pr);
p.m_Row = 3;
pr.m_Comps[0] = SParamComp::mfAdd(&p);
cg.m_ParamsNoObj->AddElem(pr);
}
}
}
if (pVP && posScr)
{
cg.m_PosScriptName = PosName;
if (cg.m_PosScriptName != m_PosScript->m_Name && pVP->m_ParamsNoObj.Num())
{
if (!cg.m_ParamsNoObj)
cg.m_ParamsNoObj = new TArray<SCGParam4f>;
for (int i=0; i<pVP->m_ParamsNoObj.Num(); i++)
{
cg.m_ParamsNoObj->AddElem(pVP->m_ParamsNoObj[i]);
cg.m_ParamsNoObj->Get(cg.m_ParamsNoObj->Num()-1).m_dwBind = 0;
}
cg.m_ParamsNoObj->Shrink();
}
if (cg.m_PosScriptName != m_PosScript->m_Name && pVP->m_ParamsObj.Num())
{
if (!cg.m_ParamsObj)
cg.m_ParamsObj = new TArray<SCGParam4f>;
for (int i=0; i<pVP->m_ParamsObj.Num(); i++)
{
cg.m_ParamsObj->AddElem(pVP->m_ParamsObj[i]);
cg.m_ParamsObj->Get(cg.m_ParamsObj->Num()-1).m_dwBind = 0;
}
cg.m_ParamsObj->Shrink();
}
}
if (cg.m_ParamsNoObj)
{
TArray<SCGParam4f> ObjP;
gRenDev->m_cEF.mfCheckObjectDependParams(cg.m_ParamsNoObj, &ObjP);
if (ObjP.Num())
{
cg.m_ParamsObj = new TArray<SCGParam4f>;
cg.m_ParamsObj->Copy(ObjP);
}
}
m_Insts.AddElem(cg);
m_CurInst = m_Insts.Num()-1;
return m_CurInst;
}
char *mfGetObjectCode(CGprogram cgPr)
{
const char *code = cgGetProgramString(cgPr, CG_COMPILED_PROGRAM);
size_t size = strlen(code)+1;
char *str = new char[size];
cryMemcpy(str, code, size);
return str;
}
char *mfLoadCG(const char *prog_text)
{
// NOTE: AMD64 port: find the 64-bit CG runtime
CGprofile pr = (CGprofile)m_CGProfileType;
char *Buf = fxReplaceInText((char *)prog_text, "vertout OUT", "vertout OUT = (vertout)0");
// make command for execution
FILE *fp = fopen("$$in.cg", "w");
if (!fp)
return NULL;
assert (*Buf);
fputs(Buf, fp);
fclose (fp);
char szCmdLine[512];
sprintf(szCmdLine, "fxc.exe /T %s /Zpr /DCGC=0 /Fc $$out.cg $$in.cg", pr == CG_PROFILE_VS_2_0 ? "vs_2_0" : pr == CG_PROFILE_VS_2_X ? "vs_2_a" : pr == CG_PROFILE_VS_3_0 ? "vs_3_0" : "vs_1_1");
if (m_EntryFunc.GetIndex())
{
strcat(szCmdLine, " /E ");
strcat(szCmdLine, m_EntryFunc.c_str());
}
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
si.dwX = 100;
si.dwY = 100;
si.dwFlags = STARTF_USEPOSITION;
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
if( !CreateProcess( NULL, // No module name (use command line).
szCmdLine, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
CREATE_NO_WINDOW, // No creation flags.
NULL, // Use parent's environment block.
NULL/*szFolderName*/, // Set starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
iLog->LogError("CreateProcess failed: %s", szCmdLine);
return NULL;
}
while (WAIT_OBJECT_0 != WaitForSingleObject (pi.hProcess, 10000))
iLog->LogWarning ("CG runtime takes forever to compile.. waiting.. (last error %d)", GetLastError());
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
fp = fopen("$$out.cg", "rb");
if (!fp)
{
Warning( 0,0,"HLSL compiler (fxc.exe) wasn't able to compile vertex shader '%s'", m_Name.c_str());
m_nFailed++;
mfSaveCGFile(Buf);
remove("$$in.cg");
if (Buf != prog_text)
delete [] Buf;
return NULL;
}
fseek(fp, 0, SEEK_END);
int size = ftell(fp);
fseek(fp, 0, SEEK_SET);
if (size < 20)
{
Warning( 0,0,"HLSL compiler (fxc.exe) wasn't able to compile vertex shader '%s'", m_Name.c_str());
m_nFailed++;
mfSaveCGFile(Buf);
remove("$$in.cg");
remove("$$out.cg");
if (Buf != prog_text)
delete [] Buf;
return NULL;
}
char *pBuf = new char[size+1];
fread(pBuf, sizeof(char), size, fp);
pBuf[size] = '\0';
fclose(fp);
remove("$$in.cg");
remove("$$out.cg");
if (CRenderer::CV_r_shaderssave == 2)
{
_chdir("c:\\MasterCD\\TestCG");
mfSaveCGFile(Buf);
_chdir("c:\\MasterCD");
}
if (Buf != prog_text)
delete [] Buf;
return pBuf;
}
LPD3DXBUFFER mfLoad(const char *prog_text)
{
// Load and create vertex shader
HRESULT hr;
LPD3DXBUFFER pCode;
LPD3DXBUFFER pBuffer = NULL;
hr = D3DXAssembleShader(prog_text, strlen(prog_text), NULL, NULL, 0, &pCode, &pBuffer);
if (FAILED(hr))
{
Warning( 0,0,"WARNING: CCGVProgram_D3D::mfLoad: Could not assemble vertex shader '%s' (%s)\n", m_Name.c_str(), gcpRendD3D->D3DError(hr));
if( pBuffer != NULL)
{
TCHAR* pstr;
TCHAR strOut[4096];
TCHAR* pstrOut;
// Need to replace \n with \r\n so edit box shows newlines properly
pstr = (TCHAR*)pBuffer->GetBufferPointer();
strOut[0] = '\0';
pstrOut = strOut;
for( int i = 0; i < 4096; i++ )
{
if( *pstr == '\n' )
*pstrOut++ = '\r';
*pstrOut = *pstr;
if( *pstr == '\0' )
break;
if( i == 4095 )
*pstrOut = '\0';
pstrOut++;
pstr++;
}
// remove any blank lines at the end
while( strOut[lstrlen(strOut) - 1] == '\n' || strOut[lstrlen(strOut) - 1] == '\r' )
{
strOut[lstrlen(strOut) - 1] = '\0';
}
Warning( 0,0,"WARNING: CCGVProgram_D3D::mfLoad: Shader script error (%s)\n", strOut);
SAFE_RELEASE(pBuffer);
}
}
if (pCode && !(m_Flags & VPFI_PRECACHEPHASE))
hr = gcpRendD3D->mfGetD3DDevice()->CreateVertexShader((DWORD*)pCode->GetBufferPointer(), (IDirect3DVertexShader9 **)&m_Insts[m_CurInst].m_pHandle);
if (FAILED(hr))
{
Warning( 0,0,"CCGVProgram_D3D::mfLoad: Could not create vertex shader '%s' (%s)\n", m_Name.c_str(), gcpRendD3D->D3DError(hr));
return NULL;
}
return pCode;
}
SCGBind *mfGetParameterBind(const char *Name)
{
CName nm = CName(Name, eFN_Add);
if (!m_Insts[m_CurInst].m_BindVars)
m_Insts[m_CurInst].m_BindVars = new TArray<SCGBind>;
int i;
for (i=0; i<m_Insts[m_CurInst].m_BindVars->Num(); i++)
{
if (nm == m_Insts[m_CurInst].m_BindVars->Get(i).m_Name)
return &m_Insts[m_CurInst].m_BindVars->Get(i);
}
return NULL;
}
void mfParameteri(SCGBind *ParamBind, const float *v)
{
int i;
if(!ParamBind)
return;
if (!ParamBind->m_dwBind || ParamBind->m_dwFrameCreated != m_dwFrame)
{
ParamBind->m_dwFrameCreated = m_dwFrame;
if (m_Insts[m_CurInst].m_BindVars)
{
for (i=0; i<m_Insts[m_CurInst].m_BindVars->Num(); i++)
{
SCGBind *p = &m_Insts[m_CurInst].m_BindVars->Get(i);
if (p->m_Name == ParamBind->m_Name)
{
ParamBind->m_dwBind = p->m_dwBind;
ParamBind->m_nBindComponents = p->m_nComponents;
if (!ParamBind->m_dwBind)
ParamBind->m_dwBind = 65536;
break;
}
}
if (i == m_Insts[m_CurInst].m_BindVars->Num())
ParamBind->m_dwBind = -1;
}
else
ParamBind->m_dwBind = -1;
if (ParamBind->m_dwBind == -1 && CRenderer::CV_r_shaderssave >= 2)
iLog->Log("Warning: couldn't find parameter %s for vertex shader %s (%x)", ParamBind->m_Name.c_str(), m_Name.c_str(), m_nMaskGen);
}
if ((int)ParamBind->m_dwBind == -1)
return;
int n;
int iparms[4];
if (ParamBind->m_dwBind == 65536)
n = 0;
else
n = ParamBind->m_dwBind;
if (m_CurParams[n][0] != v[0] || m_CurParams[n][1] != v[1] || m_CurParams[n][2] != v[2] || m_CurParams[n][3] != v[3])
{
m_CurParams[n][0] = v[0];
m_CurParams[n][1] = v[1];
m_CurParams[n][2] = v[2];
m_CurParams[n][3] = v[3];
iparms[0] = (int)v[0];
iparms[1] = (int)v[1];
iparms[2] = (int)v[2];
iparms[3] = (int)v[3];
gcpRendD3D->mfGetD3DDevice()->SetVertexShaderConstantI(n, iparms, 1);
}
v += 4;
}
void mfParameter(SCGBind *ParamBind, const float *v, int nComps)
{
if(!ParamBind)
{
return;
}
if (!ParamBind->m_dwBind || ParamBind->m_dwFrameCreated != m_dwFrame)
{
ParamBind->m_dwFrameCreated = m_dwFrame;
if (m_Insts[m_CurInst].m_BindVars)
{
int i;
for (i=0; i<m_Insts[m_CurInst].m_BindVars->Num(); i++)
{
SCGBind *p = &m_Insts[m_CurInst].m_BindVars->Get(i);
if (p->m_Name == ParamBind->m_Name)
{
assert(p->m_nComponents <= nComps);
ParamBind->m_dwBind = p->m_dwBind;
if (ParamBind->m_dwBind == 0)
ParamBind->m_dwBind = 65536;
ParamBind->m_nBindComponents = p->m_nComponents;
break;
}
}
if (i == m_Insts[m_CurInst].m_BindVars->Num())
ParamBind->m_dwBind = -1;
}
else
ParamBind->m_dwBind = -1;
if (ParamBind->m_dwBind == -1 && CRenderer::CV_r_shaderssave >= 2)
iLog->Log("Warning: couldn't find parameter %s for vertex shader %s (%x)", ParamBind->m_Name.c_str(), m_Name.c_str(), m_nMaskGen);
}
if (ParamBind->m_dwBind == -1)
return;
if (ParamBind->m_dwBind == 65536)
{
gcpRendD3D->mfGetD3DDevice()->SetVertexShaderConstantF(0, v, 4);
//memcpy(&m_CurParams[0][0], v, 4*4*sizeof(float));
}
else
{
for (int i=0; i<ParamBind->m_nBindComponents; i++)
{
int n = ParamBind->m_dwBind+i;
if (m_CurParams[n][0] != v[0] || m_CurParams[n][1] != v[1] || m_CurParams[n][2] != v[2] || m_CurParams[n][3] != v[3])
{
m_CurParams[n][0] = v[0];
m_CurParams[n][1] = v[1];
m_CurParams[n][2] = v[2];
m_CurParams[n][3] = v[3];
gcpRendD3D->mfGetD3DDevice()->SetVertexShaderConstantF(n, v, 1);
}
v += 4;
}
}
}
void mfParameter4i(SCGBind *ParamBind, const vec4_t v)
{
mfParameteri(ParamBind, v);
}
void mfParameter4f(SCGBind *ParamBind, const vec4_t v)
{
mfParameter(ParamBind, v, 1);
}
void mfParameter4f(const char *Name, const float *v)
{
SCGBind *pBind = mfGetParameterBind(Name);
if (pBind)
mfParameter4f(pBind, v);
}
void mfParameterStateMatrix(SCGMatrix *ParamBind)
{
static int sFrame;
static int sFlags;
CD3D9Renderer *r = gcpRendD3D;
LPDIRECT3DDEVICE9 dv = r->mfGetD3DDevice();
D3DXMATRIXA16 matWorldViewProj;
switch(ParamBind->m_eCGParamType)
{
case ECGP_Matr_ViewProj:
{
if (!(r->m_RP.m_ObjFlags & FOB_TRANS_MASK))
{
if (r->m_RP.m_PersFlags & RBPF_WASWORLDSPACE)
break;
r->m_RP.m_PersFlags |= RBPF_WASWORLDSPACE;
m_FrameObj = -1;
}
else
{
if (r->m_RP.m_PersFlags & RBPF_WASWORLDSPACE)
m_FrameObj = -1;
r->m_RP.m_PersFlags &= ~RBPF_WASWORLDSPACE;
}
if (sFrame != r->m_RP.m_FrameObject)
{
sFrame = r->m_RP.m_FrameObject;
if (r->m_RP.m_ClipPlaneEnabled == 2)
{
// Transform clip plane to clip space
Plane p;
p.n = r->m_RP.m_CurClipPlane.m_Normal;
p.d = r->m_RP.m_CurClipPlane.m_Dist;
Plane pTr;
pTr = TransformPlane2(r->m_InvCameraProjMatrix, p);
r->m_pd3dDevice->SetClipPlane(0, &pTr.n[0]);
r->m_RP.m_ClipPlaneWasOverrided = 2;
}
}
if (m_FrameObj != r->m_RP.m_FrameObject)
{
m_FrameObj = r->m_RP.m_FrameObject;
mathMatrixTranspose((float *)&matWorldViewProj, r->m_RP.m_pCurObject->GetVPMatrix().GetData(), g_CpuFlags);
mfParameter(ParamBind, (float *)&matWorldViewProj, 4);
}
}
break;
case ECGP_Matr_World:
{
D3DXMatrixIdentity(&matWorldViewProj);
mfParameter(ParamBind, &matWorldViewProj(0, 0), 4);
}
break;
case ECGP_Matr_View_IT:
{
D3DXMatrixMultiply((D3DXMATRIXA16 *)&r->m_ViewMatrix(0,0), (D3DXMATRIXA16 *)&r->m_RP.m_pCurObject->m_Matrix(0,0), (D3DXMATRIXA16 *)&r->m_CameraMatrix(0,0));
D3DXMATRIXA16 *matView = (D3DXMATRIXA16 *)r->m_ViewMatrix.GetData();
D3DXMatrixInverse(&matWorldViewProj, NULL, matView);
mfParameter(ParamBind, &matWorldViewProj(0, 0), 4);
}
break;
case ECGP_Matr_View:
{
D3DXMatrixMultiply((D3DXMATRIXA16 *)&r->m_ViewMatrix(0,0), (D3DXMATRIXA16 *)&r->m_RP.m_pCurObject->m_Matrix(0,0), (D3DXMATRIXA16 *)&r->m_CameraMatrix(0,0));
D3DXMATRIXA16 *matView = (D3DXMATRIXA16 *)r->m_ViewMatrix.GetData();
D3DXMatrixTranspose(&matWorldViewProj, matView);
mfParameter(ParamBind, &matWorldViewProj(0, 0), 4);
}
break;
case ECGP_Matr_View_I:
{
D3DXMatrixMultiply((D3DXMATRIXA16 *)&r->m_ViewMatrix(0,0), (D3DXMATRIXA16 *)&r->m_RP.m_pCurObject->m_Matrix(0,0), (D3DXMATRIXA16 *)&r->m_CameraMatrix(0,0));
D3DXMATRIXA16 *matView = (D3DXMATRIXA16 *)r->m_ViewMatrix.GetData();
D3DXMatrixInverse(&matWorldViewProj, NULL, matView);
D3DXMatrixTranspose(&matWorldViewProj, &matWorldViewProj);
mfParameter(ParamBind, &matWorldViewProj(0, 0), 4);
}
break;
case ECGP_Matr_View_T:
{
D3DXMatrixMultiply((D3DXMATRIXA16 *)&r->m_ViewMatrix(0,0), (D3DXMATRIXA16 *)&r->m_RP.m_pCurObject->m_Matrix(0,0), (D3DXMATRIXA16 *)&r->m_CameraMatrix(0,0));
D3DXMATRIXA16 *matView = (D3DXMATRIXA16 *)r->m_ViewMatrix.GetData();
mfParameter(ParamBind, (float *)matView, 4);
}
break;
case ECGP_Matr_Obj:
{
Matrix44 *m = &gRenDev->m_RP.m_pCurObject->m_Matrix;
mfParameter(ParamBind, m->GetData(), 4);
}
break;
case ECGP_Matr_Obj_I:
{
Matrix44 *m = &gRenDev->m_RP.m_pCurObject->GetInvMatrix();
mfParameter(ParamBind, m->GetData(), 4);
}
break;
default:
Warning( 0,0,"Unknown matrix state type %d int CG program '%s'", m_Name.c_str());
assert(0);
}
}
void mfDelInst()
{
if(m_Insts[m_CurInst].m_CGProgram && (int)m_Insts[m_CurInst].m_CGProgram != -1)
{
if (m_Insts[m_CurInst].m_BindConstants)
delete m_Insts[m_CurInst].m_BindConstants;
if (m_Insts[m_CurInst].m_BindVars)
delete m_Insts[m_CurInst].m_BindVars;
if (m_Insts[m_CurInst].m_ParamsNoObj)
delete m_Insts[m_CurInst].m_ParamsNoObj;
if (m_Insts[m_CurInst].m_ParamsObj)
delete m_Insts[m_CurInst].m_ParamsObj;
if (m_Insts[m_CurInst].m_MatrixNoObj)
delete m_Insts[m_CurInst].m_MatrixNoObj;
if (m_Insts[m_CurInst].m_MatrixObj)
delete m_Insts[m_CurInst].m_MatrixObj;
IDirect3DVertexShader9 *pVS = (IDirect3DVertexShader9 *)m_Insts[m_CurInst].m_pHandle;
if (pVS)
{
pVS->Release();
m_Insts[m_CurInst].m_pHandle = NULL;
}
}
m_Insts[m_CurInst].m_CGProgram = NULL;
}
bool mfIsValid(int Num) const { return (m_Insts[Num].m_CGProgram != NULL); }
SCGScript *mfGenerateScriptVP(CVProgram *pPosVP);
char *mfGenerateTCScript(char *Script, int nt);
void mfCompileVertAttributes(char *scr, SShader *ef);
void mfSetVariables(TArray<SCGParam4f>* Vars);
void mfPrecacheLights(int nMask);
public:
char *mfCreateAdditionalVP(CVProgram *pPosVP);
void mfCompileParam4f(char *scr, SShader *ef, TArray<SCGParam4f> *Params);
void mfCompileParamStateMatrix(char *scr, SShader *ef, TArray<SCGMatrix> *Params);
bool mfActivate(CVProgram *pPosVP);
void mfConstructFX(std::vector<SFXStruct>& Structs, std::vector<SPair>& Macros, char *entryFunc);
void mfAddFXParameter(SFXParam *pr, const char *ParamName, SShader *ef);
bool mfGetFXParamNameByID(int nParam, char *ParamName);
public:
virtual ~CCGVProgram_D3D();
virtual void Release();
virtual bool mfCompile(char *scr);
virtual bool mfSet(bool bStat, SShaderPassHW *slw=NULL, int nSetPointers=1);
virtual void mfSetVariables(bool bObj, TArray<SCGParam4f>* Vars);
virtual void mfReset();
virtual void mfPrecache();
virtual bool mfHasPointer(ESrcPointer ePtr);
virtual void mfGatherFXParameters(const char *buf, SShaderPassHW *pSHPass, std::vector<SFXParam>& Params, std::vector<SFXSampler>& Samplers, std::vector<SFXTexture>& Textures, SShader *ef);
virtual void mfPostLoad();
virtual int mfVertexFormat(bool &bUseTangents, bool &bUseLM);
void mfSetStateMatrices()
{
//PROFILE_FRAME(Shader_VShadersMatr);
for (int i=0; i<m_MatrixObj.Num(); i++)
{
SCGMatrix *tm = &m_MatrixObj[i];
mfParameterStateMatrix(tm);
}
if (m_Insts[m_CurInst].m_MatrixObj)
{
for (int i=0; i<m_Insts[m_CurInst].m_MatrixObj->Num(); i++)
{
SCGMatrix *tm = &m_Insts[m_CurInst].m_MatrixObj->Get(i);
mfParameterStateMatrix(tm);
}
}
}
static int m_nResetDeviceFrame;
static void mfSetGlobalParams();
static SCGScript *mfAddNewScript(const char *Name, const char *Script)
{
int i;
if (Name)
{
CName nm = CName(Name);
if (nm.GetIndex())
{
for (i=0; i<m_CGScripts.Num(); i++)
{
SCGScript *scr = m_CGScripts[i];
if (!scr || !scr->m_Name.GetIndex())
continue;
if (nm == scr->m_Name)
{
if (!Script || stricmp(Script, scr->m_Script) == 0)
return scr;
delete [] scr->m_Script;
break;
}
}
}
}
if (!Script)
{
if (Name)
Warning( 0,0,"Error: CCGVProgram_GL::mfAddNewScript: Couldn't find CG script for name '%s'", Name);
return NULL;
}
SCGScript *scr = new SCGScript;
if (Name)
scr->m_Name = CName(Name, eFN_Add);
size_t len = strlen(Script)+1;
scr->m_Script = new char[len];
strcpy(scr->m_Script, Script);
if (Name)
m_CGScripts.AddElem(scr);
return scr;
}
static void mfDeleteSharedScripts()
{
int i;
for (i=0; i<m_CGScripts.Num(); i++)
{
SCGScript *scr = m_CGScripts[i];
if (!scr)
continue;
SAFE_DELETE_ARRAY(scr->m_Script);
delete scr;
m_CGScripts[i] = NULL;
}
}
static TArray<SCGScript *> m_CGScripts;
static vec4_t m_CurParams[256];
};
#endif // __D3DCGVPROGRAMS_H__

View File

@@ -0,0 +1,194 @@
#ifndef D3DCUBEMAPS_H
#define D3DCUBEMAPS_H
struct SSingleLight
{
typedef byte Type;
int components;
int format;
SSingleLight(float _power) :
components(3), format(D3DFMT_X8R8G8B8), power(_power) {}
void operator() (const Vec3d& v, Type * t)
{
float z = v[2] > 0 ? v[2] : 0;
z = cry_powf(z, power);
t[0] = (Type)(z * 255.0f);
t[1] = (Type)(z * 255.0f);
t[2] = (Type)(z * 255.0f);
}
float power;
};
struct SNormalizeVector
{
typedef byte Type;
int components;
int format;
SNormalizeVector() : components(4), format(D3DFMT_X8R8G8B8) {}
void operator() (const Vec3d & v, Type * t)
{
Vec3d v2 = v;
v2 += Vec3d(1.0f,1.0f,1.0f);
t[2] = (Type)(v2[0] * 127.0f);
t[1] = (Type)(v2[1] * 127.0f);
t[0] = (Type)(v2[2] * 127.0f);
}
};
// make a cube map from a functor
template <class FunctionOfDirection> void MakeCubeMap(FunctionOfDirection & f, LPDIRECT3DCUBETEXTURE9 pCubeTexture, int size, bool bMips)
{
typedef typename FunctionOfDirection::Type Type;
int components = f.components;
int format = f.format;
Type * ip;
int dwMipmaps = pCubeTexture->GetLevelCount();
int dwLevel = 0;
while (true)
{
float offset = .5;
float delta = 1;
float halfsize = size/2.f;
Vec3d v;
D3DLOCKED_RECT Locked;
D3DXVECTOR3 Normal;
D3DSURFACE_DESC ddsdDesc;
// positive x image
{
pCubeTexture->GetLevelDesc(dwLevel, &ddsdDesc);
pCubeTexture->LockRect((D3DCUBEMAP_FACES)0, dwLevel, &Locked, NULL, 0);
Type* pBits = (Type*)(Locked.pBits);
ip = pBits;
for(int j = 0; j < size; j++)
{
for(int i=0; i < size; i++)
{
v[2] = -(i*delta + offset - halfsize);
v[1] = -(j*delta + offset - halfsize);
v[0] = halfsize;
v.Normalize();
f(v, ip);
ip += components;
}
}
pCubeTexture->UnlockRect((D3DCUBEMAP_FACES)0, dwLevel);
}
// negative x image
{
pCubeTexture->GetLevelDesc(dwLevel, &ddsdDesc);
pCubeTexture->LockRect((D3DCUBEMAP_FACES)1, dwLevel, &Locked, NULL, 0);
Type* pBits = (Type*)(Locked.pBits);
ip = pBits;
for(int j = 0; j < size; j++)
{
for(int i=0; i < size; i++)
{
v[2] = (i*delta + offset - halfsize);
v[1] = -(j*delta + offset - halfsize);
v[0] = -halfsize;
v.Normalize();
f(v, ip);
ip += components;
}
}
pCubeTexture->UnlockRect((D3DCUBEMAP_FACES)1, dwLevel);
}
// positive y image
{
pCubeTexture->GetLevelDesc(dwLevel, &ddsdDesc);
pCubeTexture->LockRect((D3DCUBEMAP_FACES)2, dwLevel, &Locked, NULL, 0);
Type* pBits = (Type*)(Locked.pBits);
ip = pBits;
for(int j = 0; j < size; j++)
{
for(int i=0; i < size; i++)
{
v[0] = (i*delta + offset - halfsize);
v[2] = (j*delta + offset - halfsize);
v[1] = halfsize;
v.Normalize();
f(v, ip);
ip += components;
}
}
pCubeTexture->UnlockRect((D3DCUBEMAP_FACES)2, dwLevel);
}
// negative y image
{
pCubeTexture->GetLevelDesc(dwLevel, &ddsdDesc);
pCubeTexture->LockRect((D3DCUBEMAP_FACES)3, dwLevel, &Locked, NULL, 0);
Type* pBits = (Type*)(Locked.pBits);
ip = pBits;
for(int j = 0; j < size; j++)
{
for(int i=0; i < size; i++)
{
v[0] = (i*delta + offset - halfsize);
v[2] = -(j*delta + offset - halfsize);
v[1] = -halfsize;
v.Normalize();
f(v, ip);
ip += components;
}
}
pCubeTexture->UnlockRect((D3DCUBEMAP_FACES)3, dwLevel);
}
// positive z image
{
pCubeTexture->GetLevelDesc(dwLevel, &ddsdDesc);
pCubeTexture->LockRect((D3DCUBEMAP_FACES)4, dwLevel, &Locked, NULL, 0);
Type* pBits = (Type*)(Locked.pBits);
ip = pBits;
for(int j = 0; j < size; j++)
{
for(int i=0; i < size; i++)
{
v[0] = (i*delta + offset - halfsize);
v[1] = -(j*delta + offset - halfsize);
v[2] = halfsize;
v.Normalize();
f(v, ip);
ip += components;
}
}
pCubeTexture->UnlockRect((D3DCUBEMAP_FACES)4, dwLevel);
}
// negative z image
{
pCubeTexture->GetLevelDesc(dwLevel, &ddsdDesc);
pCubeTexture->LockRect((D3DCUBEMAP_FACES)5, dwLevel, &Locked, NULL, 0);
Type* pBits = (Type*)(Locked.pBits);
ip = pBits;
for(int j = 0; j < size; j++)
{
for(int i=0; i < size; i++)
{
v[0] = -(i*delta + offset - halfsize);
v[1] = -(j*delta + offset - halfsize);
v[2] = -halfsize;
v.Normalize();
f(v, ip);
ip += components;
}
}
pCubeTexture->UnlockRect((D3DCUBEMAP_FACES)5, dwLevel);
}
size >>= 1;
if (!bMips || !size)
break;
dwLevel++;
if (dwLevel >= dwMipmaps)
break;
}
}
#endif

View File

@@ -0,0 +1,983 @@
#include "RenderPCH.h"
#include "DriverD3D9.h"
//-----------------------------------------------------------------------------
// Name: ColorChannelBits
// Desc: Returns the number of color channel bits in the specified D3DFORMAT
//-----------------------------------------------------------------------------
UINT ColorChannelBits( D3DFORMAT fmt )
{
switch( fmt )
{
case D3DFMT_R8G8B8:
return 8;
case D3DFMT_A8R8G8B8:
return 8;
case D3DFMT_X8R8G8B8:
return 8;
case D3DFMT_R5G6B5:
return 5;
case D3DFMT_X1R5G5B5:
return 5;
case D3DFMT_A1R5G5B5:
return 5;
case D3DFMT_A4R4G4B4:
return 4;
case D3DFMT_R3G3B2:
return 2;
case D3DFMT_A8R3G3B2:
return 2;
case D3DFMT_X4R4G4B4:
return 4;
case D3DFMT_A2B10G10R10:
return 10;
case D3DFMT_A2R10G10B10:
return 10;
default:
return 0;
}
}
//-----------------------------------------------------------------------------
// Name: ColorBits
// Desc: Returns the number of color bits in the specified D3DFORMAT
//-----------------------------------------------------------------------------
UINT ColorBits( D3DFORMAT fmt )
{
switch( fmt )
{
case D3DFMT_R8G8B8:
return 24;
case D3DFMT_A8R8G8B8:
return 32;
case D3DFMT_X8R8G8B8:
return 24;
case D3DFMT_R5G6B5:
return 16;
case D3DFMT_X1R5G5B5:
return 16;
case D3DFMT_A1R5G5B5:
return 16;
case D3DFMT_A4R4G4B4:
return 16;
case D3DFMT_R3G3B2:
return 8;
case D3DFMT_A8R3G3B2:
return 16;
case D3DFMT_X4R4G4B4:
return 16;
case D3DFMT_A2B10G10R10:
return 32;
case D3DFMT_A2R10G10B10:
return 32;
default:
return 0;
}
}
//-----------------------------------------------------------------------------
// Name: AlphaChannelBits
// Desc: Returns the number of alpha channel bits in the specified D3DFORMAT
//-----------------------------------------------------------------------------
static UINT AlphaChannelBits( D3DFORMAT fmt )
{
switch( fmt )
{
case D3DFMT_R8G8B8:
return 0;
case D3DFMT_A8R8G8B8:
return 8;
case D3DFMT_X8R8G8B8:
return 0;
case D3DFMT_R5G6B5:
return 0;
case D3DFMT_X1R5G5B5:
return 0;
case D3DFMT_A1R5G5B5:
return 1;
case D3DFMT_A4R4G4B4:
return 4;
case D3DFMT_R3G3B2:
return 0;
case D3DFMT_A8R3G3B2:
return 8;
case D3DFMT_X4R4G4B4:
return 0;
case D3DFMT_A2B10G10R10:
return 2;
case D3DFMT_A2R10G10B10:
return 2;
default:
return 0;
}
}
//-----------------------------------------------------------------------------
// Name: DepthBits
// Desc: Returns the number of depth bits in the specified D3DFORMAT
//-----------------------------------------------------------------------------
static UINT DepthBits( D3DFORMAT fmt )
{
switch( fmt )
{
case D3DFMT_D16:
return 16;
case D3DFMT_D15S1:
return 15;
case D3DFMT_D24X8:
return 24;
case D3DFMT_D24S8:
return 24;
case D3DFMT_D24X4S4:
return 24;
case D3DFMT_D32:
return 32;
default:
return 0;
}
}
//-----------------------------------------------------------------------------
// Name: StencilBits
// Desc: Returns the number of stencil bits in the specified D3DFORMAT
//-----------------------------------------------------------------------------
static UINT StencilBits( D3DFORMAT fmt )
{
switch( fmt )
{
case D3DFMT_D16:
return 0;
case D3DFMT_D15S1:
return 1;
case D3DFMT_D24X8:
return 0;
case D3DFMT_D24S8:
return 8;
case D3DFMT_D24X4S4:
return 4;
case D3DFMT_D32:
return 0;
default:
return 0;
}
}
//-----------------------------------------------------------------------------
// Name: D3DAdapterInfo destructor
// Desc:
//-----------------------------------------------------------------------------
D3DAdapterInfo::~D3DAdapterInfo( void )
{
if( pDisplayModeList != NULL )
delete pDisplayModeList;
if( pDeviceInfoList != NULL )
{
for(int idi=0; idi<pDeviceInfoList->Num(); idi++)
{
delete pDeviceInfoList->Get(idi);
}
delete pDeviceInfoList;
}
}
//-----------------------------------------------------------------------------
// Name: D3DDeviceInfo destructor
// Desc:
//-----------------------------------------------------------------------------
D3DDeviceInfo::~D3DDeviceInfo( void )
{
if( pDeviceComboList != NULL )
{
for(int idc=0; idc<pDeviceComboList->Num(); idc++)
{
delete pDeviceComboList->Get(idc);
}
delete pDeviceComboList;
}
}
//-----------------------------------------------------------------------------
// Name: D3DDeviceCombo destructor
// Desc:
//-----------------------------------------------------------------------------
D3DDeviceCombo::~D3DDeviceCombo( void )
{
if( pDepthStencilFormatList != NULL )
delete pDepthStencilFormatList;
if( pMultiSampleTypeList != NULL )
delete pMultiSampleTypeList;
if( pMultiSampleQualityList != NULL )
delete pMultiSampleQualityList;
if( pDSMSConflictList != NULL )
delete pDSMSConflictList;
if( pVertexProcessingTypeList != NULL )
delete pVertexProcessingTypeList;
if( pPresentIntervalList != NULL )
delete pPresentIntervalList;
}
//-----------------------------------------------------------------------------
// Name: CD3DEnumeration constructor
// Desc:
//-----------------------------------------------------------------------------
CD3DEnumeration::CD3DEnumeration()
{
m_pAdapterInfoList = NULL;
m_pAllowedAdapterFormatList = NULL;
AppMinFullscreenWidth = 640;
AppMinFullscreenHeight = 480;
AppMinColorChannelBits = 5;
AppMinAlphaChannelBits = 0;
AppMinDepthBits = 15;
AppMinStencilBits = 0;
AppUsesDepthBuffer = true;
AppUsesMixedVP = false;
AppRequiresWindowed = false;
AppRequiresFullscreen = false;
}
//-----------------------------------------------------------------------------
// Name: CD3DEnumeration destructor
// Desc:
//-----------------------------------------------------------------------------
CD3DEnumeration::~CD3DEnumeration()
{
if( m_pAdapterInfoList != NULL )
{
for(int iai=0; iai < m_pAdapterInfoList->Num(); iai++)
{
delete m_pAdapterInfoList->Get(iai);
}
delete m_pAdapterInfoList;
}
SAFE_DELETE( m_pAllowedAdapterFormatList );
}
//-----------------------------------------------------------------------------
// Name: SortModesCallback
// Desc: Used to sort D3DDISPLAYMODEs
//-----------------------------------------------------------------------------
static int __cdecl SortModesCallback( const void* arg1, const void* arg2 )
{
D3DDISPLAYMODE* pdm1 = (D3DDISPLAYMODE*)arg1;
D3DDISPLAYMODE* pdm2 = (D3DDISPLAYMODE*)arg2;
if (pdm1->Width > pdm2->Width)
return 1;
if (pdm1->Width < pdm2->Width)
return -1;
if (pdm1->Height > pdm2->Height)
return 1;
if (pdm1->Height < pdm2->Height)
return -1;
if (pdm1->Format > pdm2->Format)
return 1;
if (pdm1->Format < pdm2->Format)
return -1;
if (pdm1->RefreshRate > pdm2->RefreshRate)
return 1;
if (pdm1->RefreshRate < pdm2->RefreshRate)
return -1;
return 0;
}
//-----------------------------------------------------------------------------
// Name: Enumerate
// Desc: Enumerates available D3D adapters, devices, modes, etc.
//-----------------------------------------------------------------------------
HRESULT CD3DEnumeration::Enumerate()
{
HRESULT hr;
TArray<D3DFORMAT> adapterFormatList;
if( m_pD3D == NULL )
return E_FAIL;
m_pAdapterInfoList = new TArray<D3DAdapterInfo *>;
if( m_pAdapterInfoList == NULL )
return E_OUTOFMEMORY;
m_pAllowedAdapterFormatList = new TArray<D3DFORMAT>;
if( m_pAllowedAdapterFormatList == NULL )
return E_OUTOFMEMORY;
m_pAllowedAdapterFormatList->AddElem(D3DFMT_X8R8G8B8);
m_pAllowedAdapterFormatList->AddElem(D3DFMT_X1R5G5B5);
m_pAllowedAdapterFormatList->AddElem(D3DFMT_R5G6B5);
m_pAllowedAdapterFormatList->AddElem(D3DFMT_A2R10G10B10);
D3DAdapterInfo* pAdapterInfo = NULL;
UINT numAdapters = m_pD3D->GetAdapterCount();
for (UINT adapterOrdinal=0; adapterOrdinal<numAdapters; adapterOrdinal++)
{
pAdapterInfo = new D3DAdapterInfo;
if( pAdapterInfo == NULL )
return E_OUTOFMEMORY;
pAdapterInfo->m_MaxWidth = 0;
pAdapterInfo->m_MaxHeight = 0;
pAdapterInfo->pDisplayModeList = new TArray<D3DDISPLAYMODE>;
pAdapterInfo->pDeviceInfoList = new TArray<D3DDeviceInfo *>;
if(pAdapterInfo->pDisplayModeList == NULL || pAdapterInfo->pDeviceInfoList == NULL)
{
delete pAdapterInfo;
return E_OUTOFMEMORY;
}
pAdapterInfo->AdapterOrdinal = adapterOrdinal;
m_pD3D->GetAdapterIdentifier(adapterOrdinal, 0, &pAdapterInfo->AdapterIdentifier);
// Get list of all display modes on this adapter.
// Also build a temporary list of all display adapter formats.
adapterFormatList.Free();
for(int iaaf=0; iaaf<m_pAllowedAdapterFormatList->Num(); iaaf++)
{
D3DFORMAT allowedAdapterFormat = m_pAllowedAdapterFormatList->Get(iaaf);
UINT numAdapterModes = m_pD3D->GetAdapterModeCount( adapterOrdinal, allowedAdapterFormat );
for (UINT mode=0; mode<numAdapterModes; mode++)
{
D3DDISPLAYMODE displayMode;
m_pD3D->EnumAdapterModes( adapterOrdinal, allowedAdapterFormat, mode, &displayMode );
if( displayMode.Width < AppMinFullscreenWidth || displayMode.Height < AppMinFullscreenHeight || ColorChannelBits(displayMode.Format) < AppMinColorChannelBits )
continue;
pAdapterInfo->m_MaxWidth = max(pAdapterInfo->m_MaxWidth, displayMode.Width);
pAdapterInfo->m_MaxHeight = max(pAdapterInfo->m_MaxHeight, displayMode.Height);
pAdapterInfo->pDisplayModeList->AddElem(displayMode);
if(adapterFormatList.Find(displayMode.Format) < 0)
adapterFormatList.AddElem(displayMode.Format);
}
}
// Sort displaymode list
qsort((void *)&pAdapterInfo->pDisplayModeList->Get(0), pAdapterInfo->pDisplayModeList->Num(), sizeof(D3DDISPLAYMODE), SortModesCallback );
// Get info for each device on this adapter
if(FAILED(hr = EnumerateDevices( pAdapterInfo, &adapterFormatList)))
{
delete pAdapterInfo;
return hr;
}
// If at least one device on this adapter is available and compatible
// with the app, add the adapterInfo to the list
if (pAdapterInfo->pDeviceInfoList->Num() == 0)
delete pAdapterInfo;
else
m_pAdapterInfoList->AddElem(pAdapterInfo);
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: EnumerateDevices
// Desc: Enumerates D3D devices for a particular adapter.
//-----------------------------------------------------------------------------
HRESULT CD3DEnumeration::EnumerateDevices(D3DAdapterInfo* pAdapterInfo, TArray<D3DFORMAT> *pAdapterFormatList)
{
const D3DDEVTYPE devTypeArray[] = { D3DDEVTYPE_HAL, D3DDEVTYPE_SW, D3DDEVTYPE_REF };
const UINT devTypeArrayCount = sizeof(devTypeArray) / sizeof(devTypeArray[0]);
HRESULT hr;
D3DDeviceInfo* pDeviceInfo = NULL;
for(UINT idt=0; idt<devTypeArrayCount; idt++)
{
pDeviceInfo = new D3DDeviceInfo;
if( pDeviceInfo == NULL )
return E_OUTOFMEMORY;
pDeviceInfo->pDeviceComboList = new TArray<D3DDeviceCombo *>;
if( pDeviceInfo->pDeviceComboList == NULL )
{
delete pDeviceInfo;
return E_OUTOFMEMORY;
}
pDeviceInfo->AdapterOrdinal = pAdapterInfo->AdapterOrdinal;
pDeviceInfo->DevType = devTypeArray[idt];
if( FAILED( m_pD3D->GetDeviceCaps(pAdapterInfo->AdapterOrdinal, pDeviceInfo->DevType, &pDeviceInfo->Caps)))
{
delete pDeviceInfo;
continue;
}
// Get info for each devicecombo on this device
if(FAILED(hr = EnumerateDeviceCombos(pDeviceInfo, pAdapterFormatList)))
{
delete pDeviceInfo;
return hr;
}
// If at least one devicecombo for this device is found,
// add the deviceInfo to the list
if (pDeviceInfo->pDeviceComboList->Num() == 0)
{
delete pDeviceInfo;
continue;
}
pAdapterInfo->pDeviceInfoList->AddElem(pDeviceInfo);
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: EnumerateDeviceCombos
// Desc: Enumerates DeviceCombos for a particular device.
//-----------------------------------------------------------------------------
HRESULT CD3DEnumeration::EnumerateDeviceCombos(D3DDeviceInfo* pDeviceInfo, TArray<D3DFORMAT> *pAdapterFormatList)
{
const D3DFORMAT backBufferFormatArray[] =
{ D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_A2R10G10B10,
D3DFMT_R5G6B5, D3DFMT_A1R5G5B5, D3DFMT_X1R5G5B5 };
const UINT backBufferFormatArrayCount = sizeof(backBufferFormatArray) / sizeof(backBufferFormatArray[0]);
bool isWindowedArray[] = { false, true };
// See which adapter formats are supported by this device
D3DFORMAT adapterFormat;
for(int iaf=0; iaf<pAdapterFormatList->Num(); iaf++)
{
adapterFormat = pAdapterFormatList->Get(iaf);
D3DFORMAT backBufferFormat;
for(UINT ibbf=0; ibbf<backBufferFormatArrayCount; ibbf++)
{
backBufferFormat = backBufferFormatArray[ibbf];
if (AlphaChannelBits(backBufferFormat) < AppMinAlphaChannelBits)
continue;
bool isWindowed;
for( UINT iiw=0; iiw<2; iiw++)
{
isWindowed = isWindowedArray[iiw];
if (!isWindowed && AppRequiresWindowed)
continue;
if (isWindowed && AppRequiresFullscreen)
continue;
if (FAILED(m_pD3D->CheckDeviceType(pDeviceInfo->AdapterOrdinal, pDeviceInfo->DevType, adapterFormat, backBufferFormat, isWindowed)))
continue;
// At this point, we have an adapter/device/adapterformat/backbufferformat/iswindowed
// DeviceCombo that is supported by the system. We still need to confirm that it's
// compatible with the app, and find one or more suitable depth/stencil buffer format,
// multisample type, vertex processing type, and present interval.
D3DDeviceCombo* pDeviceCombo = NULL;
pDeviceCombo = new D3DDeviceCombo;
if( pDeviceCombo == NULL )
return E_OUTOFMEMORY;
pDeviceCombo->pDepthStencilFormatList = new TArray<D3DFORMAT>;
pDeviceCombo->pMultiSampleTypeList = new TArray<D3DMULTISAMPLE_TYPE>;
pDeviceCombo->pMultiSampleQualityList = new TArray<DWORD>;
pDeviceCombo->pDSMSConflictList = new TArray<D3DDSMSConflict>;
pDeviceCombo->pVertexProcessingTypeList = new TArray<VertexProcessingType>;
pDeviceCombo->pPresentIntervalList = new TArray<UINT>;
if( pDeviceCombo->pDepthStencilFormatList == NULL ||
pDeviceCombo->pMultiSampleTypeList == NULL ||
pDeviceCombo->pMultiSampleQualityList == NULL ||
pDeviceCombo->pDSMSConflictList == NULL ||
pDeviceCombo->pVertexProcessingTypeList == NULL ||
pDeviceCombo->pPresentIntervalList == NULL )
{
delete pDeviceCombo;
return E_OUTOFMEMORY;
}
pDeviceCombo->AdapterOrdinal = pDeviceInfo->AdapterOrdinal;
pDeviceCombo->DevType = pDeviceInfo->DevType;
pDeviceCombo->AdapterFormat = adapterFormat;
pDeviceCombo->BackBufferFormat = backBufferFormat;
pDeviceCombo->IsWindowed = isWindowed;
if (AppUsesDepthBuffer)
{
BuildDepthStencilFormatList(pDeviceCombo);
if (pDeviceCombo->pDepthStencilFormatList->Num() == 0)
{
delete pDeviceCombo;
continue;
}
}
BuildMultiSampleTypeList(pDeviceCombo);
if (pDeviceCombo->pMultiSampleTypeList->Num() == 0)
{
delete pDeviceCombo;
continue;
}
BuildDSMSConflictList(pDeviceCombo);
BuildVertexProcessingTypeList(pDeviceInfo, pDeviceCombo);
if (pDeviceCombo->pVertexProcessingTypeList->Num() == 0)
{
delete pDeviceCombo;
continue;
}
BuildPresentIntervalList(pDeviceInfo, pDeviceCombo);
pDeviceInfo->pDeviceComboList->AddElem(pDeviceCombo);
}
}
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: BuildDepthStencilFormatList
// Desc: Adds all depth/stencil formats that are compatible with the device
// and app to the given D3DDeviceCombo.
//-----------------------------------------------------------------------------
void CD3DEnumeration::BuildDepthStencilFormatList( D3DDeviceCombo* pDeviceCombo )
{
const D3DFORMAT depthStencilFormatArray[] =
{
D3DFMT_D16,
D3DFMT_D15S1,
D3DFMT_D24X8,
D3DFMT_D24S8,
D3DFMT_D24X4S4,
D3DFMT_D32,
};
const UINT depthStencilFormatArrayCount = sizeof(depthStencilFormatArray) /
sizeof(depthStencilFormatArray[0]);
D3DFORMAT depthStencilFmt;
for(UINT idsf=0; idsf<depthStencilFormatArrayCount; idsf++)
{
depthStencilFmt = depthStencilFormatArray[idsf];
if (DepthBits(depthStencilFmt) < AppMinDepthBits)
continue;
if (StencilBits(depthStencilFmt) < AppMinStencilBits)
continue;
if (SUCCEEDED(m_pD3D->CheckDeviceFormat(pDeviceCombo->AdapterOrdinal, pDeviceCombo->DevType, pDeviceCombo->AdapterFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFmt)))
{
if (SUCCEEDED(m_pD3D->CheckDepthStencilMatch(pDeviceCombo->AdapterOrdinal, pDeviceCombo->DevType, pDeviceCombo->AdapterFormat, pDeviceCombo->BackBufferFormat, depthStencilFmt)))
{
pDeviceCombo->pDepthStencilFormatList->AddElem(depthStencilFmt);
}
}
}
}
//-----------------------------------------------------------------------------
// Name: BuildMultiSampleTypeList
// Desc: Adds all multisample types that are compatible with the device and app to
// the given D3DDeviceCombo.
//-----------------------------------------------------------------------------
void CD3DEnumeration::BuildMultiSampleTypeList( D3DDeviceCombo* pDeviceCombo )
{
const D3DMULTISAMPLE_TYPE msTypeArray[] = {
D3DMULTISAMPLE_NONE,
D3DMULTISAMPLE_NONMASKABLE,
D3DMULTISAMPLE_2_SAMPLES,
D3DMULTISAMPLE_3_SAMPLES,
D3DMULTISAMPLE_4_SAMPLES,
D3DMULTISAMPLE_5_SAMPLES,
D3DMULTISAMPLE_6_SAMPLES,
D3DMULTISAMPLE_7_SAMPLES,
D3DMULTISAMPLE_8_SAMPLES,
D3DMULTISAMPLE_9_SAMPLES,
D3DMULTISAMPLE_10_SAMPLES,
D3DMULTISAMPLE_11_SAMPLES,
D3DMULTISAMPLE_12_SAMPLES,
D3DMULTISAMPLE_13_SAMPLES,
D3DMULTISAMPLE_14_SAMPLES,
D3DMULTISAMPLE_15_SAMPLES,
D3DMULTISAMPLE_16_SAMPLES,
};
const UINT msTypeArrayCount = sizeof(msTypeArray) / sizeof(msTypeArray[0]);
D3DMULTISAMPLE_TYPE msType;
DWORD msQuality;
for(UINT imst=0; imst<msTypeArrayCount; imst++)
{
msType = msTypeArray[imst];
if (SUCCEEDED(m_pD3D->CheckDeviceMultiSampleType(pDeviceCombo->AdapterOrdinal, pDeviceCombo->DevType, pDeviceCombo->BackBufferFormat, pDeviceCombo->IsWindowed, msType, &msQuality)))
{
pDeviceCombo->pMultiSampleTypeList->AddElem(msType);
pDeviceCombo->pMultiSampleQualityList->AddElem(msQuality);
}
}
}
//-----------------------------------------------------------------------------
// Name: BuildDSMSConflictList
// Desc: Find any conflicts between the available depth/stencil formats and
// multisample types.
//-----------------------------------------------------------------------------
void CD3DEnumeration::BuildDSMSConflictList(D3DDeviceCombo* pDeviceCombo)
{
D3DDSMSConflict DSMSConflict;
for(int ids=0; ids<pDeviceCombo->pDepthStencilFormatList->Num(); ids++)
{
D3DFORMAT dsFmt = pDeviceCombo->pDepthStencilFormatList->Get(ids);
for(int ims=0; ims< pDeviceCombo->pMultiSampleTypeList->Num(); ims++)
{
D3DMULTISAMPLE_TYPE msType = pDeviceCombo->pMultiSampleTypeList->Get(ims);
if( FAILED( m_pD3D->CheckDeviceMultiSampleType( pDeviceCombo->AdapterOrdinal, pDeviceCombo->DevType, dsFmt, pDeviceCombo->IsWindowed, msType, NULL)))
{
DSMSConflict.DSFormat = dsFmt;
DSMSConflict.MSType = msType;
pDeviceCombo->pDSMSConflictList->AddElem(DSMSConflict);
}
}
}
}
//-----------------------------------------------------------------------------
// Name: BuildVertexProcessingTypeList
// Desc: Adds all vertex processing types that are compatible with the device
// and app to the given D3DDeviceCombo.
//-----------------------------------------------------------------------------
void CD3DEnumeration::BuildVertexProcessingTypeList(D3DDeviceInfo* pDeviceInfo, D3DDeviceCombo* pDeviceCombo)
{
if ((pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0)
{
if ((pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_PUREDEVICE) != 0)
{
if (ConfirmDeviceCallback == NULL || ConfirmDeviceCallback(&pDeviceInfo->Caps, PURE_HARDWARE_VP, pDeviceCombo->AdapterFormat, pDeviceCombo->BackBufferFormat))
{
pDeviceCombo->pVertexProcessingTypeList->AddElem(PURE_HARDWARE_VP);
}
}
if (ConfirmDeviceCallback == NULL || ConfirmDeviceCallback(&pDeviceInfo->Caps, HARDWARE_VP, pDeviceCombo->AdapterFormat, pDeviceCombo->BackBufferFormat))
{
pDeviceCombo->pVertexProcessingTypeList->AddElem(HARDWARE_VP);
}
if (AppUsesMixedVP && (ConfirmDeviceCallback == NULL || ConfirmDeviceCallback(&pDeviceInfo->Caps, MIXED_VP, pDeviceCombo->AdapterFormat, pDeviceCombo->BackBufferFormat)))
{
pDeviceCombo->pVertexProcessingTypeList->AddElem(MIXED_VP);
}
}
if (ConfirmDeviceCallback == NULL || ConfirmDeviceCallback(&pDeviceInfo->Caps, SOFTWARE_VP, pDeviceCombo->AdapterFormat, pDeviceCombo->BackBufferFormat))
{
pDeviceCombo->pVertexProcessingTypeList->AddElem(SOFTWARE_VP);
}
}
//-----------------------------------------------------------------------------
// Name: BuildPresentIntervalList
// Desc: Adds all present intervals that are compatible with the device and app
// to the given D3DDeviceCombo.
//-----------------------------------------------------------------------------
void CD3DEnumeration::BuildPresentIntervalList(D3DDeviceInfo* pDeviceInfo, D3DDeviceCombo* pDeviceCombo)
{
const UINT piArray[] = {
D3DPRESENT_INTERVAL_IMMEDIATE,
D3DPRESENT_INTERVAL_DEFAULT,
D3DPRESENT_INTERVAL_ONE,
D3DPRESENT_INTERVAL_TWO,
D3DPRESENT_INTERVAL_THREE,
D3DPRESENT_INTERVAL_FOUR,
};
const UINT piArrayCount = sizeof(piArray) / sizeof(piArray[0]);
UINT pi;
for(UINT ipi=0; ipi<piArrayCount; ipi++)
{
pi = piArray[ipi];
if( pDeviceCombo->IsWindowed )
{
if( pi == D3DPRESENT_INTERVAL_TWO || pi == D3DPRESENT_INTERVAL_THREE || pi == D3DPRESENT_INTERVAL_FOUR)
{
// These intervals are not supported in windowed mode.
continue;
}
}
// Note that D3DPRESENT_INTERVAL_DEFAULT is zero, so you
// can't do a caps check for it -- it is always available.
if( pi == D3DPRESENT_INTERVAL_DEFAULT || (pDeviceInfo->Caps.PresentationIntervals & pi))
{
pDeviceCombo->pPresentIntervalList->AddElem(pi);
}
}
}
void CD3D9Renderer::SetRendParms(D3DDISPLAYMODE *pModeInfo, D3DDeviceInfo *pDeviceInfo)
{
m_bFullScreen = !m_D3DSettings.IsWindowed;
m_abpp = 0;
if (m_bFullScreen)
{
CRenderer::m_width = pModeInfo->Width;
CRenderer::m_height = pModeInfo->Height;
}
else
{
pModeInfo->Width = CRenderer::m_width;
pModeInfo->Height = CRenderer::m_height;
if (m_cbpp == 32)
pModeInfo->Format = D3DFMT_A8R8G8B8;
else
if (m_cbpp == 24)
pModeInfo->Format = D3DFMT_X8R8G8B8;
else
pModeInfo->Format = D3DFMT_R5G6B5;
}
CRenderer::m_abpp = AlphaChannelBits(m_D3DSettings.BackBufferFormat());
CRenderer::m_cbpp = ColorBits(m_D3DSettings.BackBufferFormat());
CRenderer::m_sbpp = StencilBits(m_D3DSettings.DepthStencilBufferFormat());
CRenderer::m_zbpp = DepthBits(m_D3DSettings.DepthStencilBufferFormat());
if (CV_d3d9_texturebits)
m_TextureBits = CV_d3d9_texturebits;
else
m_TextureBits = CRenderer::m_cbpp;
}
D3DFORMAT CD3D9Renderer::FindBestDepthFormat(D3DDeviceCombo* pBestDeviceCombo)
{
int i;
int mindPP = 10000;
int minsPP = 10000;
bool bFound = true;
D3DFORMAT fmt = D3DFMT_UNKNOWN;
if (CRenderer::m_zbpp < 24)
CRenderer::m_sbpp = 0;
for (i=0; i<pBestDeviceCombo->pDepthStencilFormatList->Num(); i++)
{
int sPP = StencilBits(pBestDeviceCombo->pDepthStencilFormatList->Get(i));
int dPP = DepthBits(pBestDeviceCombo->pDepthStencilFormatList->Get(i));
if (sPP == CRenderer::m_sbpp && dPP == CRenderer::m_zbpp)
{
fmt = pBestDeviceCombo->pDepthStencilFormatList->Get(i);
break;
}
else
if (CRenderer::m_sbpp)
{
if (minsPP > abs(sPP-CRenderer::m_sbpp))
{
minsPP = abs(sPP-CRenderer::m_sbpp);
fmt = pBestDeviceCombo->pDepthStencilFormatList->Get(i);
}
}
else
{
if (mindPP > abs(dPP-CRenderer::m_zbpp))
{
mindPP = abs(dPP-CRenderer::m_zbpp);
fmt = pBestDeviceCombo->pDepthStencilFormatList->Get(i);
}
}
}
return fmt;
}
int CD3D9Renderer::FindSuitableDevice(int a, bool bAllowSoft)
{
int idc;
if (a > m_D3DEnum.m_pAdapterInfoList->Num())
a = m_D3DEnum.m_pAdapterInfoList->Num()-1;
if (a < 0)
a = 0;
D3DAdapterInfo* pBestAdapterInfo = NULL;
D3DDeviceInfo* pBestDeviceInfo = NULL;
D3DDeviceCombo* pBestDeviceCombo = NULL;
D3DAdapterInfo *pAdapter = m_D3DEnum.m_pAdapterInfoList->Get(a);
D3DDISPLAYMODE requiredDisplayMode;
requiredDisplayMode.Width = CRenderer::m_width;
requiredDisplayMode.Height = CRenderer::m_height;
D3DFORMAT BackBufferFormat;
D3DFORMAT AdapterFormat;
if (CRenderer::m_cbpp == 32)
{
BackBufferFormat = D3DFMT_A8R8G8B8;
AdapterFormat = D3DFMT_X8R8G8B8;
}
else
if (CRenderer::m_cbpp == 24)
{
BackBufferFormat = D3DFMT_X8R8G8B8;
AdapterFormat = D3DFMT_X8R8G8B8;
}
else
{
BackBufferFormat = D3DFMT_X8R8G8B8;
AdapterFormat = D3DFMT_R5G6B5;
}
D3DDISPLAYMODE primaryDesktopDisplayMode;
m_pD3D->GetAdapterDisplayMode(0, &primaryDesktopDisplayMode);
// Need to find a display mode on the best adapter that uses pBestDeviceCombo->AdapterFormat
// and is as close to bestAdapterDesktopDisplayMode's res as possible
D3DDISPLAYMODE bestDisplayMode;
bestDisplayMode.Width = 0;
bestDisplayMode.Height = 0;
bestDisplayMode.Format = D3DFMT_UNKNOWN;
bestDisplayMode.RefreshRate = 0;
int d;
for(d=0; d<pAdapter->pDeviceInfoList->Num(); d++)
{
D3DAdapterInfo *pAdapter = m_D3DEnum.m_pAdapterInfoList->Get(a);
D3DDeviceInfo *pDevice = pAdapter->pDeviceInfoList->Get(d);
if ((CV_d3d9_forcesoftware && pDevice->DevType == D3DDEVTYPE_HAL) || (pDevice->DevType != D3DDEVTYPE_HAL && !bAllowSoft))
continue;
for(idc=0; idc<pDevice->pDeviceComboList->Num(); idc++)
{
D3DDeviceCombo* pDeviceCombo = pDevice->pDeviceComboList->Get(idc);
if (m_bFullScreen)
{
if (pDeviceCombo->IsWindowed)
continue;
bool bAdapterMatches = (pDeviceCombo->AdapterFormat == AdapterFormat);
// If we haven't found a compatible set yet, or if this set
// is better (because it's a HAL, and/or because formats match better),
// save it
if (pBestDeviceCombo == NULL ||
(pBestDeviceCombo->DevType != D3DDEVTYPE_HAL && pDevice->DevType == D3DDEVTYPE_HAL) ||
(pDeviceCombo->DevType == D3DDEVTYPE_HAL && pBestDeviceCombo->BackBufferFormat != BackBufferFormat && bAdapterMatches))
{
pBestAdapterInfo = pAdapter;
pBestDeviceInfo = pDevice;
pBestDeviceCombo = pDeviceCombo;
if (pDevice->DevType == D3DDEVTYPE_HAL && bAdapterMatches && pBestDeviceCombo->BackBufferFormat == BackBufferFormat)
{
// This fullscreen device combo looks great -- take it
break;
}
// Otherwise keep looking for a better fullscreen device combo
}
}
else
{
if (!pDeviceCombo->IsWindowed)
continue;
if (pDeviceCombo->AdapterFormat != primaryDesktopDisplayMode.Format)
continue;
bool bAdapterBBMatchesBB = (pDeviceCombo->BackBufferFormat == BackBufferFormat);
// If we haven't found a compatible DeviceCombo yet, or if this set
// is better (because it's a HAL, and/or because formats match better),
// save it
if( pBestDeviceCombo == NULL || (bAdapterBBMatchesBB && pDeviceCombo->DevType == D3DDEVTYPE_HAL))
{
pBestAdapterInfo = pAdapter;
pBestDeviceInfo = pDevice;
pBestDeviceCombo = pDeviceCombo;
// This windowed device combo looks great -- take it
if( bAdapterBBMatchesBB )
break;
}
}
}
if (idc != pDevice->pDeviceComboList->Num())
break;
}
if (!pBestDeviceCombo)
return -1;
if (!m_bFullScreen)
CRenderer::m_cbpp = ColorBits(pBestDeviceCombo->BackBufferFormat);
if (CV_d3d9_texturebits)
m_TextureBits = CV_d3d9_texturebits;
else
m_TextureBits = CRenderer::m_cbpp;
if (m_bFullScreen)
{
int BestError = 999999;
int Best;
int BestCD;
for(int idm=0; idm<pAdapter->pDisplayModeList->Num(); idm++)
{
D3DDISPLAYMODE* pdm = &pAdapter->pDisplayModeList->Get(idm);
if(pdm->Format != pBestDeviceCombo->AdapterFormat)
continue;
int thisCD = ColorBits(pBestDeviceCombo->AdapterFormat);
if (thisCD <= 0)
continue;
int ThisError = abs((int)pdm->Width-(int)requiredDisplayMode.Width) + abs((int)pdm->Height-(int)requiredDisplayMode.Height) + abs((int)thisCD-(int)CRenderer::m_cbpp);
if (ThisError < BestError)
{
Best = idm;
BestCD = thisCD;
BestError = ThisError;
bestDisplayMode = *pdm;
}
}
if( BestError == 999999 )
return -1;
//CRenderer::m_cbpp = BestCD;
CRenderer::m_width = bestDisplayMode.Width;
CRenderer::m_height = bestDisplayMode.Height;
iLog->Log ("Best-match display mode: %ix%ix%i (Error=%i)\n",CRenderer::m_width,CRenderer::m_height,CRenderer::m_cbpp,BestError);
m_D3DSettings.pFullscreen_AdapterInfo = pBestAdapterInfo;
m_D3DSettings.pFullscreen_DeviceInfo = pBestDeviceInfo;
m_D3DSettings.pFullscreen_DeviceCombo = pBestDeviceCombo;
m_D3DSettings.IsWindowed = false;
m_D3DSettings.Fullscreen_DisplayMode = bestDisplayMode;
m_D3DSettings.Fullscreen_DisplayMode.RefreshRate = D3DPRESENT_RATE_DEFAULT;
if (m_D3DEnum.AppUsesDepthBuffer)
{
m_D3DSettings.Fullscreen_DepthStencilBufferFormat = FindBestDepthFormat(pBestDeviceCombo);
}
m_D3DSettings.Fullscreen_MultisampleType = pBestDeviceCombo->pMultiSampleTypeList->Get(0);
m_D3DSettings.Fullscreen_MultisampleQuality = 0;
m_D3DSettings.Fullscreen_VertexProcessingType = pBestDeviceCombo->pVertexProcessingTypeList->Get(0);
m_D3DSettings.Fullscreen_PresentInterval = D3DPRESENT_INTERVAL_DEFAULT;
}
else
{
m_D3DSettings.pWindowed_AdapterInfo = pBestAdapterInfo;
m_D3DSettings.pWindowed_DeviceInfo = pBestDeviceInfo;
m_D3DSettings.pWindowed_DeviceCombo = pBestDeviceCombo;
m_D3DSettings.IsWindowed = true;
m_D3DSettings.Windowed_DisplayMode = primaryDesktopDisplayMode;
m_D3DSettings.Windowed_Width = CRenderer::m_width;
m_D3DSettings.Windowed_Height = CRenderer::m_height;
if (m_D3DEnum.AppUsesDepthBuffer)
{
if (CV_d3d9_forcesoftware)
m_D3DSettings.Windowed_DepthStencilBufferFormat = D3DFMT_D16_LOCKABLE;
else
m_D3DSettings.Windowed_DepthStencilBufferFormat = FindBestDepthFormat(pBestDeviceCombo);
}
m_D3DSettings.Windowed_MultisampleType = pBestDeviceCombo->pMultiSampleTypeList->Get(0);
m_D3DSettings.Windowed_MultisampleQuality = 0;
m_D3DSettings.Windowed_VertexProcessingType = pBestDeviceCombo->pVertexProcessingTypeList->Get(0);
m_D3DSettings.Windowed_PresentInterval = pBestDeviceCombo->pPresentIntervalList->Get(0);
}
return d;
}

View File

@@ -0,0 +1,130 @@
#ifndef D3DENUM_H
#define D3DENUM_H
//-----------------------------------------------------------------------------
// Name: enum VertexProcessingType
// Desc: Enumeration of all possible D3D vertex processing types.
//-----------------------------------------------------------------------------
enum VertexProcessingType
{
SOFTWARE_VP,
MIXED_VP,
HARDWARE_VP,
PURE_HARDWARE_VP
};
//-----------------------------------------------------------------------------
// Name: struct D3DDSMSConflict
// Desc: A depth/stencil buffer format that is incompatible with a
// multisample type.
//-----------------------------------------------------------------------------
struct D3DDSMSConflict
{
D3DFORMAT DSFormat;
D3DMULTISAMPLE_TYPE MSType;
};
//-----------------------------------------------------------------------------
// Name: struct D3DDeviceCombo
// Desc: A combination of adapter format, back buffer format, and windowed/fullscreen
// that is compatible with a particular D3D device (and the app).
//-----------------------------------------------------------------------------
struct D3DDeviceCombo
{
int AdapterOrdinal;
D3DDEVTYPE DevType;
D3DFORMAT AdapterFormat;
D3DFORMAT BackBufferFormat;
bool IsWindowed;
TArray<D3DFORMAT> *pDepthStencilFormatList; // List of D3DFORMATs
TArray<D3DMULTISAMPLE_TYPE> *pMultiSampleTypeList; // List of D3DMULTISAMPLE_TYPEs
TArray<DWORD> *pMultiSampleQualityList; // List of DWORDs (number of quality
// levels for each multisample type)
TArray<D3DDSMSConflict> *pDSMSConflictList; // List of D3DDSMSConflicts
TArray<VertexProcessingType> *pVertexProcessingTypeList; // List of VertexProcessingTypes
TArray<UINT> *pPresentIntervalList; // List of D3DPRESENT_INTERVALs
~D3DDeviceCombo( void );
};
//-----------------------------------------------------------------------------
// Name: struct D3DDeviceInfo
// Desc: Info about a D3D device, including a list of D3DDeviceCombos (see below)
// that work with the device.
//-----------------------------------------------------------------------------
struct D3DDeviceInfo
{
int AdapterOrdinal;
D3DDEVTYPE DevType;
D3DCAPS9 Caps;
TArray<D3DDeviceCombo *> *pDeviceComboList; // List of D3DDeviceCombo pointers
~D3DDeviceInfo( void );
};
//-----------------------------------------------------------------------------
// Name: struct D3DAdapterInfo
// Desc: Info about a display adapter.
//-----------------------------------------------------------------------------
struct D3DAdapterInfo
{
int AdapterOrdinal;
uint m_MaxWidth;
uint m_MaxHeight;
D3DADAPTER_IDENTIFIER9 AdapterIdentifier;
TArray<D3DDISPLAYMODE> *pDisplayModeList; // List of D3DDISPLAYMODEs
TArray<D3DDeviceInfo*> *pDeviceInfoList; // List of D3DDeviceInfo pointers
~D3DAdapterInfo( void );
};
typedef bool(* CONFIRMDEVICECALLBACK)( D3DCAPS9* pCaps, VertexProcessingType vertexProcessingType,
D3DFORMAT adapterFormat, D3DFORMAT backBufferFormat );
//-----------------------------------------------------------------------------
// Name: class CD3DEnumeration
// Desc: Enumerates available D3D adapters, devices, modes, etc.
//-----------------------------------------------------------------------------
class CD3DEnumeration
{
private:
IDirect3D9* m_pD3D;
private:
HRESULT EnumerateDevices( D3DAdapterInfo* pAdapterInfo, TArray<D3DFORMAT> *pAdapterFormatList );
HRESULT EnumerateDeviceCombos( D3DDeviceInfo* pDeviceInfo, TArray<D3DFORMAT> *pAdapterFormatList );
void BuildDepthStencilFormatList( D3DDeviceCombo* pDeviceCombo );
void BuildMultiSampleTypeList( D3DDeviceCombo* pDeviceCombo );
void BuildDSMSConflictList( D3DDeviceCombo* pDeviceCombo );
void BuildVertexProcessingTypeList( D3DDeviceInfo* pDeviceInfo, D3DDeviceCombo* pDeviceCombo );
void BuildPresentIntervalList( D3DDeviceInfo* pDeviceInfo, D3DDeviceCombo* pDeviceCombo );
public:
TArray<D3DAdapterInfo *> *m_pAdapterInfoList;
// The following variables can be used to limit what modes, formats,
// etc. are enumerated. Set them to the values you want before calling
// Enumerate().
CONFIRMDEVICECALLBACK ConfirmDeviceCallback;
UINT AppMinFullscreenWidth;
UINT AppMinFullscreenHeight;
UINT AppMinColorChannelBits; // min color bits per channel in adapter format
UINT AppMinAlphaChannelBits; // min alpha bits per pixel in back buffer format
UINT AppMinDepthBits;
UINT AppMinStencilBits;
bool AppUsesDepthBuffer;
bool AppUsesMixedVP; // whether app can take advantage of mixed vp mode
bool AppRequiresWindowed;
bool AppRequiresFullscreen;
TArray<D3DFORMAT> *m_pAllowedAdapterFormatList; // list of D3DFORMATs
CD3DEnumeration();
~CD3DEnumeration();
void SetD3D(IDirect3D9* pD3D) { m_pD3D = pD3D; }
HRESULT Enumerate();
};
#endif

View File

@@ -0,0 +1,308 @@
#include "RenderPCH.h"
#include "DriverD3D9.h"
//=========================================================================================
#include "../CryFont/FBitmap.h"
bool CD3D9Renderer::FontUpdateTexture(int nTexId, int X, int Y, int USize, int VSize, byte *pData)
{
WaitForDevice();
STexPicD3D *tp = (STexPicD3D *)gRenDev->m_TexMan->m_Textures[nTexId-TX_FIRSTBIND];
assert (tp && tp->m_Bind == nTexId);
if (tp)
{
m_TexMan->UpdateTextureRegion(tp, pData, X, Y, USize, VSize);
return true;
}
return false;
}
bool CD3D9Renderer::FontUploadTexture(class CFBitmap* pBmp, ETEX_Format eTF)
{
if(!pBmp)
{
return false;
}
unsigned int *pData = new unsigned int[pBmp->GetWidth() * pBmp->GetHeight()];
if (!pData)
{
return false;
}
pBmp->Get32Bpp(&pData);
char szName[128];
sprintf(szName, "$AutoFont_%d", m_TexGenID++);
int iFlags = FT_HASALPHA | FT_FONT | FT_NOSTREAM;
STexPic *tp = m_TexMan->CreateTexture(szName, pBmp->GetWidth(), pBmp->GetHeight(), 1, iFlags, 0, (unsigned char *)pData, eTT_Base, -1.0f, -1.0f, 0, NULL, 0, eTF);
SAFE_DELETE_ARRAY(pData);
pBmp->SetRenderData((void *)tp);
return true;
}
int CD3D9Renderer::FontCreateTexture(int Width, int Height, byte *pData, ETEX_Format eTF)
{
if (!pData)
return -1;
char szName[128];
sprintf(szName, "$AutoFont_%d", m_TexGenID++);
int iFlags = FT_HASALPHA | FT_FONT | FT_NOSTREAM | FT_NOMIPS;
STexPic *tp = m_TexMan->CreateTexture(szName, Width, Height, 1, iFlags, 0, pData, eTT_Base, -1.0f, -1.0f, 0, NULL, 0, eTF);
return tp->GetTextureID();
}
void CD3D9Renderer::FontReleaseTexture(class CFBitmap *pBmp)
{
if(!pBmp)
{
return;
}
STexPic *tp = (STexPic *)pBmp->GetRenderData();
tp->Release(false);
}
void CD3D9Renderer::FontSetTexture(class CFBitmap* pBmp, int nFilterMode)
{
if (pBmp)
{
STexPic *tp = (STexPic *)pBmp->GetRenderData();
tp->Set();
}
LPDIRECT3DDEVICE9 dv = mfGetD3DDevice();
int tmu = 0;
switch(nFilterMode)
{
case FILTER_LINEAR:
default:
if (m_RP.m_TexStages[tmu].nMipFilter != D3DTEXF_NONE)
{
m_RP.m_TexStages[tmu].nMipFilter = D3DTEXF_NONE;
dv->SetSamplerState(tmu, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
}
if (m_RP.m_TexStages[tmu].MagFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MagFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
}
if (m_RP.m_TexStages[tmu].MinFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MinFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
}
break;
case FILTER_BILINEAR:
if (m_RP.m_TexStages[tmu].nMipFilter == D3DTEXF_POINT)
{
m_RP.m_TexStages[tmu].nMipFilter = D3DTEXF_POINT;
dv->SetSamplerState(tmu, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
}
if (m_RP.m_TexStages[tmu].MagFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MagFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
}
if (m_RP.m_TexStages[tmu].MinFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MinFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
}
break;
case FILTER_TRILINEAR:
if (m_RP.m_TexStages[tmu].nMipFilter == D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].nMipFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
}
if (m_RP.m_TexStages[tmu].MagFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MagFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
}
if (m_RP.m_TexStages[tmu].MinFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MinFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
}
break;
}
}
void CD3D9Renderer::FontSetTexture(int nTexId, int nFilterMode)
{
if (nTexId <= 0 || nTexId > TX_LASTBIND)
return;
STexPicD3D *tp = (STexPicD3D *)gRenDev->m_TexMan->m_Textures[nTexId-TX_FIRSTBIND];
assert (tp && tp->m_Bind == nTexId);
if (CV_d3d9_forcesoftware)
return;
tp->Set();
LPDIRECT3DDEVICE9 dv = mfGetD3DDevice();
int tmu = 0;
switch(nFilterMode)
{
case FILTER_LINEAR:
default:
if (m_RP.m_TexStages[tmu].nMipFilter != D3DTEXF_NONE)
{
m_RP.m_TexStages[tmu].nMipFilter = D3DTEXF_NONE;
dv->SetSamplerState(tmu, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
}
if (m_RP.m_TexStages[tmu].MagFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MagFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
}
if (m_RP.m_TexStages[tmu].MinFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MinFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
}
break;
case FILTER_BILINEAR:
if (m_RP.m_TexStages[tmu].nMipFilter == D3DTEXF_POINT)
{
m_RP.m_TexStages[tmu].nMipFilter = D3DTEXF_POINT;
dv->SetSamplerState(tmu, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
}
if (m_RP.m_TexStages[tmu].MagFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MagFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
}
if (m_RP.m_TexStages[tmu].MinFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MinFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
}
break;
case FILTER_TRILINEAR:
if (m_RP.m_TexStages[tmu].nMipFilter == D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].nMipFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
}
if (m_RP.m_TexStages[tmu].MagFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MagFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
}
if (m_RP.m_TexStages[tmu].MinFilter != D3DTEXF_LINEAR)
{
m_RP.m_TexStages[tmu].MinFilter = D3DTEXF_LINEAR;
dv->SetSamplerState(tmu, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
}
break;
}
}
void CD3D9Renderer::FontSetRenderingState(unsigned long nVPWidth, unsigned long nVPHeight)
{
// setup various d3d things that we need
FontSetState(false);
D3DXMATRIX *m;
m_matProj->Push();
m_matProj->LoadIdentity();
m = m_matProj->GetTop();
D3DXMatrixOrthoOffCenterRH(m, 0.0f, (float)m_Viewport.Width, (float)m_Viewport.Height, 0.0f, -1.0f, 1.0f);
m_pd3dDevice->SetTransform(D3DTS_PROJECTION, m);
EF_PushMatrix();
m_matView->LoadIdentity();
m_pd3dDevice->SetTransform(D3DTS_VIEW, m_matView->GetTop());
}
// match table with the blending modes
static int nBlendMatchTable[] =
{
D3DBLEND_ZERO,
D3DBLEND_ONE,
D3DBLEND_SRCCOLOR,
D3DBLEND_INVSRCCOLOR,
D3DBLEND_SRCALPHA,
D3DBLEND_INVSRCALPHA,
D3DBLEND_DESTALPHA,
D3DBLEND_INVDESTALPHA,
D3DBLEND_DESTCOLOR,
D3DBLEND_INVDESTCOLOR,
};
void CD3D9Renderer::FontSetBlending(int blendSrc, int blendDest)
{
}
void CD3D9Renderer::FontRestoreRenderingState()
{
D3DXMATRIX *m;
m_matProj->Pop();
m = m_matProj->GetTop();
m_pd3dDevice->SetTransform(D3DTS_PROJECTION, m);
EF_PopMatrix();
FontSetState(true);
}
void CD3D9Renderer::FontSetState(bool bRestore)
{
static DWORD polyMode;
static D3DCOLORVALUE color;
static bool bMatColor;
static int State;
if (CV_d3d9_forcesoftware)
return;
CD3D9TexMan::BindNULL(1);
// grab the modes that we might need to change
if(!bRestore)
{
D3DSetCull(eCULL_None);
color = m_Material.Diffuse;
bMatColor = m_bMatColor;
State = m_CurState;
polyMode = m_polygon_mode;
EF_SetVertColor();
if(polyMode == R_WIREFRAME_MODE)
m_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
m_RP.m_FlagsPerFlush = 0;
EF_SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST | GS_ALPHATEST_GREATER0);
EF_SetColorOp(eCO_REPLACE, eCO_MODULATE, eCA_Diffuse | (eCA_Diffuse<<3), DEF_TEXARG0);
//m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
//m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
}
else
{
if (m_bMatColor)
EF_SetGlobalColor(color.r,color.g,color.b,color.a);
if(polyMode == R_WIREFRAME_MODE)
m_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
//EF_SetState(State);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,897 @@
/*=============================================================================
D3DREOcean.cpp : implementation of the Ocean Rendering.
Copyright (c) 2001 Crytek Studios. All Rights Reserved.
Revision history:
* Created by Honitch Andrey
=============================================================================*/
#include "RenderPCH.h"
#include "DriverD3D9.h"
#include "D3DCGVProgram.h"
#include "D3DCGPShader.h"
#include "I3dengine.h"
#include "../Common/NvTriStrip/NVTriStrip.h"
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
//=======================================================================
void CREOcean::GenerateIndices(int nLodCode)
{
CD3D9Renderer *r = gcpRendD3D;
LPDIRECT3DDEVICE9 dv = gcpRendD3D->mfGetD3DDevice();
HRESULT h;
SPrimitiveGroup pg;
IDirect3DIndexBuffer9* ibuf;
int size;
int flags = D3DUSAGE_WRITEONLY;
D3DPOOL Pool = D3DPOOL_MANAGED;
ushort *dst;
TArray<ushort> Indicies;
if (m_OceanIndicies[nLodCode])
return;
SOceanIndicies *oi = new SOceanIndicies;
m_OceanIndicies[nLodCode] = oi;
if (!(nLodCode & ~LOD_MASK))
{
int nL = nLodCode & LOD_MASK;
pg.offsIndex = 0;
pg.numIndices = m_pIndices[nL].Num();
pg.numTris = pg.numIndices-2;
pg.type = PT_STRIP;
oi->m_Groups.AddElem(pg);
size = pg.numIndices*sizeof(ushort);
h = dv->CreateIndexBuffer(size, flags, D3DFMT_INDEX16, Pool, (IDirect3DIndexBuffer9**)&oi->m_pIndicies, NULL);
ibuf = (IDirect3DIndexBuffer9*)oi->m_pIndicies;
oi->m_nInds = pg.numIndices;
h = ibuf->Lock(0, 0, (void **) &dst, 0);
cryMemcpy(dst, &m_pIndices[nL][0], pg.numIndices*sizeof(ushort));
h = ibuf->Unlock();
return;
}
int nLod = nLodCode & LOD_MASK;
int nl = 1<<nLod;
int nGrid = (OCEANGRID+1);
// set indices
int iIndex = nGrid*nl+nl;
int yStep = nGrid * nl;
for(int a=nl; a<nGrid-1-nl; a+=nl)
{
for(int i=nl; i<nGrid-nl; i+=nl, iIndex+=nl)
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex + yStep);
}
int iNextIndex = (a+nl) * nGrid + nl;
// connect two strips by inserting two degenerated triangles
if(a < nGrid-1-nl*2)
{
Indicies.AddElem(iIndex + yStep - nl);
Indicies.AddElem(iNextIndex);
}
iIndex = iNextIndex;
}
pg.numIndices = Indicies.Num();
pg.numTris = pg.numIndices-2;
pg.type = PT_STRIP;
pg.offsIndex = 0;
oi->m_Groups.AddElem(pg);
// Left
pg.offsIndex = Indicies.Num();
iIndex = nGrid*(nGrid-1);
if (!(nLodCode & (1<<LOD_LEFTSHIFT)))
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex - nGrid * nl + nl);
Indicies.AddElem(iIndex - nGrid * nl);
iIndex = iIndex - nGrid * nl + nl;
yStep = -(nGrid * nl) - nl;
for(int i=nl; i<nGrid-nl; i+=nl, iIndex-=nGrid*nl)
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex + yStep);
}
}
else
{
for(int i=0; i<nGrid-nl; i+=nl*2)
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex - (nGrid * nl) + nl);
Indicies.AddElem(iIndex - nGrid * nl * 2);
if (i < nGrid-nl-nl*2)
Indicies.AddElem(iIndex - nGrid * nl * 2 + nl);
iIndex -= nGrid * nl * 2;
}
}
pg.numIndices = Indicies.Num()-pg.offsIndex;
pg.numTris = pg.numIndices-2;
oi->m_Groups.AddElem(pg);
// Bottom
pg.offsIndex = Indicies.Num();
iIndex = 0;
if (!(nLodCode & (1<<LOD_BOTTOMSHIFT)))
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex + nGrid*nl + nl);
Indicies.AddElem(iIndex + nl);
iIndex = iIndex + nGrid*nl + nl;
yStep = -(nGrid * nl) + nl;
for(int i=nl; i<nGrid-nl; i+=nl, iIndex+=nl)
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex + yStep);
}
}
else
{
for(int i=0; i<nGrid-nl; i+=nl*2)
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex + (nGrid * nl) + nl);
Indicies.AddElem(iIndex + nl * 2);
if (i < nGrid-nl-nl*2)
Indicies.AddElem(iIndex + nGrid * nl + nl * 2);
iIndex += nl * 2;
}
}
pg.numIndices = Indicies.Num()-pg.offsIndex;
pg.numTris = pg.numIndices-2;
oi->m_Groups.AddElem(pg);
// Right
pg.offsIndex = Indicies.Num();
iIndex = nGrid-1;
if (!(nLodCode & (1<<LOD_RIGHTSHIFT)))
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex + nGrid * nl - nl);
Indicies.AddElem(iIndex + nGrid * nl);
iIndex = iIndex + nGrid * nl - nl;
yStep = nGrid * nl + nl;
for(int i=nl; i<nGrid-nl; i+=nl, iIndex+=nGrid*nl)
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex + yStep);
}
}
else
{
for(int i=0; i<nGrid-nl; i+=nl*2)
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex + (nGrid * nl) - nl);
Indicies.AddElem(iIndex + nGrid * nl * 2);
if (i < nGrid-nl-nl*2)
Indicies.AddElem(iIndex + nGrid * nl * 2 - nl);
iIndex += nGrid * nl * 2;
}
}
pg.numIndices = Indicies.Num()-pg.offsIndex;
pg.numTris = pg.numIndices-2;
oi->m_Groups.AddElem(pg);
// Top
pg.offsIndex = Indicies.Num();
iIndex = nGrid*(nGrid-1)+nGrid-1;
if (!(nLodCode & (1<<LOD_TOPSHIFT)))
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex - nGrid*nl - nl);
Indicies.AddElem(iIndex - nl);
iIndex = iIndex - nGrid*nl - nl;
yStep = nGrid * nl - nl;
for(int i=nl; i<nGrid-nl; i+=nl, iIndex-=nl)
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex + yStep);
}
}
else
{
for(int i=0; i<nGrid-nl; i+=nl*2)
{
Indicies.AddElem(iIndex);
Indicies.AddElem(iIndex - (nGrid * nl) - nl);
Indicies.AddElem(iIndex - nl * 2);
if (i < nGrid-nl-nl*2)
Indicies.AddElem(iIndex - nGrid * nl - nl * 2);
iIndex -= nl * 2;
}
}
pg.numIndices = Indicies.Num()-pg.offsIndex;
pg.numTris = pg.numIndices-2;
oi->m_Groups.AddElem(pg);
size = Indicies.Num()*sizeof(ushort);
h = dv->CreateIndexBuffer(size, flags, D3DFMT_INDEX16, Pool, (IDirect3DIndexBuffer9**)&oi->m_pIndicies, NULL);
ibuf = (IDirect3DIndexBuffer9*)oi->m_pIndicies;
oi->m_nInds = Indicies.Num();
h = ibuf->Lock(0, 0, (void **) &dst, 0);
cryMemcpy(dst, &Indicies[0], size);
h = ibuf->Unlock();
}
void CREOcean::UpdateTexture()
{
if (m_CustomTexBind[0]>0 && !CRenderer::CV_r_oceantexupdate)
return;
HRESULT h;
CD3D9Renderer *r = gcpRendD3D;
LPDIRECT3DDEVICE9 dv = gcpRendD3D->mfGetD3DDevice();
byte data[OCEANGRID][OCEANGRID][4];
double time0 = 0;
ticks(time0);
for(unsigned int y=0; y<OCEANGRID; y++)
{
for( unsigned int x=0; x<OCEANGRID; x++)
{
data[y][x][0] = (byte)(m_Normals[y][x].x * 127.0f);
data[y][x][1] = (byte)(m_Normals[y][x].y * 127.0f);
data[y][x][2] = (byte)(m_Normals[y][x].z * 127.0f);
data[y][x][3] = 0;
}
}
if (m_CustomTexBind[0] <= 0)
{
char name[128];
sprintf(name, "$AutoOcean_%d", r->m_TexGenID++);
STexPic *tp = r->m_TexMan->CreateTexture(name, OCEANGRID, OCEANGRID, 1, FT_NOMIPS | FT_NOSTREAM, FT2_NODXT, &data[0][0][0], eTT_DSDTBump, -1.0f, -1.0f, 0, NULL, 0, eTF_0888);
m_CustomTexBind[0] = tp->m_Bind;
}
else
{
STexPicD3D *tp = (STexPicD3D *)gRenDev->m_TexMan->m_Textures[m_CustomTexBind[0]-TX_FIRSTBIND];
IDirect3DTexture9 *pID3DTexture = (IDirect3DTexture9*)tp->m_RefTex.m_VidTex;
D3DLOCKED_RECT d3dlr;
h = pID3DTexture->LockRect(0, &d3dlr, NULL, 0);
D3DSURFACE_DESC ddsdDescDest;
pID3DTexture->GetLevelDesc(0, &ddsdDescDest);
if (d3dlr.Pitch == tp->m_Width*4)
cryMemcpy(d3dlr.pBits, data, tp->m_Width*tp->m_Height*4);
else
{
switch(ddsdDescDest.Format)
{
case D3DFMT_X8L8V8U8:
{
byte *pDst = (byte *)d3dlr.pBits;
byte *pSrc = &data[0][0][0];
for (int i=0; i<tp->m_Height; i++)
{
cryMemcpy(pDst, pSrc, tp->m_Width*4);
pDst += d3dlr.Pitch;
pSrc += tp->m_Width*4;
}
}
break;
case D3DFMT_L6V5U5:
break;
case D3DFMT_V8U8:
{
byte *pDst = (byte *)d3dlr.pBits;
byte *pSrc = &data[0][0][0];
for (int i=0; i<tp->m_Height; i++)
{
for (int j=0; j<tp->m_Width; j++)
{
pDst[j*2+0] = pSrc[j*4+0];
pDst[j*2+1] = pSrc[j*4+1];
}
pDst += d3dlr.Pitch;
pSrc += tp->m_Width*4;
}
}
break;
default:
assert(0);
}
}
h = pID3DTexture->UnlockRect(0);
}
unticks(time0);
m_RS.m_StatsTimeTexUpdate = (float)(time0*1000.0*g_SecondsPerCycle);
}
void CREOcean::DrawOceanSector(SOceanIndicies *oi)
{
CD3D9Renderer *r = gcpRendD3D;
LPDIRECT3DDEVICE9 dv = gcpRendD3D->mfGetD3DDevice();
HRESULT h;
h = dv->SetIndices((IDirect3DIndexBuffer9 *)oi->m_pIndicies);
for (int i=0; i<oi->m_Groups.Num(); i++)
{
SPrimitiveGroup *g = &oi->m_Groups[i];
switch (g->type)
{
case PT_STRIP:
if (FAILED(h=dv->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, (OCEANGRID+1)*(OCEANGRID+1), g->offsIndex, g->numTris)))
{
r->Error("CREOcean::DrawOceanSector: DrawIndexedPrimitive error", h);
return;
}
break;
case PT_LIST:
if (FAILED(h=dv->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, (OCEANGRID+1)*(OCEANGRID+1), g->offsIndex, g->numTris)))
{
r->Error("CREOcean::DrawOceanSector: DrawIndexedPrimitive error", h);
return;
}
break;
case PT_FAN:
if (FAILED(h=dv->DrawIndexedPrimitive(D3DPT_TRIANGLEFAN, 0, 0, (OCEANGRID+1)*(OCEANGRID+1), g->offsIndex, g->numTris)))
{
r->Error("CREOcean::DrawOceanSector: DrawIndexedPrimitive error", h);
return;
}
break;
}
gRenDev->m_nPolygons += g->numTris;
}
}
static _inline int Compare(SOceanSector *& p1, SOceanSector *& p2)
{
if(p1->m_Flags > p2->m_Flags)
return 1;
else
if(p1->m_Flags < p2->m_Flags)
return -1;
return 0;
}
static _inline float sCalcSplash(SSplash *spl, float fX, float fY)
{
CD3D9Renderer *r = gcpRendD3D;
float fDeltaTime = r->m_RP.m_RealTime - spl->m_fStartTime;
float fScaleFactor = 1.0f / (r->m_RP.m_RealTime - spl->m_fLastTime + 1.0f);
float vDelt[2];
// Calculate 2D distance
vDelt[0] = spl->m_Pos[0] - fX; vDelt[1] = spl->m_Pos[1] - fY;
float fSqDist = vDelt[0]*vDelt[0] + vDelt[1]*vDelt[1];
// Inverse square root
unsigned int *n1 = (unsigned int *)&fSqDist;
unsigned int nn = 0x5f3759df - (*n1 >> 1);
float *n2 = (float *)&nn;
float fDistSplash = 1.0f / ((1.5f - (fSqDist * 0.5f) * *n2 * *n2) * *n2);
// Emulate sin waves
float fDistFactor = fDeltaTime*10.0f - fDistSplash + 4.0f;
fDistFactor = CLAMP(fDistFactor, 0.0f, 1.0f);
float fRad = (fDistSplash - fDeltaTime*10) * 0.4f / 3.1416f * 1024.0f;
float fSin = gRenDev->m_RP.m_tSinTable[QRound(fRad)&0x3ff] * fDistFactor;
return fSin * fScaleFactor * spl->m_fForce;
}
float *CREOcean::mfFillAdditionalBuffer(SOceanSector *os, int nSplashes, SSplash *pSplashes[], int& nCurSize, int nLod, float fSize)
{
float *pHM, *pTZ;
int nFloats = (os->m_Flags & OSF_NEEDHEIGHTS) ? 1 : 0;
if (nSplashes)
nFloats++;
pTZ = (float *)GetVBPtr((OCEANGRID+1)*(OCEANGRID+1));
pHM = pTZ;
int nStep = 1<<nLod;
if (!nSplashes)
{
for (int ty=0; ty<OCEANGRID+1; ty+=nStep)
{
pTZ = &pHM[ty*(OCEANGRID+1)*2];
for (int tx=0; tx<OCEANGRID+1; tx+=nStep)
{
float fX = m_Pos[ty][tx][0]*fSize+os->x;
float fY = m_Pos[ty][tx][1]*fSize+os->y;
float fZ = GetHMap(fX, fY);
pTZ[0] = fZ;
pTZ += nStep*2;
}
}
}
else
if (!(os->m_Flags & OSF_NEEDHEIGHTS))
{
for (int ty=0; ty<OCEANGRID+1; ty+=nStep)
{
pTZ = &pHM[ty*(OCEANGRID+1)*2];
for (int tx=0; tx<OCEANGRID+1; tx+=nStep)
{
float fX = m_Pos[ty][tx][0]*fSize+os->x;
float fY = m_Pos[ty][tx][1]*fSize+os->y;
float fSplash = 0;
for (int n=0; n<nSplashes; n++)
{
SSplash *spl = pSplashes[n];
fSplash += sCalcSplash(spl, fX, fY);
}
pTZ[0] = 0;
pTZ[1] = fSplash;
pTZ += nStep*2;
}
}
}
else
{
for (int ty=0; ty<OCEANGRID+1; ty+=nStep)
{
pTZ = &pHM[ty*(OCEANGRID+1)*2];
for (int tx=0; tx<OCEANGRID+1; tx+=nStep)
{
float fX = m_Pos[ty][tx][0]*fSize+os->x;
float fY = m_Pos[ty][tx][1]*fSize+os->y;
float fZ = GetHMap(fX, fY);
pTZ[0] = fZ;
float fSplash = 0;
for (int n=0; n<nSplashes; n++)
{
SSplash *spl = pSplashes[n];
fSplash += sCalcSplash(spl, fX, fY);
}
pTZ[1] = fSplash; // / (float)nSplashes;
pTZ += nStep*2;
}
}
}
return pHM;
}
void CREOcean::mfReset()
{
for (int i=0; i<NUM_OCEANVBS; i++)
{
IDirect3DVertexBuffer9* vb = (IDirect3DVertexBuffer9*)m_pVertsPool[i];
SAFE_RELEASE(vb);
m_pVertsPool[i] = NULL;
}
if (m_pBuffer)
{
gRenDev->ReleaseBuffer(m_pBuffer);
m_pBuffer = NULL;
}
}
void CREOcean::InitVB()
{
CD3D9Renderer *r = gcpRendD3D;
LPDIRECT3DDEVICE9 dv = gcpRendD3D->mfGetD3DDevice();
HRESULT h;
m_nNumVertsInPool = (OCEANGRID+1)*(OCEANGRID+1);
int size = m_nNumVertsInPool * sizeof(struct_VERTEX_FORMAT_TEX2F);
for (int i=0; i<NUM_OCEANVBS; i++)
{
h = dv->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_TEX1, D3DPOOL_DEFAULT, (IDirect3DVertexBuffer9**)&m_pVertsPool[i], NULL);
}
m_nCurVB = 0;
m_bLockedVB = false;
{
D3DVERTEXELEMENT9 elem[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, // position
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, // normal
D3DDECL_END()
};
h = dv->CreateVertexDeclaration(&elem[0], (IDirect3DVertexDeclaration9**)&m_VertDecl);
}
{
D3DVERTEXELEMENT9 elem[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, // position
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, // normal
{1, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0}, // heightmpa/splashes
D3DDECL_END()
};
h = dv->CreateVertexDeclaration(&elem[0], (IDirect3DVertexDeclaration9**)&m_VertDeclHeightSplash);
}
}
struct_VERTEX_FORMAT_TEX2F *CREOcean::GetVBPtr(int nVerts)
{
HRESULT h;
struct_VERTEX_FORMAT_TEX2F *pVertices = NULL;
if (nVerts > m_nNumVertsInPool)
{
assert(0);
return NULL;
}
if (m_bLockedVB)
UnlockVBPtr();
m_nCurVB++;
if (m_nCurVB >= NUM_OCEANVBS)
m_nCurVB = 0;
IDirect3DVertexBuffer9 *pVB = (IDirect3DVertexBuffer9 *)m_pVertsPool[m_nCurVB];
h = pVB->Lock(0, 0, (void **) &pVertices, D3DLOCK_DISCARD);
m_bLockedVB = true;
return pVertices;
}
void CREOcean::UnlockVBPtr()
{
if (m_bLockedVB)
{
IDirect3DVertexBuffer9 *pVB = (IDirect3DVertexBuffer9 *)m_pVertsPool[m_nCurVB];
HRESULT hr = pVB->Unlock();
m_bLockedVB = false;
}
}
void CREOcean::mfDrawOceanSectors()
{
float x, y;
CD3D9Renderer *r = gcpRendD3D;
LPDIRECT3DDEVICE9 dv = gcpRendD3D->mfGetD3DDevice();
HRESULT h;
CVertexBuffer *vb = m_pBuffer;
int i;
m_RS.m_StatsNumRendOceanSectors = 0;
ushort *saveInds = r->m_RP.m_RendIndices;
I3DEngine *eng = (I3DEngine *)iSystem->GetI3DEngine();
float fMaxDist = eng->GetMaxViewDistance() / 1.0f;
CCamera cam = r->GetCamera();
Vec3d mins;
Vec3d maxs;
Vec3d cameraPos = cam.GetPos();
float fCurX = (float)((int)cameraPos[0] & ~255) + 128.0f;
float fCurY = (float)((int)cameraPos[1] & ~255) + 128.0f;
float fSize = (float)CRenderer::CV_r_oceansectorsize;
float fHeightScale = (float)CRenderer::CV_r_oceanheightscale;
fMaxDist = (float)((int)(fMaxDist / fSize + 1.0f)) * fSize;
if (fSize != m_fSectorSize)
{
m_fSectorSize = fSize;
for (int i=0; i<256; i++)
{
m_OceanSectorsHash[i].Free();
}
}
float fWaterLevel = eng->GetWaterLevel();
CVProgram *vp = NULL;
int nMaxSplashes = CLAMP(CRenderer::CV_r_oceanmaxsplashes, 0, 16);
//x = y = 0;
//x = fCurX;
//y = fCurY;
m_VisOceanSectors.SetUse(0);
int osNear = -1;
int nMinLod = 65536;
for (y=fCurY-fMaxDist; y<fCurY+fMaxDist; y+=fSize)
{
for (x=fCurX-fMaxDist; x<fCurX+fMaxDist; x+=fSize)
{
SOceanSector *os = GetSectorByPos(x, y);
if (!(os->m_Flags & (OSF_FIRSTTIME | OSF_VISIBLE)))
continue;
mins.x = x+m_MinBound.x*fSize;
mins.y = y+m_MinBound.y*fSize;
mins.z = fWaterLevel+m_MinBound.z*fHeightScale;
maxs.x = x+fSize+m_MaxBound.x*fSize;
maxs.y = y+fSize+m_MaxBound.y*fSize;
maxs.z = fWaterLevel+m_MaxBound.z*fHeightScale;
int cull = cam.IsAABBVisible_hierarchical( AABB(mins,maxs) );
if (cull != CULL_EXCLUSION)
{
Vec3d vCenter = (mins + maxs) * 0.5f;
os->nLod = GetLOD(cameraPos, vCenter);
if (os->nLod < nMinLod)
{
nMinLod = os->nLod;
osNear = m_VisOceanSectors.Num();
}
os->m_Frame = gRenDev->m_cEF.m_Frame;
os->m_Flags &= ~OSF_LODUPDATED;
m_VisOceanSectors.AddElem(os);
}
}
}
if (m_VisOceanSectors.Num())
{
LinkVisSectors(fSize);
::Sort(&m_VisOceanSectors[0], m_VisOceanSectors.Num());
}
int nCurSize;
bool bCurNeedBuffer = false;
h = dv->SetVertexDeclaration((LPDIRECT3DVERTEXDECLARATION9)m_VertDecl);
float *pHM, *pTZ;
int nIndVP = CRenderer::CV_r_waterreflections ? 0 : 1;
for (i=0; i<m_VisOceanSectors.Num(); i++)
{
SOceanSector *os = m_VisOceanSectors[i];
// if ((int)os != 0x1ac32240 && (int)os != 0xe985fc8)
// continue;
int nLod = os->nLod;
bool bL = (nLod < GetSectorByPos(os->x-fSize, os->y)->nLod);
bool bR = (nLod < GetSectorByPos(os->x+fSize, os->y)->nLod);
bool bT = (nLod < GetSectorByPos(os->x, os->y+fSize)->nLod);
bool bB = (nLod < GetSectorByPos(os->x, os->y-fSize)->nLod);
int nLodCode = nLod + (bL<<LOD_LEFTSHIFT) + (bR<<LOD_RIGHTSHIFT) + (bT<<LOD_TOPSHIFT) + (bB<<LOD_BOTTOMSHIFT);
if (!m_OceanIndicies[nLodCode])
GenerateIndices(nLodCode);
int nSplashes = 0;
SSplash *pSplashes[16];
int nS;
for (nS=0; nS<r->m_RP.m_Splashes.Num(); nS++)
{
SSplash *spl = &r->m_RP.m_Splashes[nS];
float fCurRadius = spl->m_fCurRadius;
if (spl->m_Pos[0]-fCurRadius > os->x+fSize ||
spl->m_Pos[1]-fCurRadius > os->y+fSize ||
spl->m_Pos[0]+fCurRadius < os->x ||
spl->m_Pos[1]+fCurRadius < os->y)
continue;
pSplashes[nSplashes++] = spl;
if (nSplashes == nMaxSplashes)
break;
}
if (os->m_Flags & OSF_FIRSTTIME)
{
pTZ = (float *)GetVBPtr((OCEANGRID+1)*(OCEANGRID+1));
pHM = pTZ;
float fMinLevel = 99999.0f;
bool bBlend = false;
bool bNeedHeights = false;
for (uint ty=0; ty<OCEANGRID+1; ty++)
{
for (uint tx=0; tx<OCEANGRID+1; tx++)
{
float fX = m_Pos[ty][tx][0]*fSize+os->x;
float fY = m_Pos[ty][tx][1]*fSize+os->y;
float fZ = GetHMap(fX, fY);
pTZ[0] = fZ;
pTZ += 2;
fMinLevel = min(fMinLevel, fZ);
if (!bBlend && fWaterLevel-fZ <= 1.0f)
bBlend = true;
if (fWaterLevel-fZ < 16.0f)
bNeedHeights = true;
}
}
os->m_Flags &= ~OSF_FIRSTTIME;
if (fMinLevel <= fWaterLevel)
os->m_Flags |= OSF_VISIBLE;
//bNeedHeights = bBlend = false;
if (bNeedHeights)
os->m_Flags |= OSF_NEEDHEIGHTS;
if (bBlend)
{
os->m_Flags |= OSF_BLEND;
os->RenderState = GS_DEPTHWRITE | GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA;
}
else
os->RenderState = GS_DEPTHWRITE;
}
else
if ((os->m_Flags & OSF_NEEDHEIGHTS) || nSplashes)
pHM = mfFillAdditionalBuffer(os, nSplashes, pSplashes, nCurSize, nLod, fSize);
m_RS.m_StatsNumRendOceanSectors++;
r->EF_SetState(os->RenderState);
int nVP = 0;
if (os->m_Flags & OSF_NEEDHEIGHTS)
nVP += OVP_HEIGHT;
if (nSplashes)
nVP++;
CVProgram *curVP = m_VPs[nVP];
if (!curVP)
continue;
if (vp != curVP)
{
vp = curVP;
vp->mfSet(true, NULL, 0);
}
int nFloats = (os->m_Flags & OSF_NEEDHEIGHTS) ? 1 : 0;
if (nSplashes)
nFloats++;
UnlockVBPtr();
if (nFloats)
{
IDirect3DVertexBuffer9 *pVB = (IDirect3DVertexBuffer9 *)m_pVertsPool[m_nCurVB];
h = dv->SetStreamSource(1, pVB, 0, sizeof(struct_VERTEX_FORMAT_TEX2F));
if (!bCurNeedBuffer)
{
h = dv->SetVertexDeclaration((LPDIRECT3DVERTEXDECLARATION9)m_VertDeclHeightSplash);
bCurNeedBuffer = true;
}
}
else
if (bCurNeedBuffer)
{
h = dv->SetStreamSource(1, NULL, 0, 0);
h = dv->SetVertexDeclaration((LPDIRECT3DVERTEXDECLARATION9)m_VertDecl);
bCurNeedBuffer = false;
}
float param[4];
param[0] = os->x;
param[1] = os->y;
param[2] = 0;
param[3] = 0;
CCGVProgram_D3D *vpD3D = (CCGVProgram_D3D *)vp;
SCGBind *pBind = vpD3D->mfGetParameterBind("PosOffset");
if (pBind)
vpD3D->mfParameter4f(pBind, param);
pBind = vpD3D->mfGetParameterBind("PosScale");
param[0] = fSize;
param[1] = fSize;
param[2] = fHeightScale;
param[3] = 1;
if (pBind)
vpD3D->mfParameter4f(pBind, param);
/*if (nSplashes)
{
static Vec3d sPos;
static float sTime;
sPos = Vec3d(306, 1942, 0);
if ((GetAsyncKeyState(VK_NUMPAD1) & 0x8000))
sTime = r->m_RP.m_RealTime;
float fForce = 1.5f;
cgBindIter *pBind = vpGL->mfGetParameterBind("Splash1");
if (pBind)
{
param[0] = sPos[0];
param[1] = sPos[1];
param[2] = sPos[2];
param[3] = 0;
vpGL->mfParameter4f(pBind, param);
}
pBind = vpGL->mfGetParameterBind("Time");
if (pBind)
{
float fDeltaTime = r->m_RP.m_RealTime - sTime;
float fScaleFactor = 1.0f / (r->m_RP.m_RealTime - sTime + 1.0f);
param[0] = fForce * fScaleFactor;
param[1] = 0;
param[2] = -fDeltaTime*10;
param[3] = fDeltaTime*10.0f;
vpGL->mfParameter4f(pBind, param);
}
}*/
DrawOceanSector(m_OceanIndicies[nLodCode]);
}
}
void CREOcean::mfDrawOceanScreenLod()
{
}
bool CREOcean::mfDraw(SShader *ef, SShaderPass *sfm)
{
double time0 = 0;
ticks(time0);
if (!m_pVertsPool[0])
InitVB();
if (!m_pBuffer)
m_pBuffer = gRenDev->CreateBuffer((OCEANGRID+1)*(OCEANGRID+1), VERTEX_FORMAT_P3F_N, "Ocean", true);
if (CRenderer::CV_r_oceanrendtype == 0)
mfDrawOceanSectors();
else
mfDrawOceanScreenLod();
unticks(time0);
m_RS.m_StatsTimeRendOcean = (float)(time0*1000.0*g_SecondsPerCycle);
// gRenDev->PostLoad();
return true;
}
bool CREOcean::mfPreDraw(SShaderPass *sl)
{
CVertexBuffer *vb = m_pBuffer;
for (int i=0; i<VSF_NUM; i++)
{
if (vb->m_VS[i].m_bLocked)
gcpRendD3D->UnlockBuffer(vb, i);
}
LPDIRECT3DDEVICE9 dv = gcpRendD3D->mfGetD3DDevice();
HRESULT h;
h = dv->SetStreamSource(0, (IDirect3DVertexBuffer9 *)vb->m_VS[VSF_GENERAL].m_VertBuf.m_pPtr, 0, m_VertexSize[vb->m_vertexformat]);
return true;
}
char BoxSides[0x40*8] = {
0,0,0,0, 0,0,0,0, //00
0,4,6,2, 0,0,0,4, //01
7,5,1,3, 0,0,0,4, //02
0,0,0,0, 0,0,0,0, //03
0,1,5,4, 0,0,0,4, //04
0,1,5,4, 6,2,0,6, //05
7,5,4,0, 1,3,0,6, //06
0,0,0,0, 0,0,0,0, //07
7,3,2,6, 0,0,0,4, //08
0,4,6,7, 3,2,0,6, //09
7,5,1,3, 2,6,0,6, //0a
0,0,0,0, 0,0,0,0, //0b
0,0,0,0, 0,0,0,0, //0c
0,0,0,0, 0,0,0,0, //0d
0,0,0,0, 0,0,0,0, //0e
0,0,0,0, 0,0,0,0, //0f
0,2,3,1, 0,0,0,4, //10
0,4,6,2, 3,1,0,6, //11
7,5,1,0, 2,3,0,6, //12
0,0,0,0, 0,0,0,0, //13
0,2,3,1, 5,4,0,6, //14
1,5,4,6, 2,3,0,6, //15
7,5,4,0, 2,3,0,6, //16
0,0,0,0, 0,0,0,0, //17
0,2,6,7, 3,1,0,6, //18
0,4,6,7, 3,1,0,6, //19
7,5,1,0, 2,6,0,6, //1a
0,0,0,0, 0,0,0,0, //1b
0,0,0,0, 0,0,0,0, //1c
0,0,0,0, 0,0,0,0, //1d
0,0,0,0, 0,0,0,0, //1e
0,0,0,0, 0,0,0,0, //1f
7,6,4,5, 0,0,0,4, //20
0,4,5,7, 6,2,0,6, //21
7,6,4,5, 1,3,0,6, //22
0,0,0,0, 0,0,0,0, //23
7,6,4,0, 1,5,0,6, //24
0,1,5,7, 6,2,0,6, //25
7,6,4,0, 1,3,0,6, //26
0,0,0,0, 0,0,0,0, //27
7,3,2,6, 4,5,0,6, //28
0,4,5,7, 3,2,0,6, //29
6,4,5,1, 3,2,0,6, //2a
0,0,0,0, 0,0,0,0, //2b
0,0,0,0, 0,0,0,0, //2c
0,0,0,0, 0,0,0,0, //2d
0,0,0,0, 0,0,0,0, //2e
0,0,0,0, 0,0,0,0, //2f
0,0,0,0, 0,0,0,0, //30
0,0,0,0, 0,0,0,0, //31
0,0,0,0, 0,0,0,0, //32
0,0,0,0, 0,0,0,0, //33
0,0,0,0, 0,0,0,0, //34
0,0,0,0, 0,0,0,0, //35
0,0,0,0, 0,0,0,0, //36
0,0,0,0, 0,0,0,0, //37
0,0,0,0, 0,0,0,0, //38
0,0,0,0, 0,0,0,0, //39
0,0,0,0, 0,0,0,0, //3a
0,0,0,0, 0,0,0,0, //3b
0,0,0,0, 0,0,0,0, //3c
0,0,0,0, 0,0,0,0, //3d
0,0,0,0, 0,0,0,0, //3e
0,0,0,0, 0,0,0,0, //3f
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,73 @@
#ifndef D3DSETTINGS_H
#define D3DSETTINGS_H
//-----------------------------------------------------------------------------
// Name: class CD3DSettings
// Desc: Current D3D settings: adapter, device, mode, formats, etc.
//-----------------------------------------------------------------------------
class CD3DSettings
{
public:
bool IsWindowed;
D3DAdapterInfo* pWindowed_AdapterInfo;
D3DDeviceInfo* pWindowed_DeviceInfo;
D3DDeviceCombo* pWindowed_DeviceCombo;
D3DDISPLAYMODE Windowed_DisplayMode; // not changable by the user
D3DFORMAT Windowed_DepthStencilBufferFormat;
D3DMULTISAMPLE_TYPE Windowed_MultisampleType;
DWORD Windowed_MultisampleQuality;
VertexProcessingType Windowed_VertexProcessingType;
UINT Windowed_PresentInterval;
int Windowed_Width;
int Windowed_Height;
D3DAdapterInfo* pFullscreen_AdapterInfo;
D3DDeviceInfo* pFullscreen_DeviceInfo;
D3DDeviceCombo* pFullscreen_DeviceCombo;
D3DDISPLAYMODE Fullscreen_DisplayMode; // changable by the user
D3DFORMAT Fullscreen_DepthStencilBufferFormat;
D3DMULTISAMPLE_TYPE Fullscreen_MultisampleType;
DWORD Fullscreen_MultisampleQuality;
VertexProcessingType Fullscreen_VertexProcessingType;
UINT Fullscreen_PresentInterval;
D3DAdapterInfo* PAdapterInfo() { return IsWindowed ? pWindowed_AdapterInfo : pFullscreen_AdapterInfo; }
D3DDeviceInfo* PDeviceInfo() { return IsWindowed ? pWindowed_DeviceInfo : pFullscreen_DeviceInfo; }
D3DDeviceCombo* PDeviceCombo() { return IsWindowed ? pWindowed_DeviceCombo : pFullscreen_DeviceCombo; }
int AdapterOrdinal() { return PDeviceCombo()->AdapterOrdinal; }
D3DDEVTYPE DevType() { return PDeviceCombo()->DevType; }
D3DFORMAT BackBufferFormat() { return PDeviceCombo()->BackBufferFormat; }
D3DFORMAT AdapterFormat() { return PDeviceCombo()->AdapterFormat; }
D3DDISPLAYMODE DisplayMode() { return IsWindowed ? Windowed_DisplayMode : Fullscreen_DisplayMode; }
void SetDisplayMode(D3DDISPLAYMODE value) { if (IsWindowed) Windowed_DisplayMode = value; else Fullscreen_DisplayMode = value; }
D3DFORMAT DepthStencilBufferFormat() { return IsWindowed ? Windowed_DepthStencilBufferFormat : Fullscreen_DepthStencilBufferFormat; }
void SetDepthStencilBufferFormat(D3DFORMAT value) { if (IsWindowed) Windowed_DepthStencilBufferFormat = value; else Fullscreen_DepthStencilBufferFormat = value; }
D3DMULTISAMPLE_TYPE MultisampleType() { return IsWindowed ? Windowed_MultisampleType : Fullscreen_MultisampleType; }
void SetMultisampleType(D3DMULTISAMPLE_TYPE value) { if (IsWindowed) Windowed_MultisampleType = value; else Fullscreen_MultisampleType = value; }
DWORD MultisampleQuality() { return IsWindowed ? Windowed_MultisampleQuality : Fullscreen_MultisampleQuality; }
void SetMultisampleQuality(DWORD value) { if (IsWindowed) Windowed_MultisampleQuality = value; else Fullscreen_MultisampleQuality = value; }
VertexProcessingType GetVertexProcessingType() { return IsWindowed ? Windowed_VertexProcessingType : Fullscreen_VertexProcessingType; }
void SetVertexProcessingType(VertexProcessingType value) { if (IsWindowed) Windowed_VertexProcessingType = value; else Fullscreen_VertexProcessingType = value; }
UINT PresentInterval() { return IsWindowed ? Windowed_PresentInterval : Fullscreen_PresentInterval; }
void SetPresentInterval(UINT value) { if (IsWindowed) Windowed_PresentInterval = value; else Fullscreen_PresentInterval = value; }
};
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,827 @@
#ifndef __D3DTEXTURE_H
#define __D3DTEXTURE_H
class D3DDataFormat
{
public:
virtual void GetData(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, DWORD& dwValue) { assert(0); };
virtual void SetData(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, DWORD dwValue) { assert(0); };
virtual void GetColors(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, float& fRed, float& fGreen, float& fBlue, float& fAlpha) { assert(0); };
virtual void SetColors(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, float fRed, float fGreen, float fBlue, float fAlpha) { assert(0); };
virtual void GetLuminance(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, float& Luminance) { assert(0); };
virtual void SetLuminance(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, float Luminance) { assert(0); };
virtual void GetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, D3DXVECTOR3& inVector) { assert(0); };
virtual void SetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, const D3DXVECTOR3& inVector) { assert(0); };
};
class D3DDataFormat_32Bit : public D3DDataFormat
{
public:
virtual void GetData(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, DWORD& dwValue)
{
dwValue = (*(DWORD*) (((BYTE*)LockData.pBits) + (j * LockData.Pitch) + (i * sizeof(DWORD))) );
}
virtual void SetData(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, DWORD dwValue)
{
*(DWORD*)(((BYTE*)LockData.pBits) + (j * LockData.Pitch) + (i * sizeof(DWORD))) = dwValue;
}
};
class D3DDataFormat_16Bit : public D3DDataFormat
{
public:
virtual void GetData(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, DWORD& dwValue)
{
dwValue = ((DWORD)*(WORD*)(((BYTE*)LockData.pBits) + (j * LockData.Pitch) + (i * sizeof(WORD))) );
}
virtual void SetData(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, DWORD dwValue)
{
*(WORD*)(((BYTE*)LockData.pBits) + (j * LockData.Pitch) + (i * sizeof(WORD))) = (WORD)dwValue;
}
};
class D3DDataFormat_8Bit : public D3DDataFormat
{
public:
virtual void GetData(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, DWORD& dwValue)
{
dwValue = ((DWORD)*(BYTE*)(((BYTE*)LockData.pBits) + (j * LockData.Pitch) + (i * sizeof(BYTE))) );
}
virtual void SetData(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, DWORD dwValue)
{
*(BYTE*)(((BYTE*)LockData.pBits) + (j * LockData.Pitch) + (i * sizeof(WORD))) = (BYTE)dwValue;
}
};
class D3DDataFormat_A8R8G8B8 : public D3DDataFormat_32Bit
{
public:
virtual void GetColors(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, float& fRed, float& fGreen, float& fBlue, float& fAlpha)
{
DWORD dwValue;
GetData(LockData, i, j, dwValue);
fBlue = ((float)(dwValue & 0xFF))/ 255.0f;
fGreen = ((float)((dwValue >> 8) & 0xFF)) / 255.0f;
fRed = ((float)((dwValue >> 16) & 0xFF)) / 255.0f;
fAlpha = ((float)((dwValue >> 24) & 0xFF)) / 255.0f;
}
virtual void GetLuminance(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, float& Luminance)
{
float fRed, fGreen, fBlue, fAlpha;
GetColors(LockData, i, j, fRed, fGreen, fBlue, fAlpha);
Luminance = ((fRed * 0.3f) + (fGreen * 0.59f) + (fBlue * 0.11f));
}
virtual void SetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, const D3DXVECTOR3& inVector)
{
D3DXVECTOR3 vecScaled = (inVector + D3DXVECTOR3(1.0f, 1.0f, 1.0f)) * 127.5f;
BYTE red = (BYTE)vecScaled.x;
BYTE green = (BYTE)vecScaled.y;
BYTE blue = (BYTE)vecScaled.z;
BYTE alpha = 0xFF;
DWORD dwData = (DWORD)( ( (DWORD)alpha << 24 ) | ( (DWORD)red << 16 ) | ( (DWORD)green << 8 ) | ( (DWORD)blue << 0) );
SetData(LockData, i, j, dwData);
}
virtual void GetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, D3DXVECTOR3& outVector)
{
DWORD dwData;
GetData(LockData, i, j, dwData);
outVector.x = (float)((dwData >> 16) & 0xFF);
outVector.y = (float)((dwData >> 8) & 0xFF);
outVector.z = (float)((dwData) & 0xFF);
outVector /= 127.5f;
outVector -= D3DXVECTOR3(1.0f, 1.0f, 1.0f);
}
};
class D3DDataFormat_X8R8G8B8 : public D3DDataFormat_32Bit
{
public:
virtual void GetColors(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, float& fRed, float& fGreen, float& fBlue, float& fAlpha)
{
DWORD dwValue;
GetData(LockData, i, j, dwValue);
fBlue = ((float)(dwValue & 0xFF))/ 255.0f;
fGreen = ((float)((dwValue >> 8) & 0xFF)) / 255.0f;
fRed = ((float)((dwValue >> 16) & 0xFF)) / 255.0f;
fAlpha = 1.0f;
}
virtual void GetLuminance(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, float& Luminance)
{
float fRed, fGreen, fBlue, fAlpha;
GetColors(LockData, i, j, fRed, fGreen, fBlue, fAlpha);
Luminance = ((fRed * 0.3f) + (fGreen * 0.59f) + (fBlue * 0.11f));
}
virtual void SetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, const D3DXVECTOR3& inVector)
{
D3DXVECTOR3 vecScaled = (inVector + D3DXVECTOR3(1.0f, 1.0f, 1.0f)) * 127.5f;
BYTE red = (BYTE)vecScaled.x;
BYTE green = (BYTE)vecScaled.y;
BYTE blue = (BYTE)vecScaled.z;
BYTE alpha = 0xFF;
DWORD dwData = (DWORD)( ( (DWORD)alpha << 24 ) | ( (DWORD)red << 16 ) | ( (DWORD)green << 8 ) | ( (DWORD)blue << 0) );
SetData(LockData, i, j, dwData);
}
virtual void GetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, D3DXVECTOR3& outVector)
{
DWORD dwData;
GetData(LockData, i, j, dwData);
outVector.x = (float)((dwData >> 16) & 0xFF);
outVector.y = (float)((dwData >> 8) & 0xFF);
outVector.z = (float)((dwData) & 0xFF);
outVector /= 127.5f;
outVector -= D3DXVECTOR3(1.0f, 1.0f, 1.0f);
}
};
class D3DDataFormat_Q8W8V8U8 : public D3DDataFormat_32Bit
{
virtual void SetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, const D3DXVECTOR3& inVector)
{
D3DXVECTOR3 vecScaled = inVector * 127.5f;
signed char red = (signed char)vecScaled.x;
signed char green = (signed char)vecScaled.y;
signed char blue = (signed char)vecScaled.z;
signed char alpha = 0;
DWORD dwData = (DWORD)( ( (DWORD)(unsigned char)alpha << 24 ) | ( (DWORD)(unsigned char)blue << 16 ) | ( (DWORD)(unsigned char)green << 8 ) | ( (DWORD)(unsigned char)red << 0) );
SetData(LockData, i, j, dwData);
}
virtual void GetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, D3DXVECTOR3& outVector)
{
DWORD dwData;
GetData(LockData, i, j, dwData);
outVector.x = (float)(signed char)((dwData) & 0xFF);
outVector.y = (float)(signed char)((dwData >> 8) & 0xFF);
outVector.z = (float)(signed char)((dwData >> 16) & 0xFF);
outVector /= 127.5f;
}
};
class D3DDataFormat_X8L8V8U8 : public D3DDataFormat_32Bit
{
virtual void SetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, const D3DXVECTOR3& inVector)
{
D3DXVECTOR3 vecScaled = inVector * 127.5f;
signed char red = (signed char)vecScaled.x;
signed char green = (signed char)vecScaled.y;
signed char blue = (signed char)vecScaled.z;
signed char alpha = 0;
DWORD dwData = (DWORD)( ( (DWORD)(unsigned char)alpha << 24 ) | ( (DWORD)(unsigned char)blue << 16 ) | ( (DWORD)(unsigned char)green << 8 ) | ( (DWORD)(unsigned char)red << 0) );
SetData(LockData, i, j, dwData);
}
virtual void GetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, D3DXVECTOR3& outVector)
{
DWORD dwData;
GetData(LockData, i, j, dwData);
outVector.x = (float)(signed char)((dwData) & 0xFF);
outVector.y = (float)(signed char)((dwData >> 8) & 0xFF);
outVector.z = (float)(signed char)((dwData >> 16) & 0xFF);
outVector /= 127.5f;
}
};
class D3DDataFormat_D3DHS : public D3DDataFormat_32Bit
{
virtual void SetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, const D3DXVECTOR3& inVector)
{
D3DXVECTOR3 vecScaled = inVector * 32767.0f;
signed short h = (signed short)vecScaled.x;
signed short l = (signed short)vecScaled.y;
DWORD dwData = ( ( (DWORD)(unsigned short)h << 16 ) | ( (DWORD)(unsigned short)l << 0 ) );
SetData(LockData, i, j, dwData);
}
virtual void GetVector(const D3DLOCKED_RECT& LockData, DWORD i, DWORD j, D3DXVECTOR3& outVector)
{
DWORD dwData;
GetData(LockData, i, j, dwData);
outVector.x = (float)(unsigned short)((dwData >> 16) & 0xFFFF);
outVector.y = (float)(unsigned short)((dwData) & 0xFFFF);
outVector.z = 1.0f;
outVector /= 32767.0f;
}
};
class D3D2DTextureLocker
{
public:
enum
{
MAX_LOCK_LEVELS = 12
};
D3D2DTextureLocker(LPDIRECT3DTEXTURE9 pTexture)
: m_pTexture(pTexture),
m_pDataFormat(NULL)
{
m_pTexture->AddRef();
for (DWORD i=0; i < MAX_LOCK_LEVELS; i++)
{
m_bLocked[i] = false;
}
m_dwLevels = m_pTexture->GetLevelCount();
D3DSURFACE_DESC LevelDesc;
m_pTexture->GetLevelDesc(0, &LevelDesc);
switch(LevelDesc.Format)
{
case D3DFMT_UNKNOWN:
case D3DFMT_VERTEXDATA:
case D3DFMT_INDEX16:
#ifndef _XBOX
case D3DFMT_INDEX32:
#endif
case D3DFMT_DXT1:
case D3DFMT_DXT2:
#ifndef _XBOX
case D3DFMT_DXT3:
#endif
case D3DFMT_DXT4:
#ifndef _XBOX
case D3DFMT_DXT5:
default:
assert(!"Don't understand surface format");
break;
case D3DFMT_R8G8B8:
assert(!"Don't handle 24 bit surfaces");
break;
case D3DFMT_X8L8V8U8:
m_pDataFormat = new D3DDataFormat_X8L8V8U8;
break;
#endif
case D3DFMT_A8R8G8B8:
m_pDataFormat = new D3DDataFormat_A8R8G8B8;
break;
case D3DFMT_X8R8G8B8:
m_pDataFormat = new D3DDataFormat_X8R8G8B8;
break;
case D3DFMT_Q8W8V8U8:
m_pDataFormat = new D3DDataFormat_Q8W8V8U8;
break;
case MAKEFOURCC('N', 'V', 'H', 'S'):
m_pDataFormat = new D3DDataFormat_D3DHS;
break;
}
assert(m_pDataFormat);
}
virtual ~D3D2DTextureLocker()
{
for (DWORD i = 0; i < MAX_LOCK_LEVELS; i++)
{
if (m_bLocked[i])
{
Unlock(i);
}
}
SAFE_RELEASE(m_pTexture);
SAFE_DELETE(m_pDataFormat);
}
bool Lock(DWORD dwLevel)
{
HRESULT hr;
assert(dwLevel < m_dwLevels);
assert(!m_bLocked[dwLevel]);
m_bLocked[dwLevel] = true;
hr = m_pTexture->LockRect(dwLevel, &m_LockData[dwLevel], NULL, 0);
m_pTexture->GetLevelDesc(dwLevel, &m_LevelDesc[dwLevel]);
if (FAILED(hr))
return false;
return true;
}
bool Unlock(DWORD dwLevel)
{
HRESULT hr;
assert(dwLevel < m_dwLevels);
assert(m_bLocked[dwLevel]);
m_bLocked[dwLevel] = false;
hr = m_pTexture->UnlockRect(dwLevel);
if (FAILED(hr))
return false;
return true;
}
void WrapAddress(DWORD dwLevel, DWORD& i, DWORD& j)
{
if (i >= 0)
{
i = (i % m_LevelDesc[dwLevel].Width);
}
else
{
i = (m_LevelDesc[dwLevel].Width - 1) + (i % m_LevelDesc[dwLevel].Width);
}
if (j >= 0)
{
j = (j % m_LevelDesc[dwLevel].Height);
}
else
{
j = (m_LevelDesc[dwLevel].Height - 1) + (j % m_LevelDesc[dwLevel].Height);
}
assert(i >= 0);
assert(j >= 0);
assert(i < m_LevelDesc[dwLevel].Width);
assert(j < m_LevelDesc[dwLevel].Height);
}
void GetMapData(DWORD dwLevel, DWORD i, DWORD j, DWORD& dwValue)
{
assert(m_bLocked[dwLevel]);
WrapAddress(dwLevel, i, j);
m_pDataFormat->GetData(m_LockData[dwLevel], i, j, dwValue);
}
void SetMapData(DWORD dwLevel, DWORD i, DWORD j, DWORD dwValue)
{
assert(m_bLocked[dwLevel]);
WrapAddress(dwLevel, i, j);
m_pDataFormat->SetData(m_LockData[dwLevel], i, j, dwValue);
}
void GetMapColors(DWORD dwLevel, DWORD i, DWORD j, float& fRed, float& fGreen, float& fBlue, float& fAlpha)
{
assert(m_bLocked[dwLevel]);
WrapAddress(dwLevel, i, j);
m_pDataFormat->GetColors(m_LockData[dwLevel], i, j, fRed, fGreen, fBlue, fAlpha);
}
void GetMapLuminance(DWORD dwLevel, DWORD i, DWORD j, float& Luminance)
{
assert(m_bLocked[dwLevel]);
WrapAddress(dwLevel, i, j);
m_pDataFormat->GetLuminance(m_LockData[dwLevel], i, j, Luminance);
}
void SetMapVector(DWORD dwLevel, DWORD i, DWORD j, const D3DXVECTOR3& inVector)
{
assert(m_bLocked[dwLevel]);
WrapAddress(dwLevel, i, j);
m_pDataFormat->SetVector(m_LockData[dwLevel], i, j, inVector);
}
void GetMapVector(DWORD dwLevel, DWORD i, DWORD j, D3DXVECTOR3& inVector)
{
assert(m_bLocked[dwLevel]);
WrapAddress(dwLevel, i, j);
m_pDataFormat->GetVector(m_LockData[dwLevel], i, j, inVector);
}
private:
D3DDataFormat* m_pDataFormat;
DWORD m_dwLevels;
bool m_bLocked[MAX_LOCK_LEVELS];
D3DLOCKED_RECT m_LockData[MAX_LOCK_LEVELS];
D3DSURFACE_DESC m_LevelDesc[MAX_LOCK_LEVELS];
LPDIRECT3DTEXTURE9 m_pTexture;
};
class D3D2DSurfaceLocker
{
public:
D3D2DSurfaceLocker(LPDIRECT3DSURFACE9 pSurface)
: m_pSurface(pSurface),
m_pDataFormat(NULL)
{
m_pSurface->AddRef();
m_bLocked = false;
m_pSurface->GetDesc(&m_LevelDesc);
switch(m_LevelDesc.Format)
{
case D3DFMT_UNKNOWN:
case D3DFMT_VERTEXDATA:
case D3DFMT_INDEX16:
#ifndef _XBOX
case D3DFMT_INDEX32:
#endif
#ifndef _XBOX
case D3DFMT_DXT1:
case D3DFMT_DXT2:
case D3DFMT_DXT3:
case D3DFMT_DXT4:
case D3DFMT_DXT5:
default:
assert(!"Don't understand surface format");
break;
case D3DFMT_R8G8B8:
assert(!"Don't handle 24 bit surfaces");
break;
case D3DFMT_X8L8V8U8:
m_pDataFormat = new D3DDataFormat_X8L8V8U8;
break;
#endif
case D3DFMT_A8R8G8B8:
m_pDataFormat = new D3DDataFormat_A8R8G8B8;
break;
case D3DFMT_X8R8G8B8:
m_pDataFormat = new D3DDataFormat_X8R8G8B8;
break;
case D3DFMT_Q8W8V8U8:
m_pDataFormat = new D3DDataFormat_Q8W8V8U8;
break;
case MAKEFOURCC('N', 'V', 'H', 'S'):
m_pDataFormat = new D3DDataFormat_D3DHS;
break;
}
assert(m_pDataFormat);
}
virtual ~D3D2DSurfaceLocker()
{
if (m_bLocked)
{
Unlock();
}
SAFE_RELEASE(m_pSurface);
SAFE_DELETE(m_pDataFormat);
}
bool Lock()
{
HRESULT hr;
assert(!m_bLocked);
m_bLocked = true;
hr = m_pSurface->LockRect(&m_LockData, NULL, 0);
if (FAILED(hr))
return false;
return true;
}
bool Unlock()
{
HRESULT hr;
assert(m_bLocked);
m_bLocked = false;
hr = m_pSurface->UnlockRect();
if (FAILED(hr))
return false;
return true;
}
void WrapAddress(DWORD& i, DWORD& j)
{
if (i >= 0)
{
i = (i % m_LevelDesc.Width);
}
else
{
i = (m_LevelDesc.Width - 1) + (i % m_LevelDesc.Width);
}
if (j >= 0)
{
j = (j % m_LevelDesc.Height);
}
else
{
j = (m_LevelDesc.Height - 1) + (j % m_LevelDesc.Height);
}
assert(i >= 0);
assert(j >= 0);
assert(i < m_LevelDesc.Width);
assert(j < m_LevelDesc.Height);
}
void GetMapData(DWORD i, DWORD j, DWORD& dwValue)
{
assert(m_bLocked);
WrapAddress(i, j);
m_pDataFormat->GetData(m_LockData, i, j, dwValue);
}
void SetMapData(DWORD i, DWORD j, DWORD dwValue)
{
assert(m_bLocked);
WrapAddress(i, j);
m_pDataFormat->SetData(m_LockData, i, j, dwValue);
}
void GetMapColors(DWORD i, DWORD j, float& fRed, float& fGreen, float& fBlue, float& fAlpha)
{
assert(m_bLocked);
WrapAddress(i, j);
m_pDataFormat->GetColors(m_LockData, i, j, fRed, fGreen, fBlue, fAlpha);
}
void GetMapLuminance(DWORD i, DWORD j, float& Luminance)
{
assert(m_bLocked);
WrapAddress(i, j);
m_pDataFormat->GetLuminance(m_LockData, i, j, Luminance);
}
void SetMapVector(DWORD i, DWORD j, const D3DXVECTOR3& inVector)
{
assert(m_bLocked);
WrapAddress(i, j);
m_pDataFormat->SetVector(m_LockData, i, j, inVector);
}
void GetMapVector(DWORD i, DWORD j, D3DXVECTOR3& inVector)
{
assert(m_bLocked);
WrapAddress(i, j);
m_pDataFormat->GetVector(m_LockData, i, j, inVector);
}
private:
D3DDataFormat* m_pDataFormat;
bool m_bLocked;
D3DSURFACE_DESC m_LevelDesc;
D3DLOCKED_RECT m_LockData;
LPDIRECT3DSURFACE9 m_pSurface;
};
class CD3DTexture
{
public:
// Gets height from luminance value
static LPDIRECT3DTEXTURE9 CreateNormalMap(LPDIRECT3DDEVICE9 pD3DDev, LPDIRECT3DTEXTURE9 pSource, STexPic *ti, bool bMips, D3DXVECTOR3 Scale, D3DFORMAT Format = D3DFMT_Q8W8V8U8, D3DPOOL Pool = D3DPOOL_MANAGED)
{
LPDIRECT3DTEXTURE9 pNormalMap = NULL;
D3DSURFACE_DESC ddsdDescDest;
D3DSURFACE_DESC ddsdDescSource;
D3DXVECTOR3 Normal;
HRESULT hr;
DWORD i, j;
LPDIRECT3DTEXTURE9 pNewTex = NULL;
assert(pSource && pSource->GetType() == D3DRTYPE_TEXTURE);
if (!pSource)
return NULL;
(pSource)->GetLevelDesc(0, &ddsdDescSource);
// Handle conversion from compressed to specified format
switch(ddsdDescSource.Format)
{
default:
break;
case D3DFMT_DXT1:
case D3DFMT_DXT3:
case D3DFMT_DXT5:
{
hr = D3DXCreateTexture(pD3DDev, ddsdDescSource.Width, ddsdDescSource.Height, bMips ? D3DX_DEFAULT : 1, 0, Format, D3DPOOL_SYSTEMMEM, &pNewTex);
if (FAILED(hr))
return NULL;
// Copy the levels to RGB textures
for (i = 0; i < 1; i++)
{
LPDIRECT3DSURFACE9 pDestSurf;
LPDIRECT3DSURFACE9 pSourceSurf;
pNewTex->GetSurfaceLevel(i, &pDestSurf);
pSource->GetSurfaceLevel(i, &pSourceSurf);
D3DXLoadSurfaceFromSurface(pDestSurf, NULL, NULL, pSourceSurf, NULL, NULL, D3DX_FILTER_NONE, 0);
SAFE_RELEASE(pDestSurf);
SAFE_RELEASE(pSourceSurf);
}
pSource = pNewTex;
}
break;
}
hr = D3DXCreateTexture(pD3DDev, ddsdDescSource.Width, ddsdDescSource.Height, bMips ? D3DX_DEFAULT : 1, 0, Format, Pool, &pNormalMap );
if (FAILED(hr))
{
SAFE_RELEASE(pNewTex);
return NULL;
}
D3D2DTextureLocker SourceLocker(pSource);
D3D2DTextureLocker DestLocker(pNormalMap);
for (DWORD Level = 0; Level < 1; Level++)
{
pNormalMap->GetLevelDesc(Level, &ddsdDescDest);
DWORD dwWidth = ddsdDescDest.Width;
DWORD dwHeight = ddsdDescDest.Height;
SourceLocker.Lock(Level);
DestLocker.Lock(Level);
for(i=0; i < dwWidth; i++)
{
for(j = 0; j < dwHeight; j++)
{
float fRight, fLeft, fUp, fDown;
SourceLocker.GetMapLuminance(Level, i + 1, j, fRight);
SourceLocker.GetMapLuminance(Level, i - 1, j, fLeft);
SourceLocker.GetMapLuminance(Level, i, j - 1, fUp);
SourceLocker.GetMapLuminance(Level, i, j + 1, fDown);
D3DXVECTOR3 dfdi(2.f, 0.f, fRight - fLeft);
D3DXVECTOR3 dfdj(0.f, 2.f, fDown - fUp);
D3DXVec3Cross(&Normal, &dfdi, &dfdj);
Normal[0] *= Scale[0];
Normal[1] *= Scale[1];
Normal[2] *= Scale[2];
D3DXVec3Normalize(&Normal, &Normal);
if (ti->m_eTT == eTT_DSDTBump)
Normal[2] = 0.5f;
DestLocker.SetMapVector(Level, i, j, Normal);
}
}
SourceLocker.Unlock(Level);
DestLocker.Unlock(Level);
}
SAFE_RELEASE(pNewTex);
return pNormalMap;
}
static void FilterNormalMap(LPDIRECT3DDEVICE9 pD3DDev, LPDIRECT3DTEXTURE9 pNormalMap)
{
D3DSURFACE_DESC ddsdDescSource;
D3DXVECTOR3 Normal;
DWORD i, j;
D3D2DTextureLocker SurfaceLocker(pNormalMap);
for (DWORD Level = 0; Level < pNormalMap->GetLevelCount() - 1; Level++)
{
SurfaceLocker.Lock(Level);
SurfaceLocker.Lock(Level + 1);
pNormalMap->GetLevelDesc(Level, &ddsdDescSource);
for(i=0; i < ddsdDescSource.Width; i+=2)
{
for(j = 0; j < ddsdDescSource.Height; j+=2)
{
D3DXVECTOR3 Vectors[4];
SurfaceLocker.GetMapVector(Level, i, j, Vectors[0]);
SurfaceLocker.GetMapVector(Level, i+1, j, Vectors[1]);
SurfaceLocker.GetMapVector(Level, i+1, j+1, Vectors[2]);
SurfaceLocker.GetMapVector(Level, i+1, j+1, Vectors[3]);
D3DXVECTOR3 Normal = Vectors[0] + Vectors[1] + Vectors[2] + Vectors[3];
D3DXVec3Normalize(&Normal, &Normal);
SurfaceLocker.SetMapVector(Level + 1, i / 2, j / 2, Normal);
}
}
SurfaceLocker.Unlock(Level);
SurfaceLocker.Unlock(Level + 1);
}
}
static LPDIRECT3DCUBETEXTURE9 CreateNormalizationCubeMap(LPDIRECT3DDEVICE9 pD3DDev, DWORD dwWidth, DWORD dwMipmaps = 0, D3DPOOL Pool = D3DPOOL_MANAGED)
{
HRESULT hr;
LPDIRECT3DCUBETEXTURE9 pCubeTexture;
hr = D3DXCreateCubeTexture(pD3DDev, dwWidth, dwMipmaps, 0, D3DFMT_X8R8G8B8, Pool, &pCubeTexture);
if(FAILED(hr))
{
return NULL;
}
if (dwMipmaps == 0)
dwMipmaps = pCubeTexture->GetLevelCount();
for (DWORD dwLevel = 0; dwLevel < dwMipmaps; dwLevel++)
{
for (int i = 0; i < 6; i++)
{
D3DLOCKED_RECT Locked;
D3DXVECTOR3 Normal;
float w,h;
D3DSURFACE_DESC ddsdDesc;
pCubeTexture->GetLevelDesc(dwLevel, &ddsdDesc);
pCubeTexture->LockRect((D3DCUBEMAP_FACES)i, dwLevel, &Locked, NULL, 0);
for (unsigned int y = 0; y < ddsdDesc.Height; y++)
{
h = (float)y / ((float)(ddsdDesc.Height - 1));
h *= 2.0f;
h -= 1.0f;
for (unsigned int x = 0; x < ddsdDesc.Width; x++)
{
w = (float)x / ((float)(ddsdDesc.Width - 1));
w *= 2.0f;
w -= 1.0f;
DWORD* pBits = (DWORD*)((BYTE*)Locked.pBits + (y * Locked.Pitch));
pBits += x;
switch((D3DCUBEMAP_FACES)i)
{
case D3DCUBEMAP_FACE_POSITIVE_X:
Normal = D3DXVECTOR3(1.0f, -h, -w);
break;
case D3DCUBEMAP_FACE_NEGATIVE_X:
Normal = D3DXVECTOR3(-1.0f, -h, w);
break;
case D3DCUBEMAP_FACE_POSITIVE_Y:
Normal = D3DXVECTOR3(w, 1.0f, h);
break;
case D3DCUBEMAP_FACE_NEGATIVE_Y:
Normal = D3DXVECTOR3(w, -1.0f, -h);
break;
case D3DCUBEMAP_FACE_POSITIVE_Z:
Normal = D3DXVECTOR3(w, -h, 1.0f);
break;
case D3DCUBEMAP_FACE_NEGATIVE_Z:
Normal = D3DXVECTOR3(-w, -h, -1.0f);
break;
default:
assert(0);
break;
}
D3DXVec3Normalize(&Normal, &Normal);
// Scale to be a color from 0 to 255 (127 is 0)
Normal += D3DXVECTOR3(1.0f, 1.0f, 1.0f);
Normal *= 127.0f;
// Store the color
*pBits = (DWORD)(((DWORD)Normal.x << 16) | ((DWORD)Normal.y << 8) | ((DWORD)Normal.z << 0));
}
}
pCubeTexture->UnlockRect((D3DCUBEMAP_FACES)i, 0);
}
}
return pCubeTexture;
}
};
//vlad123
#endif __D3DTEXTURE_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,788 @@
/*=============================================================================
D3DTexturesStreaming.cpp : Direct3D9 specific texture streaming technology.
Copyright (c) 2001 Crytek Studios. All Rights Reserved.
Revision history:
* Created by Honitch Andrey
=============================================================================*/
#include "RenderPCH.h"
#include "DriverD3D9.h"
//===============================================================================
//#define TEXUSAGE D3DUSAGE_DYNAMIC
//#define TEXPOOL D3DPOOL_DEFAULT
#define TEXUSAGE 0
#define TEXPOOL D3DPOOL_MANAGED
void STexPic::BuildMips()
{
}
void STexPicD3D::BuildMips()
{
CD3D9Renderer *r = gcpRendD3D;
LPDIRECT3DDEVICE9 dv = r->mfGetD3DDevice();
IDirect3DTexture9 *pID3DTexture = NULL;
IDirect3DCubeTexture9 *pID3DCubeTexture = NULL;
HRESULT h;
D3DLOCKED_RECT d3dlr;
D3DSURFACE_DESC ddsdDescDest;
if (!m_Mips[0])
CreateMips();
if (m_eTT != eTT_Cubemap)
{
pID3DTexture = (IDirect3DTexture9*)m_RefTex.m_VidTex;
for (int i=0; i<m_nMips; i++)
{
pID3DTexture->GetLevelDesc(i, &ddsdDescDest);
assert (ddsdDescDest.Width && ddsdDescDest.Height);
int size = CD3D9TexMan::TexSize(ddsdDescDest.Width, ddsdDescDest.Height, ddsdDescDest.Format);
SAFE_DELETE(m_Mips[0][i]);
SMipmap *mp = new SMipmap(ddsdDescDest.Width, ddsdDescDest.Height, size);
m_Mips[0][i] = mp;
mp->m_bUploaded = true;
h = pID3DTexture->LockRect(i, &d3dlr, NULL, 0);
cryMemcpy(&mp->DataArray[0], d3dlr.pBits, size);
pID3DTexture->UnlockRect(i);
}
}
else
{
pID3DCubeTexture = (IDirect3DCubeTexture9*)m_RefTex.m_VidTex;
for (int n=0; n<6; n++)
{
for (int i=0; i<m_nMips; i++)
{
pID3DCubeTexture->GetLevelDesc(i, &ddsdDescDest);
assert (ddsdDescDest.Width && ddsdDescDest.Height);
int size = CD3D9TexMan::TexSize(ddsdDescDest.Width, ddsdDescDest.Height, ddsdDescDest.Format);
SAFE_DELETE(m_Mips[n][i]);
SMipmap *mp = new SMipmap(ddsdDescDest.Width, ddsdDescDest.Height, size);
m_Mips[n][i] = mp;
mp->m_bUploaded = true;
h = pID3DCubeTexture->LockRect((D3DCUBEMAP_FACES)n, i, &d3dlr, NULL, 0);
cryMemcpy(&mp->DataArray[0], d3dlr.pBits, size);
pID3DCubeTexture->UnlockRect((D3DCUBEMAP_FACES)n, i);
}
}
}
}
bool STexPic::UploadMips(int nStartMip, int nEndMip)
{
return false;
}
void STexPic::FakeUploadMips(int nStartMip, int nEndMip)
{
int i;
if (CRenderer::CV_r_texturesstreamingonlyvideo)
m_LoadedSize = 0;
for (i=nStartMip; i<=nEndMip; i++)
{
int nLod = i-m_nBaseMip;
SMipmap *mp = m_Mips[0][i];
if (mp->m_bUploaded)
{
#ifdef _DEBUG
int nI = i+1;
while (nI <= nEndMip)
{
SMipmap *mp = m_Mips[0][nI];
assert (mp && mp->m_bUploaded);
nI++;
}
#endif
break;
}
m_LoadedSize += m_pFileTexMips[i].m_Size;
gRenDev->m_TexMan->m_StatsCurTexMem += m_pFileTexMips[i].m_Size;
}
}
bool STexPicD3D::UploadMips(int nStartMip, int nEndMip)
{
double time0 = 0;
ticks(time0);
CD3D9Renderer *r = gcpRendD3D;
LPDIRECT3DDEVICE9 dv = r->mfGetD3DDevice();
IDirect3DTexture9 *pID3DTexture = NULL;
IDirect3DCubeTexture9 *pID3DCubeTexture = NULL;
HRESULT h;
D3DLOCKED_RECT d3dlr;
int i;
if (CRenderer::CV_r_texturesstreamingonlyvideo)
{
if (!AddToPool(nStartMip, m_nMips-nStartMip))
return true;
if (!m_pPoolItem)
return true;
}
if (m_eTT != eTT_Cubemap)
{
pID3DTexture = (IDirect3DTexture9*)m_RefTex.m_VidTex;
if (!pID3DTexture)
{
if( FAILED( h = dv->CreateTexture(m_Width>>m_nBaseMip, m_Height>>m_nBaseMip, m_nMips-m_nBaseMip, TEXUSAGE, (D3DFORMAT)m_DstFormat, TEXPOOL, &pID3DTexture, NULL)))
return true;
m_RefTex.m_VidTex = pID3DTexture;
}
int SizeToLoad = 0;
if (m_pPoolItem)
{
for (i=nStartMip; i<=nEndMip; i++)
{
int nLod = i-nStartMip;
SMipmap *mp = m_Mips[0][i];
gRenDev->m_TexMan->m_StatsCurTexMem += m_pFileTexMips[i].m_Size;
gRenDev->m_TexMan->m_UpLoadBytes += m_pFileTexMips[i].m_Size;
LPDIRECT3DSURFACE9 pDestSurf, pSrcSurf;
h = pID3DTexture->GetSurfaceLevel(nLod, &pDestSurf);
pSrcSurf = (LPDIRECT3DSURFACE9)m_pPoolItem->m_pOwner->m_SysSurfaces[nLod];
h = pSrcSurf->LockRect(&d3dlr, NULL, 0);
#ifdef _DEBUG
int nD3DSize;
if (m_DstFormat == D3DFMT_DXT1 || m_DstFormat == D3DFMT_DXT3 || m_DstFormat == D3DFMT_DXT5)
nD3DSize = (d3dlr.Pitch/4) * ((mp->VSize+3)&~3);
else
nD3DSize = d3dlr.Pitch * mp->VSize;
assert(nD3DSize == m_pFileTexMips[i].m_Size);
#endif
SizeToLoad += m_pFileTexMips[i].m_Size;
// Copy data to system texture
cryMemcpy((byte *)d3dlr.pBits, &mp->DataArray[0], m_pFileTexMips[i].m_Size);
// Unlock the system texture
pSrcSurf->UnlockRect();
h = dv->UpdateSurface(pSrcSurf, 0, pDestSurf, 0);
SAFE_RELEASE(pDestSurf);
mp->m_bUploaded = true;
}
}
else
{
pID3DTexture->SetLOD(nStartMip-m_nBaseMip);
for (i=nStartMip; i<=nEndMip; i++)
{
int nLod = i-m_nBaseMip;
SMipmap *mp = m_Mips[0][i];
if (mp->m_bUploaded)
{
#ifdef _DEBUG
int nI = i+1;
while (nI <= nEndMip)
{
SMipmap *mp = m_Mips[0][nI];
assert (mp && mp->m_bUploaded);
nI++;
}
#endif
break;
}
m_LoadedSize += m_pFileTexMips[i].m_Size;
gRenDev->m_TexMan->m_StatsCurTexMem += m_pFileTexMips[i].m_Size;
gRenDev->m_TexMan->m_UpLoadBytes += m_pFileTexMips[i].m_Size;
h = pID3DTexture->LockRect(nLod, &d3dlr, NULL, 0);
#ifdef _DEBUG
int nD3DSize;
if (m_DstFormat == D3DFMT_DXT1 || m_DstFormat == D3DFMT_DXT3 || m_DstFormat == D3DFMT_DXT5)
nD3DSize = (d3dlr.Pitch/4) * ((mp->VSize+3)&~3);
else
nD3DSize = d3dlr.Pitch * mp->VSize;
assert(nD3DSize == m_pFileTexMips[i].m_Size);
#endif
SizeToLoad += m_pFileTexMips[i].m_Size;
// Copy data to video texture
cryMemcpy((byte *)d3dlr.pBits, &mp->DataArray[0], m_pFileTexMips[i].m_Size);
// Unlock the video texture
pID3DTexture->UnlockRect(nLod);
mp->m_bUploaded = true;
}
}
if (gRenDev->m_LogFileStr)
gRenDev->LogStrv(SRendItem::m_RecurseLevel, "Uploading mips '%s'. (Side: %d, %d-%d[%d]), Size: %d, Time: %.3f\n", m_SourceName.c_str(), -1, nStartMip, i-1, m_nMips, SizeToLoad, iTimer->GetAsyncCurTime());
}
else
{
pID3DCubeTexture = (IDirect3DCubeTexture9*)m_RefTex.m_VidTex;
if (!pID3DCubeTexture)
{
if( FAILED( h = dv->CreateCubeTexture(m_Width>>m_nBaseMip, m_nMips-m_nBaseMip, TEXUSAGE, (D3DFORMAT)m_DstFormat, TEXPOOL, &pID3DCubeTexture, NULL)))
return true;
m_RefTex.m_VidTex = pID3DCubeTexture;
}
if (!m_pPoolItem)
pID3DCubeTexture->SetLOD(nStartMip-m_nBaseMip);
for (int n=0; n<6; n++)
{
int SizeToLoad = 0;
if (m_pPoolItem)
{
for (i=nStartMip; i<=nEndMip; i++)
{
int nLod = i-nStartMip;
SMipmap *mp = m_Mips[n][i];
gRenDev->m_TexMan->m_StatsCurTexMem += m_pFileTexMips[i].m_Size;
gRenDev->m_TexMan->m_UpLoadBytes += m_pFileTexMips[i].m_Size;
LPDIRECT3DSURFACE9 pDestSurf, pSrcSurf;
h = pID3DCubeTexture->GetCubeMapSurface((D3DCUBEMAP_FACES)n, nLod, &pDestSurf);
pSrcSurf = (LPDIRECT3DSURFACE9)m_pPoolItem->m_pOwner->m_SysSurfaces[nLod];
h = pSrcSurf->LockRect(&d3dlr, NULL, 0);
#ifdef _DEBUG
int nD3DSize;
if (m_DstFormat == D3DFMT_DXT1 || m_DstFormat == D3DFMT_DXT3 || m_DstFormat == D3DFMT_DXT5)
nD3DSize = (d3dlr.Pitch/4) * ((mp->VSize+3)&~3);
else
nD3DSize = d3dlr.Pitch * mp->VSize;
assert(nD3DSize == m_pFileTexMips[i].m_Size);
#endif
SizeToLoad += m_pFileTexMips[i].m_Size;
// Copy data to system texture
cryMemcpy((byte *)d3dlr.pBits, &mp->DataArray[0], m_pFileTexMips[i].m_Size);
// Unlock the system texture
pSrcSurf->UnlockRect();
h = dv->UpdateSurface(pSrcSurf, 0, pDestSurf, 0);
SAFE_RELEASE(pDestSurf);
mp->m_bUploaded = true;
}
}
else
{
for (i=nStartMip; i<=nEndMip; i++)
{
int nLod = i-m_nBaseMip;
SMipmap *mp = m_Mips[n][i];
if (mp->m_bUploaded)
{
#ifdef _DEBUG
int nI = i+1;
while (nI <= nEndMip)
{
SMipmap *mp = m_Mips[n][nI];
assert (mp && mp->m_bUploaded);
nI++;
}
#endif
break;
}
if (!mp->DataArray.GetSize())
continue;
m_LoadedSize += m_pFileTexMips[i].m_Size;
gRenDev->m_TexMan->m_StatsCurTexMem += m_pFileTexMips[i].m_Size;
gRenDev->m_TexMan->m_UpLoadBytes += m_pFileTexMips[i].m_Size;
h = pID3DCubeTexture->LockRect((D3DCUBEMAP_FACES)n, nLod, &d3dlr, NULL, 0);
#ifdef _DEBUG
int nD3DSize;
if (m_DstFormat == D3DFMT_DXT1 || m_DstFormat == D3DFMT_DXT3 || m_DstFormat == D3DFMT_DXT5)
nD3DSize = (d3dlr.Pitch/4) * ((mp->VSize+3)&~3);
else
nD3DSize = d3dlr.Pitch * mp->VSize;
assert(nD3DSize == m_pFileTexMips[i].m_Size);
#endif
SizeToLoad += m_pFileTexMips[i].m_Size;
// Copy data to video texture
cryMemcpy((byte *)d3dlr.pBits, &mp->DataArray[0], m_pFileTexMips[i].m_Size);
// Unlock the video texture
pID3DCubeTexture->UnlockRect((D3DCUBEMAP_FACES)n, nLod);
mp->m_bUploaded = true;
}
}
if (gRenDev->m_LogFileStr)
gRenDev->LogStrv(SRendItem::m_RecurseLevel, "Uploading mips '%s'. (Side: %d, %d-%d[%d]), Size: %d, Time: %.3f\n", m_SourceName.c_str(), n, nStartMip, i-1, m_nMips, SizeToLoad, iTimer->GetAsyncCurTime());
}
}
unticks(time0);
r->m_RP.m_PS.m_fTexUploadTime += (float)(time0*1000.0*g_SecondsPerCycle);
return true;
}
// Just remove item from the texture object and keep Item in Pool list for future use
// This function doesn't release API texture
void STexPic::RemoveFromPool()
{
if (!m_pPoolItem)
return;
STexPoolItem *pIT = m_pPoolItem;
m_pPoolItem = NULL;
pIT->m_pTex = NULL;
pIT->m_fLastTimeUsed = gRenDev->m_RP.m_RealTime;
m_LoadedSize = -1;
m_RefTex.m_VidTex = NULL;
}
bool STexPic::AddToPool(int nStartMip, int nMips)
{
assert (m_Mips && nStartMip<m_nMips && m_Mips[0][nStartMip]);
SMipmap * mp = m_Mips[0][nStartMip];
STexPool *pPool = NULL;
LPDIRECT3DDEVICE9 dv = gcpRendD3D->mfGetD3DDevice();
IDirect3DTexture9 *pID3DTexture = NULL;
HRESULT h;
if (m_pPoolItem)
{
if (m_pPoolItem->m_pOwner->m_nMips == nMips && m_pPoolItem->m_pOwner->m_Width == mp->USize && m_pPoolItem->m_pOwner->m_Height == mp->VSize)
return false;
STexPoolItem *pIT = m_pPoolItem;
RemoveFromPool();
pIT->LinkFree(&gRenDev->m_TexMan->m_FreeTexPoolItems);
int nSides = 1;
if (m_eTT == eTT_Cubemap)
nSides = 6;
for (int j=0; j<nSides; j++)
{
if (!m_Mips[j])
continue;
for (int i=0; i<m_nMips; i++)
{
if (m_Mips[j][i])
m_Mips[j][i]->m_bUploaded = false;
}
}
/*IDirect3DBaseTexture9 *pTex = (IDirect3DBaseTexture9*)pIT->m_pAPITexture;
SAFE_RELEASE(pTex);
pIT->Unlink();
gRenDev->m_TexMan->m_StatsCurTexMem -= pIT->m_pOwner->m_Size;
delete pIT;*/
}
pPool = gRenDev->m_TexMan->CreatePool(mp->USize, mp->VSize, nMips, m_DstFormat, m_eTT);
if (!pPool)
return false;
// Try to find empty item in the pool
STexPoolItem *pIT = pPool->m_ItemsList.m_Next;
while (pIT != &pPool->m_ItemsList)
{
if (!pIT->m_pTex)
break;
pIT = pIT->m_Next;
}
if (pIT != &pPool->m_ItemsList)
{
pIT->UnlinkFree();
gRenDev->m_TexMan->m_StatsCurTexMem -= pPool->m_Size;
}
else
{
pIT = new STexPoolItem;
pIT->m_pOwner = pPool;
pIT->Link(&pPool->m_ItemsList);
// Create API texture for the item in DEFAULT pool
IDirect3DCubeTexture9 *pID3DCubeTexture = NULL;
pID3DTexture = NULL;
if (m_eTT != eTT_Cubemap)
{
if( FAILED( h = dv->CreateTexture(mp->USize, mp->VSize, nMips, TEXUSAGE, (D3DFORMAT)m_DstFormat, D3DPOOL_DEFAULT, &pID3DTexture, NULL)))
{
assert(0);
return false;
}
pIT->m_pAPITexture = pID3DTexture;
}
else
{
if( FAILED( h = dv->CreateCubeTexture(mp->USize, nMips, TEXUSAGE, (D3DFORMAT)m_DstFormat, D3DPOOL_DEFAULT, &pID3DCubeTexture, NULL)))
{
assert(0);
return false;
}
pIT->m_pAPITexture = pID3DCubeTexture;
}
}
m_LoadedSize = pPool->m_Size;
m_pPoolItem = pIT;
pIT->m_pTex = this;
m_RefTex.m_VidTex = pIT->m_pAPITexture;
return true;
}
STexPool *CTexMan::CreatePool(int nWidth, int nHeight, int nMips, int nFormat, ETexType eTT)
{
LPDIRECT3DDEVICE9 dv = gcpRendD3D->mfGetD3DDevice();
HRESULT h;
int i;
IDirect3DTexture9 *pID3DTexture = NULL;
STexPool *pPool = NULL;
for (i=0; i<m_TexPools.Num(); i++)
{
pPool = m_TexPools[i];
if (pPool->m_nMips == nMips && pPool->m_Width == nWidth && pPool->m_Height == nHeight && pPool->m_Format == nFormat && pPool->m_eTT == eTT)
break;
}
// Create new pool
if (i == m_TexPools.Num())
{
pPool = new STexPool;
pPool->m_eTT = eTT;
pPool->m_Format = nFormat;
pPool->m_Width = nWidth;
pPool->m_Height = nHeight;
pPool->m_nMips = nMips;
pPool->m_Size = 0;
int wdt = nWidth;
int hgt = nHeight;
for (i=0; i<nMips; i++)
{
if (!wdt)
wdt = 1;
if (!hgt)
hgt = 1;
pPool->m_Size += CD3D9TexMan::TexSize(wdt, hgt, nFormat);
wdt >>= 1;
hgt >>= 1;
}
if (eTT == eTT_Cubemap)
pPool->m_Size *= 6;
if( FAILED( h = dv->CreateTexture(nWidth, nHeight, nMips, TEXUSAGE, (D3DFORMAT)nFormat, D3DPOOL_SYSTEMMEM, &pID3DTexture, NULL)))
return NULL;
pPool->m_pSysTexture = pID3DTexture;
for (i=0; i<nMips; i++)
{
LPDIRECT3DSURFACE9 pDestSurf;
h = pID3DTexture->GetSurfaceLevel(i, &pDestSurf);
pPool->m_SysSurfaces.AddElem(pDestSurf);
}
pPool->m_SysSurfaces.Shrink();
pPool->m_ItemsList.m_Next = &pPool->m_ItemsList;
pPool->m_ItemsList.m_Prev = &pPool->m_ItemsList;
gRenDev->m_TexMan->m_TexPools.AddElem(pPool);
}
return pPool;
}
void CTexMan::CreatePools()
{
int nMaxTexSize = gcpRendD3D->m_pd3dDevice->GetAvailableTextureMem();
int i = 10;
int j, n;
while (i)
{
int wdt = (1<<i);
int hgt = (1<<i);
int nTexSize = 0;
nTexSize += CD3D9TexMan::TexSize(wdt, hgt, D3DFMT_DXT1);
nTexSize += CD3D9TexMan::TexSize(wdt, hgt, D3DFMT_DXT3);
nTexSize += CD3D9TexMan::TexSize(wdt, hgt, D3DFMT_A8R8G8B8);
int nH = i-1;
if (nH < 0)
nH = 0;
hgt = (1<<nH);
nTexSize += CD3D9TexMan::TexSize(wdt, hgt, D3DFMT_DXT1);
nTexSize += CD3D9TexMan::TexSize(wdt, hgt, D3DFMT_DXT3);
nTexSize += CD3D9TexMan::TexSize(wdt, hgt, D3DFMT_A8R8G8B8);
n = nMaxTexSize / nTexSize / i / 2;
for (j=0; j<n; j++)
{
CreatePool(1<<i, 1<<i, i, D3DFMT_DXT1, eTT_Base);
CreatePool(1<<i, 1<<i, i, D3DFMT_DXT3, eTT_Base);
CreatePool(1<<i, 1<<i, i, D3DFMT_A8R8G8B8, eTT_Base);
CreatePool(1<<i, 1<<nH, i, D3DFMT_DXT1, eTT_Base);
CreatePool(1<<i, 1<<nH, i, D3DFMT_DXT3, eTT_Base);
CreatePool(1<<i, 1<<nH, i, D3DFMT_A8R8G8B8, eTT_Base);
}
i--;
}
}
void CTexMan::UnloadOldTextures(STexPic *pExclude)
{
if (!CRenderer::CV_r_texturesstreampoolsize)
return;
//ValidateTexSize();
// First try to release freed texture pool items
STexPoolItem *pIT = gRenDev->m_TexMan->m_FreeTexPoolItems.m_PrevFree;
while (pIT != &gRenDev->m_TexMan->m_FreeTexPoolItems)
{
assert (!pIT->m_pTex);
STexPoolItem *pITNext = pIT->m_PrevFree;
IDirect3DBaseTexture9 *pTex = (IDirect3DBaseTexture9*)pIT->m_pAPITexture;
SAFE_RELEASE(pTex);
pIT->Unlink();
pIT->UnlinkFree();
m_StatsCurTexMem -= pIT->m_pOwner->m_Size;
delete pIT;
pIT = pITNext;
if (m_StatsCurTexMem < CRenderer::CV_r_texturesstreampoolsize*1024*1024)
break;
}
// Second release old texture objects
STexPic *pTP = STexPic::m_Root.m_Prev;
while (m_StatsCurTexMem >= CRenderer::CV_r_texturesstreampoolsize*1024*1024)
{
if (pTP == &STexPic::m_Root)
{
ICVar *var = iConsole->GetCVar("r_TexturesStreamPoolSize");
var->Set(m_StatsCurTexMem/(1024*1024)+30);
iLog->Log("WARNING: Texture pool was changed to %d Mb", CRenderer::CV_r_texturesstreampoolsize);
return;
}
STexPic *Next = pTP->m_Prev;
if (pTP != pExclude)
pTP->Unload();
pTP = Next;
}
}
void STexPic::PrecacheAsynchronously(float fDist, int Flags)
{
if (gRenDev->m_bDeviceLost)
return;
// Ignore predicted load if we near to texture thrashing
if (m_nCustomMip)
return;
PROFILE_FRAME(Texture_Precache);
if (gRenDev->m_TexMan->m_Streamed & 1)
{
if (m_Flags2 & (FT2_WASUNLOADED | FT2_PARTIALLYLOADED))
{
if (!IsStreamed())
return;
//if (!(Flags & FPR_NEEDLIGHT) && m_eTT == eTT_Bumpmap)
// return;
if (CRenderer::CV_r_logTexStreaming >= 2)
gRenDev->LogStrv(SRendItem::m_RecurseLevel, "Precache '%s' (Stream)\n", m_SourceName.c_str());
LoadFromCache(Flags, fDist);
}
else
{
if (CRenderer::CV_r_logTexStreaming >= 2)
gRenDev->LogStrv(SRendItem::m_RecurseLevel, "Precache '%s' (Skip)\n", m_SourceName.c_str());
}
}
if (gRenDev->m_TexMan->m_Streamed & 2)
{
if (CRenderer::CV_r_logTexStreaming >= 2)
gRenDev->LogStrv(SRendItem::m_RecurseLevel, "Precache '%s' (Draw)\n", m_SourceName.c_str());
gcpRendD3D->EF_SetState(GS_NOCOLMASK | GS_NODEPTHTEST);
Set();
int nOffs;
struct_VERTEX_FORMAT_TRP3F_COL4UB_TEX2F *vTri = gcpRendD3D->GetVBPtr2D(3, nOffs);
DWORD col = -1;
// Define the triangle
vTri[0].x = 0;
vTri[0].y = 0;
vTri[0].z = 1;
vTri[0].rhw = 1.0f;
vTri[0].color.dcolor = col;
vTri[0].st[0] = 0;
vTri[0].st[1] = 0;
vTri[1].x = 2;
vTri[1].y = 0;
vTri[1].z = 1;
vTri[1].rhw = 1.0f;
vTri[1].color.dcolor = col;
vTri[1].st[0] = 1;
vTri[1].st[1] = 0;
vTri[2].x = 2;
vTri[2].y = 2;
vTri[2].z = 1;
vTri[2].rhw = 1.0f;
vTri[2].color.dcolor = col;
vTri[2].st[0] = 1;
vTri[2].st[1] = 1;
gcpRendD3D->UnlockVB2D();
gcpRendD3D->m_pd3dDevice->SetStreamSource(0, gcpRendD3D->m_pVB2D, 0, sizeof(struct_VERTEX_FORMAT_TRP3F_COL4UB_TEX2F));
gcpRendD3D->EF_SetVertexDeclaration(0, VERTEX_FORMAT_TRP3F_COL4UB_TEX2F);
gcpRendD3D->m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, nOffs, 1);
gcpRendD3D->EF_SetState(GS_NODEPTHTEST);
}
}
void CTexMan::CheckTexLimits(STexPic *pExclude)
{
ValidateTexSize();
if (!m_Streamed)
return;
// To avoid textures thrashing we will try to predict it using some statistics
// and using 3-Phase old textures releasing scheme
m_TexSizeHistory[m_nTexSizeHistory & 7] = gRenDev->m_TexMan->m_StatsCurTexMem;
m_nTexSizeHistory++;
bool bUp = true;
int n = m_nTexSizeHistory-8;
if (n < 0)
n = 0;
int nMinTexSize = 0;
int nPrev;
for (int i=n; i<m_nTexSizeHistory; i++)
{
int m = i&7;
if (i == n)
nMinTexSize = m_TexSizeHistory[m];
else
nMinTexSize = min(m_TexSizeHistory[m], nMinTexSize);
if (bUp)
{
if (i == n || m_TexSizeHistory[m] > nPrev)
nPrev = m_TexSizeHistory[m];
else
bUp = false;
}
}
int nPoolSize = CRenderer::CV_r_texturesstreampoolsize*1024*1024;
if (nMinTexSize < (int)(nPoolSize*0.8f))
{
if (m_nCustomMip > 0)
m_nCustomMip--;
}
else
if (nMinTexSize > (int)(nPoolSize*0.98f))
{
if (m_nCustomMip < 2)
m_nCustomMip++;
}
if (!m_nPhaseProcessingTextures)
m_nPhaseProcessingTextures = 1;
// Phase1: delete old freed pool items
if (m_nPhaseProcessingTextures == 1)
{
float fTime = gRenDev->m_RP.m_RealTime;
int n = 20;
STexPoolItem *pIT = gRenDev->m_TexMan->m_FreeTexPoolItems.m_PrevFree;
while (pIT != &gRenDev->m_TexMan->m_FreeTexPoolItems)
{
assert (!pIT->m_pTex);
STexPoolItem *pITNext = pIT->m_PrevFree;
if (fTime-pIT->m_fLastTimeUsed > 2.0f)
{
IDirect3DBaseTexture9 *pTex = (IDirect3DBaseTexture9*)pIT->m_pAPITexture;
SAFE_RELEASE(pTex);
pIT->Unlink();
pIT->UnlinkFree();
m_StatsCurTexMem -= pIT->m_pOwner->m_Size;
nMinTexSize -= pIT->m_pOwner->m_Size;
delete pIT;
n--;
}
pIT = pITNext;
if (!n || nMinTexSize <= (int)(nPoolSize*0.88f))
break;
}
if (nMinTexSize <= (int)(nPoolSize*0.88f))
m_nPhaseProcessingTextures = 0;
else
if (pIT == &gRenDev->m_TexMan->m_FreeTexPoolItems)
{
m_nProcessedTextureID1 = 0;
m_pProcessedTexture1 = NULL;
m_nPhaseProcessingTextures = 2;
}
}
// Phase2: unload old textures (which was used at least 2 secs ago)
if (m_nPhaseProcessingTextures == 2)
{
STexPic *tp;
if (!m_nProcessedTextureID1 || !(tp=m_Textures[m_nProcessedTextureID1]) || !tp->m_Prev || tp != m_pProcessedTexture1)
tp = STexPic::m_Root.m_Prev;
int nFrame = gRenDev->GetFrameID();
int nWeight = 0;
while (tp != &STexPic::m_Root)
{
STexPic *Next = tp->m_Prev;
if (tp->m_AccessFrame && nFrame-tp->m_AccessFrame > 100 && !(tp->m_Flags & FT_NOSTREAM))
{
nWeight += 10;
tp->Unload();
}
tp = Next;
nWeight++;
if (nWeight > 100)
break;
}
if (tp == &STexPic::m_Root)
m_nPhaseProcessingTextures = 0;
else
{
m_nProcessedTextureID1 = tp->m_Id;
m_pProcessedTexture1 = tp;
}
}
{
STexPic *tp;
if (!m_nProcessedTextureID2 || !(tp=m_Textures[m_nProcessedTextureID2]) || !tp->m_Prev || tp != m_pProcessedTexture2)
tp = STexPic::m_Root.m_Prev;
else
tp = m_Textures[m_nProcessedTextureID2];
int nFrame = gRenDev->GetFrameID();
int nWeight = 0;
while (tp != &STexPic::m_Root)
{
STexPic *Next = tp->m_Prev;
if (tp->m_fMinDistance)
{
if ((tp->m_Width >64 || tp->m_Height > 64) && tp->m_nCustomMip != m_nCustomMip)
{
nWeight += 5;
tp->m_nCustomMip = m_nCustomMip;
tp->m_Flags2 |= FT2_NEEDTORELOAD;
}
}
tp = Next;
nWeight++;
if (nWeight > 100)
break;
}
if (tp == &STexPic::m_Root)
{
m_nProcessedTextureID2 = 0;
m_pProcessedTexture2 = NULL;
}
else
{
m_nProcessedTextureID2 = tp->m_Id;
m_pProcessedTexture2 = tp;
}
}
if (!(gRenDev->m_TexMan->m_Streamed & 1))
return;
if (CRenderer::CV_r_texturesstreampoolsize < 10)
CRenderer::CV_r_texturesstreampoolsize = 10;
ValidateTexSize();
// Usually we do it in case of textures thrashing
if (gRenDev->m_TexMan->m_StatsCurTexMem >= CRenderer::CV_r_texturesstreampoolsize*1024*1024)
UnloadOldTextures(pExclude);
}

View File

@@ -0,0 +1,853 @@
/*=============================================================================
D3DTexturesStreaming.cpp : Direct3D9 vertex/index buffers management.
Copyright (c) 2001 Crytek Studios. All Rights Reserved.
Revision history:
* Created by Honitch Andrey
=============================================================================*/
#include "RenderPCH.h"
#include "DriverD3D9.h"
//===============================================================================
#ifdef _DEBUG
TArray<SDynVB> gDVB;
#endif
//===============================================================================
void *CVertexBuffer::GetStream(int nStream, int *nOffs)
{
if (m_VS[nStream].m_pPool)
{
if (nOffs)
*nOffs = m_VS[nStream].m_nBufOffset;
return m_VS[nStream].m_pPool->m_pVB;
}
else
{
if (nOffs)
*nOffs = 0;
return m_VS[nStream].m_VertBuf.m_pPtr;
}
}
void CD3D9Renderer::DrawDynVB(int nOffs, int Pool, int nVerts)
{
PROFILE_FRAME(Draw_IndexMesh);
if (!m_SceneRecurseCount)
{
iLog->Log("Error: CD3D9Renderer::DrawDynVB without BeginScene\n");
return;
}
if (CV_d3d9_forcesoftware)
return;
if (!nVerts)
return;
if (m_bDeviceLost)
return;
HRESULT h;
struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F *pDst = (struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F *)GetVBPtr3D(nVerts, nOffs);
//assert(pDst);
if (!pDst)
return;
if (m_TempDynVB)
{
cryMemcpy(pDst, m_TempDynVB, nVerts*sizeof(struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F));
SAFE_DELETE_ARRAY(m_TempDynVB);
}
else
cryMemcpy(pDst, m_DynVB, nVerts*sizeof(struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F));
m_pVB3D[0]->Unlock();
// Bind our vertex as the first data stream of our device
h = m_pd3dDevice->SetStreamSource(0, m_pVB3D[0], 0, sizeof(struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F));
EF_SetVertexDeclaration(0, VERTEX_FORMAT_P3F_COL4UB_TEX2F);
// Render the two triangles from the data stream
h = m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, nOffs, nVerts/3);
}
void CD3D9Renderer::DrawDynVB(struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F *pBuf, ushort *pInds, int nVerts, int nInds, int nPrimType)
{
PROFILE_FRAME(Draw_IndexMesh);
if (!pBuf)
return;
if (!m_SceneRecurseCount)
{
iLog->Log("Error: CD3D9Renderer::DrawDynVB without BeginScene\n");
return;
}
if (CV_d3d9_forcesoftware)
return;
if (!nVerts || !nInds)
return;
if (FAILED(m_pd3dDevice->TestCooperativeLevel()))
return;
HRESULT h;
int nOffs, nIOffs;
struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F *pDst = (struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F *)GetVBPtr3D(nVerts, nOffs);
assert(pDst);
if (!pDst)
return;
ushort *pDstInds = NULL;
if (pInds)
pDstInds = GetIBPtr(nInds, nIOffs);
cryMemcpy(pDst, pBuf, nVerts*sizeof(struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F));
if (pDstInds)
cryMemcpy(pDstInds, pInds, nInds*sizeof(short));
m_pVB3D[0]->Unlock();
if (pDstInds)
m_pIB->Unlock();
// Bind our vertex as the first data stream of our device
h = m_pd3dDevice->SetStreamSource(0, m_pVB3D[0], 0, sizeof(struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F));
EF_SetVertexDeclaration(0, VERTEX_FORMAT_P3F_COL4UB_TEX2F);
// Render triangles from the data stream
if (pDstInds)
{
h = m_pd3dDevice->SetIndices((IDirect3DIndexBuffer9 *)m_pIB);
h = m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, nOffs, 0, nVerts, nIOffs, nInds/3);
}
else
{
h = m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, nOffs, nVerts/3);
}
}
//===============================================================================
void CD3D9Renderer::CreateIndexBuffer(SVertexStream *dest,const void *src,int indexcount)
{
WaitForDevice();
if (dest->m_VertBuf.m_pPtr)
{
IDirect3DIndexBuffer9 *pIndBuf = (IDirect3DIndexBuffer9 *)dest->m_VertBuf.m_pPtr;
#ifdef _DEBUG
sRemoveVB(pIndBuf, dest);
#endif
SAFE_RELEASE(pIndBuf);
}
dest->m_nItems = 0;
if (indexcount)
{
IDirect3DIndexBuffer9 *ibuf=NULL;
int size = indexcount*sizeof(ushort);
int flags = D3DUSAGE_WRITEONLY;
D3DPOOL Pool = D3DPOOL_MANAGED;
if (dest->m_bDynamic)
{
flags |= D3DUSAGE_DYNAMIC;
Pool = D3DPOOL_DEFAULT;
}
HRESULT hReturn = m_pd3dDevice->CreateIndexBuffer(size, flags, D3DFMT_INDEX16, Pool, &ibuf, NULL);
#ifdef _DEBUG
sAddVB(ibuf, dest, NULL, "Index buf");
#endif
if (FAILED(hReturn))
{
iLog->Log("Failed to create index buffer\n");
return;
}
dest->m_VertBuf.m_pPtr = ibuf;
dest->m_nItems = indexcount;
}
if (src && indexcount)
UpdateIndexBuffer(dest, src, indexcount, true);
}
void CD3D9Renderer::UpdateIndexBuffer(SVertexStream *dest,const void *src,int indexcount, bool bUnLock)
{
PROFILE_FRAME(Mesh_UpdateIBuffers);
if (m_bDeviceLost)
return;
HRESULT hReturn;
IDirect3DIndexBuffer9 *ibuf;
if (src && indexcount)
{
if (dest->m_nItems < indexcount)
{
if (dest->m_nItems)
ReleaseIndexBuffer(dest);
CreateIndexBuffer(dest, NULL, indexcount);
}
ushort *dst;
ibuf = (IDirect3DIndexBuffer9 *)dest->m_VertBuf.m_pPtr;
{
PROFILE_FRAME(Mesh_UpdateIBuffersLock);
hReturn = ibuf->Lock(0, 0, (void **) &dst, dest->m_bDynamic ? D3DLOCK_DISCARD : 0);
}
int size = indexcount*sizeof(ushort);
{
PROFILE_FRAME(Mesh_UpdateIBuffersCopy);
cryMemcpy(dst, src, size);
}
dest->m_VData = dst;
//hReturn = m_pd3dDevice->TestCooperativeLevel();
if (bUnLock)
{
hReturn = ibuf->Unlock();
dest->m_bLocked = false;
}
else
dest->m_bLocked = true;
}
else
if (dest->m_VertBuf.m_pPtr)
{
if (bUnLock && dest->m_bLocked)
{
ibuf = (IDirect3DIndexBuffer9 *)dest->m_VertBuf.m_pPtr;
hReturn = ibuf->Unlock();
dest->m_bLocked = false;
}
else
if (!bUnLock && !dest->m_bLocked)
{
PROFILE_FRAME(Mesh_UpdateIBuffersLock);
ibuf = (IDirect3DIndexBuffer9 *)dest->m_VertBuf.m_pPtr;
ushort *dst;
hReturn = ibuf->Lock(0, 0, (void **) &dst, dest->m_bDynamic ? D3DLOCK_DISCARD : 0);
dest->m_bLocked = true;
dest->m_VData = dst;
}
}
}
void CD3D9Renderer::ReleaseIndexBuffer(SVertexStream *dest)
{
IDirect3DIndexBuffer9 *ibuf = (IDirect3DIndexBuffer9 *)dest->m_VertBuf.m_pPtr;
#ifdef _DEBUG
if (ibuf)
sRemoveVB(ibuf, dest);
#endif
SAFE_RELEASE(ibuf);
dest->Reset();
}
void *CD3D9Renderer::GetDynVBPtr(int nVerts, int &nOffs, int Pool)
{
void *vBuf = NULL;
nOffs = 0;
switch(Pool)
{
case 0:
default:
if (nVerts <= 2048)
{
SAFE_DELETE_ARRAY(m_TempDynVB);
return m_DynVB;
}
else
{
m_TempDynVB = new struct_VERTEX_FORMAT_P3F_COL4UB_TEX2F [nVerts];
return m_TempDynVB;
}
break;
case 1:
case 2:
vBuf = GetVBPtr3D(nVerts, nOffs, Pool);
break;
}
return vBuf;
}
#ifdef _DEBUG
static char *szDescBuf[] =
{
"Base Mesh",
"Mesh Tangents",
"Mesh LM",
};
#endif
bool CD3D9Renderer::AllocateVBChunk(int bytes_count, TVertPool *Ptr, SVertexStream *pVB, const char *szSource)
{
assert(bytes_count);
int best_i = -1;
int min_size = 10000000;
// find best chunk
for(int i=0; i<Ptr->m_alloc_info.Count(); i++)
{
if(!Ptr->m_alloc_info[i].busy)
{
if(Ptr->m_alloc_info[i].bytes_num >= bytes_count)
{
if(Ptr->m_alloc_info[i].bytes_num < min_size)
{
best_i = i;
min_size = Ptr->m_alloc_info[i].bytes_num;
}
}
}
}
if(best_i>=0)
{ // use best free chunk
Ptr->m_alloc_info[best_i].busy = true;
Ptr->m_alloc_info[best_i].szSource = szSource;
int bytes_free = Ptr->m_alloc_info[best_i].bytes_num - bytes_count;
if(bytes_free>0)
{
// modify reused shunk
Ptr->m_alloc_info[best_i].bytes_num = bytes_count;
// insert another free shunk
alloc_info_struct new_shunk;
new_shunk.bytes_num = bytes_free;
new_shunk.ptr = Ptr->m_alloc_info[best_i].ptr + Ptr->m_alloc_info[best_i].bytes_num;
new_shunk.busy = false;
if(best_i < Ptr->m_alloc_info.Count()-1) // if not last
Ptr->m_alloc_info.InsertBefore(new_shunk, best_i+1);
else
Ptr->m_alloc_info.Add(new_shunk);
}
pVB->m_nBufOffset = Ptr->m_alloc_info[best_i].ptr;
pVB->m_pPool = (SVertPool *)Ptr;
return true;
}
int res_ptr = 0;
int piplevel = Ptr->m_alloc_info.Count() ? (Ptr->m_alloc_info.Last().ptr - Ptr->m_alloc_info[0].ptr) + Ptr->m_alloc_info.Last().bytes_num : 0;
if(piplevel + bytes_count + 100 >= Ptr->m_nBufSize)
{
return false;
}
else
{
res_ptr = piplevel;
}
// register new chunk
alloc_info_struct ai;
ai.ptr = res_ptr;
ai.szSource = szSource;
ai.bytes_num = bytes_count;
ai.busy = true;
Ptr->m_alloc_info.Add(ai);
pVB->m_nBufOffset = res_ptr;
pVB->m_pPool = (SVertPool *)Ptr;
return true;
}
bool CD3D9Renderer::ReleaseVBChunk(TVertPool *Ptr, SVertexStream *pVB)
{
int p = pVB->m_nBufOffset;
for(int i=0; i<Ptr->m_alloc_info.Count(); i++)
{
if(Ptr->m_alloc_info[i].ptr == p)
{
Ptr->m_alloc_info[i].busy = false;
// delete info about last unused shunks
while(Ptr->m_alloc_info.Count() && Ptr->m_alloc_info.Last().busy == false)
Ptr->m_alloc_info.Delete(Ptr->m_alloc_info.Count()-1);
// merge unused shunks
for(int s=0; s<Ptr->m_alloc_info.Count()-1; s++)
{
assert(Ptr->m_alloc_info[s].ptr < Ptr->m_alloc_info[s+1].ptr);
if(Ptr->m_alloc_info[s].busy == false)
{
if(Ptr->m_alloc_info[s+1].busy == false)
{
Ptr->m_alloc_info[s].bytes_num += Ptr->m_alloc_info[s+1].bytes_num;
Ptr->m_alloc_info.Delete(s+1);
s--;
}
}
}
return Ptr->m_alloc_info.Count() ? false : true;
}
}
iLog->Log("Error: CD3D9Renderer::ReleaseVBChunk::ReleasePointer: pointer not found");
return false;
}
void CD3D9Renderer::AllocVBInPool(int size, int nVFormat, SVertexStream *pVB)
{
CD3D9Renderer *rd = gcpRendD3D;
assert(nVFormat>=0 && nVFormat<VERTEX_FORMAT_NUMS);
int Flags = D3DUSAGE_WRITEONLY;
D3DPOOL Pool = D3DPOOL_MANAGED;
int fvf = 0;
int VBsize = CV_d3d9_vbpoolsize;
TVertPool* Ptr;
for(Ptr=sVertPools; Ptr; Ptr=Ptr->Next)
{
if (AllocateVBChunk(size, Ptr, pVB, NULL))
break;
}
if (!Ptr)
{
Ptr = new TVertPool;
Ptr->m_nBufSize = VBsize;
Ptr->m_pVB = NULL;
Ptr->Next = sVertPools;
Ptr->PrevLink = &sVertPools;
if (sVertPools)
{
assert(sVertPools->PrevLink == &sVertPools);
sVertPools->PrevLink = &Ptr->Next;
}
sVertPools = Ptr;
AllocateVBChunk(size, Ptr, pVB, NULL);
}
if (!Ptr->m_pVB)
rd->m_pd3dDevice->CreateVertexBuffer(VBsize, Flags, fvf, Pool, &Ptr->m_pVB, NULL);
}
void CD3D9Renderer::CreateBuffer(int size, int vertexformat, CVertexBuffer *buf, int Type, const char *szSource)
{
PROFILE_FRAME(Mesh_CreateVBuffers);
WaitForDevice();
if (CV_d3d9_vbpools && size < CV_d3d9_vbpoolsize && !buf->m_bDynamic)
{
AllocVBInPool(size, vertexformat, &buf->m_VS[Type]);
return;
}
IDirect3DVertexBuffer9 *vptr = NULL;
int fvf = m_RP.m_D3DFixedPipeline[Type][vertexformat].m_Handle;
int Flags = D3DUSAGE_WRITEONLY;
D3DPOOL Pool = D3DPOOL_MANAGED;
if (buf->m_bDynamic)
{
Flags |= D3DUSAGE_DYNAMIC;
Pool = D3DPOOL_DEFAULT;
}
HRESULT hReturn = m_pd3dDevice->CreateVertexBuffer(size, Flags, fvf, Pool, &vptr, NULL);
if (FAILED(hReturn))
return;
buf->m_VS[Type].m_bDynamic = buf->m_bDynamic;
#ifdef _DEBUG
sAddVB(vptr, &buf->m_VS[Type], buf, szDescBuf[Type]);
#endif
void *dst;
buf->m_VS[Type].m_VertBuf.m_pPtr = vptr;
hReturn = vptr->Lock(0, 0, (void **) &dst, buf->m_bDynamic ? D3DLOCK_NOOVERWRITE : 0);
buf->m_VS[Type].m_VData = dst;
hReturn = vptr->Unlock();
m_CurVertBufferSize += size;
}
CVertexBuffer *CD3D9Renderer::CreateBuffer(int vertexcount,int vertexformat, const char *szSource, bool bDynamic)
{
PROFILE_FRAME(Mesh_CreateVBuffers);
WaitForDevice();
IDirect3DVertexBuffer9 *vptr = NULL;
int fvf = m_RP.m_D3DFixedPipeline[0][vertexformat].m_Handle;
int Flags = D3DUSAGE_WRITEONLY;
D3DPOOL Pool = D3DPOOL_MANAGED;
if (bDynamic)
{
Flags |= D3DUSAGE_DYNAMIC;
Pool = D3DPOOL_DEFAULT;
}
int size = m_VertexSize[vertexformat]*vertexcount;
if (size+m_CurVertBufferSize > m_MaxVertBufferSize)
{
CLeafBuffer *pLB = CLeafBuffer::m_Root.m_Prev;
while (size+m_CurVertBufferSize > m_MaxVertBufferSize)
{
if (pLB == &CLeafBuffer::m_Root)
iConsole->Exit("Error: Pipeline buffer overflow. Current geometry cannot fit in video memory (%s)", gRenDev->GetStatusText(eRS_VidBuffer));
CLeafBuffer *Next = pLB->m_Prev;
pLB->Unload();
pLB = Next;
}
}
m_CurVertBufferSize += m_VertexSize[vertexformat]*vertexcount;
CVertexBuffer *newbuf = new CVertexBuffer;
newbuf->m_bDynamic = bDynamic;
newbuf->m_VS[VSF_GENERAL].m_bDynamic = bDynamic;
newbuf->m_VS[VSF_GENERAL].m_bLocked = false;
newbuf->m_fence=0;
newbuf->m_NumVerts = vertexcount;
newbuf->m_vertexformat = vertexformat;
if (CV_d3d9_vbpools && m_VertexSize[vertexformat]*vertexcount < CV_d3d9_vbpoolsize && !newbuf->m_bDynamic)
{
AllocVBInPool(size, vertexformat, &newbuf->m_VS[VSF_GENERAL]);
return newbuf;
}
HRESULT hReturn = m_pd3dDevice->CreateVertexBuffer(m_VertexSize[vertexformat]*vertexcount, Flags, fvf, Pool, &vptr, NULL);
if (FAILED(hReturn))
return (NULL);
newbuf->m_VS[VSF_GENERAL].m_VertBuf.m_pPtr = vptr;
#ifdef _DEBUG
sAddVB(vptr, &newbuf->m_VS[VSF_GENERAL], newbuf, szDescBuf[VSF_GENERAL]);
#endif
return(newbuf);
}
///////////////////////////////////////////
void CD3D9Renderer::UpdateBuffer(CVertexBuffer *dest, const void *src, int vertexcount, bool bUnLock, int offs, int Type)
{
PROFILE_FRAME(Mesh_UpdateVBuffers);
if (m_bDeviceLost)
return;
VOID *pVertices;
HRESULT hr = 0;
IDirect3DVertexBuffer9 *tvert;
int size;
int nOffs = 0;
if (!src)
{
if (!Type)
{
tvert=(IDirect3DVertexBuffer9 *)dest->GetStream(VSF_GENERAL, &nOffs);
size = m_VertexSize[dest->m_vertexformat];
if (bUnLock)
{
// video buffer update
if (dest->m_VS[VSF_GENERAL].m_bLocked)
{
dest->m_VS[VSF_GENERAL].m_bLocked = false;
hr = tvert->Unlock();
}
}
else
{
// video buffer update
if (!dest->m_VS[VSF_GENERAL].m_bLocked)
{
PROFILE_FRAME(Mesh_UpdateVBuffersLock);
dest->m_VS[VSF_GENERAL].m_bLocked = true;
hr=tvert->Lock(0, 0, (void **) &pVertices, dest->m_bDynamic ? D3DLOCK_DISCARD : 0);
byte *pData = (byte *)pVertices;
dest->m_VS[VSF_GENERAL].m_VData = &pData[nOffs];
}
}
}
else
{
for (int i=0; i<VSF_NUM; i++)
{
tvert = (IDirect3DVertexBuffer9 *)dest->GetStream(i, &nOffs);
if (!tvert)
continue;
if (!((1<<i) & Type))
continue;
if (bUnLock)
{
if (dest->m_VS[i].m_bLocked)
{
dest->m_VS[i].m_bLocked = false;
hr = tvert->Unlock();
}
}
else
{
if (!dest->m_VS[i].m_bLocked)
{
PROFILE_FRAME(Mesh_UpdateVBuffersLock);
dest->m_VS[i].m_bLocked = true;
hr=tvert->Lock(0, 0, (void **) &pVertices, dest->m_bDynamic ? D3DLOCK_DISCARD : 0);
byte *pData = (byte *)pVertices;
dest->m_VS[VSF_GENERAL].m_VData = &pData[nOffs];
}
}
}
}
return;
}
if (Type == VSF_GENERAL)
{
if (dest->m_VS[VSF_GENERAL].m_pPool)
{
tvert = dest->m_VS[VSF_GENERAL].m_pPool->m_pVB;
nOffs = dest->m_VS[VSF_GENERAL].m_nBufOffset;
}
else
tvert = (IDirect3DVertexBuffer9 *)dest->m_VS[VSF_GENERAL].m_VertBuf.m_pPtr;
size = m_VertexSize[dest->m_vertexformat];
}
else
if (Type == VSF_TANGENTS)
{
if (dest->m_VS[VSF_TANGENTS].m_pPool)
{
tvert = dest->m_VS[VSF_TANGENTS].m_pPool->m_pVB;
nOffs = dest->m_VS[VSF_TANGENTS].m_nBufOffset;
}
else
tvert = (IDirect3DVertexBuffer9 *)dest->m_VS[VSF_TANGENTS].m_VertBuf.m_pPtr;
size = sizeof(SPipTangents);
}
if (!tvert) // system buffer update
{
PROFILE_FRAME(Mesh_UpdateVBuffersCopy);
if (dest->m_bFenceSet)
cryMemcpy(dest->m_VS[Type].m_VData, src, size*vertexcount);
else
if (Type == VSF_GENERAL && dest->m_VS[VSF_GENERAL].m_VData)
cryMemcpy(dest->m_VS[VSF_GENERAL].m_VData, src, size*vertexcount);
return;
}
// video buffer update
if (!dest->m_VS[Type].m_bLocked)
{
PROFILE_FRAME(Mesh_UpdateVBuffersLock);
dest->m_VS[Type].m_bLocked = true;
hr=tvert->Lock(nOffs, size*vertexcount, (void **) &pVertices, dest->m_bDynamic ? D3DLOCK_DISCARD : 0);
assert(!hr);
dest->m_VS[Type].m_VData = pVertices;
}
if (SUCCEEDED(hr) && src)
{
PROFILE_FRAME(Mesh_UpdateVBuffersCopy);
cryMemcpy(dest->m_VS[Type].m_VData, src, size*vertexcount);
tvert->Unlock();
dest->m_VS[Type].m_bLocked = false;
m_RP.m_PS.m_MeshUpdateBytes += size*vertexcount;
}
else
if (dest->m_VS[Type].m_bLocked && bUnLock)
{
tvert->Unlock();
dest->m_VS[Type].m_bLocked = false;
}
}
void CD3D9Renderer::UnlockBuffer(CVertexBuffer *buf, int Type)
{
if (!buf->m_VS[Type].m_bLocked)
return;
if (m_bDeviceLost)
return;
if (buf->m_bFenceSet)
{
UnlockVB3D(Type+1);
buf->m_VS[Type].m_bLocked = false;
return;
}
IDirect3DVertexBuffer9 *tvert;
tvert = (IDirect3DVertexBuffer9 *)buf->GetStream(Type, NULL);
HRESULT hr = tvert->Unlock();
buf->m_VS[Type].m_bLocked = false;
}
///////////////////////////////////////////
void CD3D9Renderer::ReleaseBuffer(CVertexBuffer *bufptr)
{
if (bufptr)
{
m_CurVertBufferSize -= m_VertexSize[bufptr->m_vertexformat]*bufptr->m_NumVerts;
if (bufptr->m_VS[VSF_TANGENTS].m_VertBuf.m_pPtr)
m_CurVertBufferSize -= sizeof(SPipTangents)*bufptr->m_NumVerts;
IDirect3DVertexBuffer9 *vtemp;
if (bufptr->m_VS[VSF_GENERAL].m_pPool)
{
TVertPool *pPool = (TVertPool *)bufptr->m_VS[VSF_GENERAL].m_pPool;
if (ReleaseVBChunk(pPool, &bufptr->m_VS[VSF_GENERAL]))
{
IDirect3DVertexBuffer9 *vtemp = pPool->m_pVB;
SAFE_RELEASE(vtemp);
pPool->Unlink();
delete pPool;
}
}
else
{
vtemp = (IDirect3DVertexBuffer9 *)bufptr->m_VS[VSF_GENERAL].m_VertBuf.m_pPtr;
#ifdef _DEBUG
if (vtemp)
sRemoveVB(vtemp, &bufptr->m_VS[VSF_GENERAL]);
#endif
SAFE_RELEASE(vtemp);
bufptr->m_VS[VSF_GENERAL].m_VertBuf.m_pPtr = NULL;
}
if (bufptr->m_VS[VSF_TANGENTS].m_pPool)
{
TVertPool *pPool = (TVertPool *)bufptr->m_VS[VSF_TANGENTS].m_pPool;
if (ReleaseVBChunk(pPool, &bufptr->m_VS[VSF_TANGENTS]))
{
IDirect3DVertexBuffer9 *vtemp = pPool->m_pVB;
SAFE_RELEASE(vtemp);
pPool->Unlink();
delete pPool;
}
}
else
{
vtemp = (IDirect3DVertexBuffer9 *)bufptr->m_VS[VSF_TANGENTS].m_VertBuf.m_pPtr;
#ifdef _DEBUG
if (vtemp)
sRemoveVB(vtemp, &bufptr->m_VS[VSF_TANGENTS]);
#endif
SAFE_RELEASE(vtemp);
bufptr->m_VS[VSF_TANGENTS].m_VertBuf.m_pPtr = NULL;
}
delete bufptr;
}
}
#include "../Common/NvTriStrip/NVTriStrip.h"
///////////////////////////////////////////
void CD3D9Renderer::DrawBuffer(CVertexBuffer *src,SVertexStream *indicies,int numindices,int offsindex,int prmode,int vert_start,int vert_stop, CMatInfo *mi)
{
if (m_bDeviceLost)
return;
if (CV_d3d9_forcesoftware)
return;
if (!m_SceneRecurseCount)
{
iLog->Log("ERROR: CD3D9Renderer::DrawBuffer before BeginScene");
return;
}
if (!indicies->m_VertBuf.m_pPtr || !src)
return;
PROFILE_FRAME(Draw_IndexMesh);
int size = numindices * sizeof(short);
if (src->m_VS[VSF_GENERAL].m_bLocked)
{
IDirect3DVertexBuffer9 *tvert = (IDirect3DVertexBuffer9 *)src->m_VS[VSF_GENERAL].m_VertBuf.m_pPtr;
tvert->Unlock();
src->m_VS[VSF_GENERAL].m_bLocked = false;
}
IDirect3DIndexBuffer9 *ibuf = (IDirect3DIndexBuffer9 *)indicies->m_VertBuf.m_pPtr;
HRESULT h = EF_SetVertexDeclaration(0, src->m_vertexformat);
int nOffs;
IDirect3DVertexBuffer9 *pBuf = (IDirect3DVertexBuffer9 *)src->GetStream(VSF_GENERAL, &nOffs);
h = m_pd3dDevice->SetStreamSource( 0, pBuf, nOffs, m_VertexSize[src->m_vertexformat]);
h = m_pd3dDevice->SetIndices(ibuf);
int NumVerts = src->m_NumVerts;
if (vert_stop)
NumVerts = vert_stop;
switch(prmode)
{
case R_PRIMV_TRIANGLES:
h = m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,NumVerts,offsindex,numindices/3);
m_nPolygons+=numindices/3;
break;
case R_PRIMV_TRIANGLE_STRIP:
h = m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,0,0,NumVerts,offsindex,numindices-2);
m_nPolygons+=numindices-2;
break;
case R_PRIMV_MULTI_GROUPS:
{
if (mi)
{
int offs = mi->nFirstIndexId;
int nGroups = mi->m_dwNumSections;
SPrimitiveGroup *gr = mi->m_pPrimitiveGroups;
if (gr)
{
for (int i=0; i<nGroups; i++)
{
SPrimitiveGroup *g = &gr[i];
switch (g->type)
{
case PT_STRIP:
if (FAILED(h=m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, mi->nNumVerts, g->offsIndex+offs, g->numIndices - 2)))
{
Error("CD3D9Renderer::DrawBuffer: DrawIndexedPrimitive error", h);
return;
}
m_nPolygons += (g->numIndices - 2);
break;
case PT_LIST:
if (FAILED(h=m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mi->nNumVerts, g->offsIndex+offs, g->numIndices / 3)))
{
Error("CD3D9Renderer::DrawBuffer: DrawIndexedPrimitive error", h);
return;
}
m_nPolygons += (g->numIndices / 3);
break;
case PT_FAN:
if (FAILED(h=m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLEFAN, 0, 0, mi->nNumVerts, g->offsIndex+offs, g->numIndices - 2)))
{
Error("CD3D9Renderer::DrawBuffer: DrawIndexedPrimitive error", h);
return;
}
m_nPolygons += (g->numIndices - 2);
break;
}
}
}
}
}
break;
}
}

View File

@@ -0,0 +1,48 @@
#include "RenderPCH.h"
#include "DriverD3D9.h"
#include "I3dengine.h"
void CD3D9Renderer::PrepareOutSpaceTextures(CREOutSpace * pRE)
{
int arrnResult[2];
ScanOutSpaceCube(pRE->m_TexID, iSystem->GetViewCamera().GetPos(), arrnResult);
}
void CD3D9Renderer::DrawOutSpaceSide( const float *angle, const Vec3d & Pos, int tex_size, int offsetX, int offsetY)
{
if (!iSystem)
return;
CRenderer * renderer = gRenDev;
CCamera tmp_camera = renderer->GetCamera();
CCamera prevCamera = tmp_camera;
tmp_camera.Init(tex_size,tex_size);
tmp_camera.SetPos(Pos);
tmp_camera.SetAngle(Vec3d(angle[0], angle[1], angle[2]));
tmp_camera.Update();
iSystem->SetViewCamera(tmp_camera);
gRenDev->SetCamera(tmp_camera);
gRenDev->SetViewport(tex_size*offsetX, tex_size*offsetY, tex_size, tex_size);
I3DEngine *eng = (I3DEngine *)iSystem->GetIProcess();
eng->SetCamera(tmp_camera,false );
eng->DrawLowDetail(0);
iSystem->SetViewCamera(prevCamera);
gRenDev->SetCamera(prevCamera);
}
void CD3D9Renderer::ScanOutSpaceCube(uint & nTexID, const Vec3d & vPos, int * pResult)
{
}
bool CREOutSpace::mfDraw(SShader *ef, SShaderPass *sfm)
{
return true;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,101 @@
#ifndef _DynamicIB_H_
#define _DynamicIB_H_
template <class Type> class DynamicIB
{
private :
LPDIRECT3DINDEXBUFFER9 m_pIB;
uint m_Count;
int m_nOffs;
bool m_bLocked;
Type* m_pLockedData;
public :
uint GetCount() const
{
return m_Count;
}
int GetOffset() const
{
return m_nOffs;
}
void Reset()
{
m_nOffs = 0;
}
DynamicIB(const LPDIRECT3DDEVICE9 pD3D, const unsigned int& theElementsCount)
{
m_pIB = 0;
m_bLocked = false;
m_pLockedData = NULL;
m_nOffs = 0;
m_Count = theElementsCount;
HRESULT hr = pD3D->CreateIndexBuffer(theElementsCount*sizeof(Type), D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, sizeof(Type)==2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &m_pIB, NULL);
assert((hr == D3D_OK) && (m_pIB));
}
LPDIRECT3DVERTEXBUFFER9 GetInterface() const { return m_pIB; }
Type* Lock(const unsigned int& theLockCount, int &nOffs)
{
if (theLockCount > m_Count)
{
assert(false);
return NULL;
}
if (m_bLocked)
return m_pLockedData;
HRESULT hr;
if ( m_pIB )
{
if (theLockCount+m_nOffs > m_Count)
{
hr = m_pIB->Lock(0, theLockCount*sizeof(Type), (void **) &m_pLockedData, D3DLOCK_DISCARD);
nOffs = 0;
m_nOffs = theLockCount;
}
else
{
hr = m_pIB->Lock(m_nOffs*sizeof(Type), theLockCount*sizeof(Type), (void **) &m_pLockedData, D3DLOCK_NOOVERWRITE);
nOffs = m_nOffs;
m_nOffs += theLockCount;
}
assert(m_pLockedData != NULL);
m_bLocked = true;
}
return m_pLockedData;
}
void Unlock()
{
if ((m_bLocked) && (m_pIB))
{
HRESULT hr = m_pIB->Unlock();
assert( hr == D3D_OK );
m_bLocked = false;
}
}
HRESULT Bind(const LPDIRECT3DDEVICE9 pD3D)
{
return pD3D->SetIndices(m_pIB);
}
~DynamicIB()
{
Unlock();
SAFE_RELEASE(m_pIB);
}
};
#endif _DynamicIB_H_

View File

@@ -0,0 +1,101 @@
#ifndef _DynamicVB_H_
#define _DynamicVB_H_
template <class VertexType> class DynamicVB
{
private :
LPDIRECT3DVERTEXBUFFER9 m_pVB;
uint m_BytesCount;
int m_nBytesOffs;
bool m_bLocked;
VertexType* m_pLockedData;
public :
uint GetBytesCount() const
{
return m_BytesCount;
}
int GetBytesOffset() const
{
return m_nBytesOffs;
}
void Reset()
{
m_nBytesOffs = m_BytesCount;
}
DynamicVB(const LPDIRECT3DDEVICE9 pD3D, const DWORD& theFVF, const unsigned int& theVertsCount )
{
m_pVB = 0;
m_bLocked = false;
m_pLockedData = NULL;
m_nBytesOffs = 0;
m_BytesCount = theVertsCount * sizeof(VertexType);
HRESULT hr = pD3D->CreateVertexBuffer(m_BytesCount, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, theFVF, D3DPOOL_DEFAULT, &m_pVB, NULL);
assert((hr == D3D_OK) && (m_pVB));
}
LPDIRECT3DVERTEXBUFFER9 GetInterface() const { return m_pVB; }
VertexType* Lock(const unsigned int& theLockBytesCount, int &nOffs)
{
if (theLockBytesCount > m_BytesCount)
{
assert(false);
return NULL;
}
if (m_bLocked)
return m_pLockedData;
HRESULT hr;
if ( m_pVB )
{
if (theLockBytesCount+m_nBytesOffs > m_BytesCount)
{
hr = m_pVB->Lock(0, theLockBytesCount, (void **) &m_pLockedData, D3DLOCK_DISCARD);
nOffs = 0;
m_nBytesOffs = theLockBytesCount;
}
else
{
hr = m_pVB->Lock(m_nBytesOffs, theLockBytesCount, (void **) &m_pLockedData, D3DLOCK_NOOVERWRITE);
nOffs = m_nBytesOffs;
m_nBytesOffs += theLockBytesCount;
}
assert(m_pLockedData != NULL);
m_bLocked = true;
}
return m_pLockedData;
}
void Unlock()
{
if ((m_bLocked) && (m_pVB))
{
HRESULT hr = m_pVB->Unlock();
assert( hr == D3D_OK );
m_bLocked = false;
}
}
HRESULT Bind(const LPDIRECT3DDEVICE9 pD3D, uint StreamNumber, int nBytesOffset, int Stride)
{
return pD3D->SetStreamSource(StreamNumber, m_pVB, nBytesOffset, Stride);
}
~DynamicVB()
{
Unlock();
SAFE_RELEASE(m_pVB);
}
};
#endif _DynamicVB_H_

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,88 @@
#ifndef _STATICIB_H_
#define _STATICIB_H_
/////////////////////////////
// D. Sim Dietrich Jr.
// sim.dietrich@nvidia.com
//////////////////////
template < class IndexType > class StaticIB
{
private :
LPDIRECT3DINDEXBUFFER9 mpIB;
uint mIndexCount;
bool mbLocked;
IndexType* m_pLockedData;
public :
unsigned int GetIndexCount() const
{
return mIndexCount;
}
StaticIB( const LPDIRECT3DDEVICE9 pD3D, const unsigned int& theIndexCount )
{
mpIB = 0;
mbLocked = false;
mIndexCount = theIndexCount;
HRESULT hr = pD3D->CreateIndexBuffer( mIndexCount * sizeof( IndexType ), D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &mpIB, NULL);
ASSERT( ( hr == D3D_OK ) && ( mpIB ) );
}
LPDIRECT3DINDEXBUFFER9 GetInterface() const { return mpIB; }
IndexType* Lock( const unsigned int& theLockCount, unsigned int& theStartIndex )
{
// Ensure there is enough space in the IB for this data
ASSERT ( theLockCount <= mIndexCount );
if (mbLocked)
return m_pLockedData;
if ( mpIB )
{
DWORD dwFlags = D3DLOCK_DISCARD;
DWORD dwSize = 0;
HRESULT hr = mpIB->Lock( 0, 0, reinterpret_cast<void**>( &m_pLockedData ), dwFlags );
ASSERT( hr == D3D_OK );
ASSERT( m_pLockedData != 0 );
mbLocked = true;
theStartIndex = 0;
}
return m_pLockedData;
}
void Unlock()
{
if ( ( mbLocked ) && ( mpIB ) )
{
HRESULT hr = mpIB->Unlock();
ASSERT( hr == D3D_OK );
mbLocked = false;
}
}
~StaticIB()
{
Unlock();
if ( mpIB )
{
mpIB->Release();
}
}
};
typedef StaticIB< unsigned short > StaticIB16;
typedef StaticIB< unsigned int > StaticIB32;
#endif _STATICIB_H_

View File

@@ -0,0 +1,81 @@
#ifndef _StaticVB_H_
#define _StaticVB_H_
template <class VertexType> class StaticVB
{
private :
LPDIRECT3DVERTEXBUFFER9 mpVB;
uint mVertexCount;
bool mbLocked;
VertexType* m_pLockedData;
public :
uint GetVertexCount() const
{
return mVertexCount;
}
StaticVB( const LPDIRECT3DDEVICE9 pD3D, const DWORD& theFVF, const unsigned int& theVertexCount )
{
mpVB = 0;
mbLocked = false;
m_pLockedData = NULL;
mVertexCount = theVertexCount;
HRESULT hr = pD3D->CreateVertexBuffer( mVertexCount * sizeof( VertexType ), D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, theFVF, D3DPOOL_DEFAULT, &mpVB, NULL);
ASSERT( ( hr == D3D_OK ) && ( mpVB ) );
}
LPDIRECT3DVERTEXBUFFER9 GetInterface() const { return mpVB; }
VertexType* Lock( const unsigned int& theLockCount, unsigned int& theStartVertex )
{
theStartVertex = 0;
// Ensure there is enough space in the VB for this data
ASSERT ( theLockCount <= mVertexCount );
if (mbLocked)
return m_pLockedData;
if ( mpVB )
{
DWORD dwFlags = D3DLOCK_DISCARD;
DWORD dwSize = 0;
HRESULT hr = mpVB->Lock( 0, 0, reinterpret_cast<void**>( &m_pLockedData ), dwFlags );
ASSERT( hr == D3D_OK );
ASSERT( m_pLockedData != 0 );
mbLocked = true;
}
return m_pLockedData;
}
void Unlock()
{
if ( ( mbLocked ) && ( mpVB ) )
{
HRESULT hr = mpVB->Unlock();
ASSERT( hr == D3D_OK );
mbLocked = false;
}
}
~StaticVB()
{
Unlock();
if ( mpVB )
{
mpVB->Release();
}
}
};
#endif _StaticVB_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = "file:F:\\Crytek\\RenderDll\\XRenderD3D9\\XRenderD3D9.vcproj"
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT"
}

View File

@@ -0,0 +1,567 @@
//-----------------------------------------------------------------------------
// File: GetDXVer.cpp
//
// Desc: Demonstrates how applications can detect what version of DirectX
// is installed.
//
// (C) Copyright Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define INITGUID
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#ifndef WIN64
#include <dxdiag.h>
#endif
HRESULT GetDirectXVersionViaDxDiag( DWORD* pdwDirectXVersionMajor, DWORD* pdwDirectXVersionMinor, TCHAR* pcDirectXVersionLetter );
HRESULT GetDirectXVerionViaFileVersions( DWORD* pdwDirectXVersionMajor, DWORD* pdwDirectXVersionMinor, TCHAR* pcDirectXVersionLetter );
HRESULT GetFileVersion( TCHAR* szPath, ULARGE_INTEGER* pllFileVersion );
ULARGE_INTEGER MakeInt64( WORD a, WORD b, WORD c, WORD d );
int CompareLargeInts( ULARGE_INTEGER ullParam1, ULARGE_INTEGER ullParam2 );
//-----------------------------------------------------------------------------
// Name: GetDXVersion()
// Desc: This function returns the DirectX version.
// Arguments:
// pdwDirectXVersion - This can be NULL. If non-NULL, the return value is:
// 0x00000000 = No DirectX installed
// 0x00010000 = DirectX 1.0 installed
// 0x00020000 = DirectX 2.0 installed
// 0x00030000 = DirectX 3.0 installed
// 0x00030001 = DirectX 3.0a installed
// 0x00050000 = DirectX 5.0 installed
// 0x00060000 = DirectX 6.0 installed
// 0x00060100 = DirectX 6.1 installed
// 0x00060101 = DirectX 6.1a installed
// 0x00070000 = DirectX 7.0 installed
// 0x00070001 = DirectX 7.0a installed
// 0x00080000 = DirectX 8.0 installed
// 0x00080100 = DirectX 8.1 installed
// 0x00080101 = DirectX 8.1a installed
// 0x00080102 = DirectX 8.1b installed
// 0x00080200 = DirectX 8.2 installed
// 0x00090000 = DirectX 9.0 installed
// strDirectXVersion - Destination string to receive a string name of the DirectX Version. Can be NULL.
// cchDirectXVersion - Size of destination buffer in characters. Length should be at least 10 chars.
// Returns: S_OK if the function succeeds.
// E_FAIL if the DirectX version info couldn't be determined.
//
// Please note that this code is intended as a general guideline. Your
// app will probably be able to simply query for functionality (via
// QueryInterface) for one or two components.
//
// Also please ensure your app will run on future releases of DirectX.
// For example:
// "if( dwDirectXVersion != 0x00080100 ) return false;" is VERY BAD.
// "if( dwDirectXVersion < 0x00080100 ) return false;" is MUCH BETTER.
//-----------------------------------------------------------------------------
HRESULT GetDXVersion( DWORD* pdwDirectXVersion, TCHAR* strDirectXVersion, int cchDirectXVersion )
{
bool bGotDirectXVersion = false;
// Init values to unknown
if( pdwDirectXVersion )
*pdwDirectXVersion = 0;
if( strDirectXVersion && cchDirectXVersion > 0 )
strDirectXVersion[0] = 0;
DWORD dwDirectXVersionMajor = 0;
DWORD dwDirectXVersionMinor = 0;
TCHAR cDirectXVersionLetter = ' ';
// First, try to use dxdiag's COM interface to get the DirectX version.
// The only downside is this will only work on DX9 or later.
if( SUCCEEDED( GetDirectXVersionViaDxDiag( &dwDirectXVersionMajor, &dwDirectXVersionMinor, &cDirectXVersionLetter ) ) )
bGotDirectXVersion = true;
if( !bGotDirectXVersion )
{
// Getting the DirectX version info from DxDiag failed,
// so most likely we are on DX8.x or earlier
if( SUCCEEDED( GetDirectXVerionViaFileVersions( &dwDirectXVersionMajor, &dwDirectXVersionMinor, &cDirectXVersionLetter ) ) )
bGotDirectXVersion = true;
}
// If both techniques failed, then return E_FAIL
if( !bGotDirectXVersion )
return E_FAIL;
// Set the output values to what we got and return
cDirectXVersionLetter = (char)tolower(cDirectXVersionLetter);
if( pdwDirectXVersion )
{
// If pdwDirectXVersion is non-NULL, then set it to something
// like 0x00080102 which would represent DX8.1b
DWORD dwDirectXVersion = dwDirectXVersionMajor;
dwDirectXVersion <<= 8;
dwDirectXVersion += dwDirectXVersionMinor;
dwDirectXVersion <<= 8;
if( cDirectXVersionLetter >= 'a' && cDirectXVersionLetter <= 'z' )
dwDirectXVersion += (cDirectXVersionLetter - 'a') + 1;
*pdwDirectXVersion = dwDirectXVersion;
}
if( strDirectXVersion && cchDirectXVersion > 0 )
{
// If strDirectXVersion is non-NULL, then set it to something
// like "8.1b" which would represent DX8.1b
if( cDirectXVersionLetter == ' ' )
_sntprintf( strDirectXVersion, cchDirectXVersion, TEXT("%d.%d"), dwDirectXVersionMajor, dwDirectXVersionMinor );
else
_sntprintf( strDirectXVersion, cchDirectXVersion, TEXT("%d.%d%c"), dwDirectXVersionMajor, dwDirectXVersionMinor, cDirectXVersionLetter );
strDirectXVersion[cchDirectXVersion-1] = 0;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: GetDirectXVersionViaDxDiag()
// Desc: Tries to get the DirectX version from DxDiag's COM interface
//-----------------------------------------------------------------------------
HRESULT GetDirectXVersionViaDxDiag( DWORD* pdwDirectXVersionMajor,
DWORD* pdwDirectXVersionMinor,
TCHAR* pcDirectXVersionLetter )
{
#ifndef WIN64
HRESULT hr;
bool bCleanupCOM = false;
bool bSuccessGettingMajor = false;
bool bSuccessGettingMinor = false;
bool bSuccessGettingLetter = false;
// Init COM. COM may fail if its already been inited with a different
// concurrency model. And if it fails you shouldn't release it.
hr = CoInitialize(NULL);
bCleanupCOM = SUCCEEDED(hr);
// Get an IDxDiagProvider
bool bGotDirectXVersion = false;
IDxDiagProvider* pDxDiagProvider = NULL;
hr = CoCreateInstance( CLSID_DxDiagProvider,
NULL,
CLSCTX_INPROC_SERVER,
IID_IDxDiagProvider,
(LPVOID*) &pDxDiagProvider );
if( SUCCEEDED(hr) )
{
// Fill out a DXDIAG_INIT_PARAMS struct
DXDIAG_INIT_PARAMS dxDiagInitParam;
ZeroMemory( &dxDiagInitParam, sizeof(DXDIAG_INIT_PARAMS) );
dxDiagInitParam.dwSize = sizeof(DXDIAG_INIT_PARAMS);
dxDiagInitParam.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION;
dxDiagInitParam.bAllowWHQLChecks = false;
dxDiagInitParam.pReserved = NULL;
// Init the m_pDxDiagProvider
hr = pDxDiagProvider->Initialize( &dxDiagInitParam );
if( SUCCEEDED(hr) )
{
IDxDiagContainer* pDxDiagRoot = NULL;
IDxDiagContainer* pDxDiagSystemInfo = NULL;
// Get the DxDiag root container
hr = pDxDiagProvider->GetRootContainer( &pDxDiagRoot );
if( SUCCEEDED(hr) )
{
// Get the object called DxDiag_SystemInfo
hr = pDxDiagRoot->GetChildContainer( L"DxDiag_SystemInfo", &pDxDiagSystemInfo );
if( SUCCEEDED(hr) )
{
VARIANT var;
VariantInit( &var );
// Get the "dwDirectXVersionMajor" property
hr = pDxDiagSystemInfo->GetProp( L"dwDirectXVersionMajor", &var );
if( SUCCEEDED(hr) && var.vt == VT_UI4 )
{
if( pdwDirectXVersionMajor )
*pdwDirectXVersionMajor = var.ulVal;
bSuccessGettingMajor = true;
}
VariantClear( &var );
// Get the "dwDirectXVersionMinor" property
hr = pDxDiagSystemInfo->GetProp( L"dwDirectXVersionMinor", &var );
if( SUCCEEDED(hr) && var.vt == VT_UI4 )
{
if( pdwDirectXVersionMinor )
*pdwDirectXVersionMinor = var.ulVal;
bSuccessGettingMinor = true;
}
VariantClear( &var );
// Get the "szDirectXVersionLetter" property
hr = pDxDiagSystemInfo->GetProp( L"szDirectXVersionLetter", &var );
if( SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL )
{
#ifdef UNICODE
*pcDirectXVersionLetter = var.bstrVal[0];
#else
char strDestination[10];
WideCharToMultiByte( CP_ACP, 0, var.bstrVal, -1, strDestination, 10*sizeof(CHAR), NULL, NULL );
if( pcDirectXVersionLetter )
*pcDirectXVersionLetter = strDestination[0];
#endif
bSuccessGettingLetter = true;
}
VariantClear( &var );
// If it all worked right, then mark it down
if( bSuccessGettingMajor && bSuccessGettingMinor && bSuccessGettingLetter )
bGotDirectXVersion = true;
pDxDiagSystemInfo->Release();
}
pDxDiagRoot->Release();
}
}
pDxDiagProvider->Release();
}
if( bCleanupCOM )
CoUninitialize();
if( bGotDirectXVersion )
return S_OK;
else
return E_FAIL;
#else
*pdwDirectXVersionMajor = 9;
*pdwDirectXVersionMinor = 1;
strcpy(pcDirectXVersionLetter, "DirectX9.1 beta AMD64 build");
return S_OK;
#endif
}
//-----------------------------------------------------------------------------
// Name: GetDirectXVerionViaFileVersions()
// Desc: Tries to get the DirectX version by looking at DirectX file versions
//-----------------------------------------------------------------------------
HRESULT GetDirectXVerionViaFileVersions( DWORD* pdwDirectXVersionMajor,
DWORD* pdwDirectXVersionMinor,
TCHAR* pcDirectXVersionLetter )
{
ULARGE_INTEGER llFileVersion;
TCHAR szPath[512];
TCHAR szFile[512];
BOOL bFound = false;
if( GetSystemDirectory( szPath, MAX_PATH ) != 0 )
{
szPath[MAX_PATH-1]=0;
// Switch off the ddraw version
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\ddraw.dll") );
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
if( CompareLargeInts( llFileVersion, MakeInt64( 4, 2, 0, 95 ) ) >= 0 ) // Win9x version
{
// flle is >= DX1.0 version, so we must be at least DX1.0
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 1;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
if( CompareLargeInts( llFileVersion, MakeInt64( 4, 3, 0, 1096 ) ) >= 0 ) // Win9x version
{
// flle is is >= DX2.0 version, so we must DX2.0 or DX2.0a (no redist change)
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 2;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
if( CompareLargeInts( llFileVersion, MakeInt64( 4, 4, 0, 68 ) ) >= 0 ) // Win9x version
{
// flle is is >= DX3.0 version, so we must be at least DX3.0
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 3;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
}
// Switch off the d3drg8x.dll version
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\d3drg8x.dll") );
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
if( CompareLargeInts( llFileVersion, MakeInt64( 4, 4, 0, 70 ) ) >= 0 ) // Win9x version
{
// d3drg8x.dll is the DX3.0a version, so we must be DX3.0a or DX3.0b (no redist change)
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 3;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT('a');
bFound = true;
}
}
// Switch off the ddraw version
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\ddraw.dll") );
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
if( CompareLargeInts( llFileVersion, MakeInt64( 4, 5, 0, 155 ) ) >= 0 ) // Win9x version
{
// ddraw.dll is the DX5.0 version, so we must be DX5.0 or DX5.2 (no redist change)
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 5;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
if( CompareLargeInts( llFileVersion, MakeInt64( 4, 6, 0, 318 ) ) >= 0 ) // Win9x version
{
// ddraw.dll is the DX6.0 version, so we must be at least DX6.0
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 6;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
if( CompareLargeInts( llFileVersion, MakeInt64( 4, 6, 0, 436 ) ) >= 0 ) // Win9x version
{
// ddraw.dll is the DX6.1 version, so we must be at least DX6.1
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 6;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 1;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
}
// Switch off the dplayx.dll version
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\dplayx.dll") );
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
if( CompareLargeInts( llFileVersion, MakeInt64( 4, 6, 3, 518 ) ) >= 0 ) // Win9x version
{
// ddraw.dll is the DX6.1 version, so we must be at least DX6.1a
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 6;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 1;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT('a');
bFound = true;
}
}
// Switch off the ddraw version
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\ddraw.dll") );
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
if( CompareLargeInts( llFileVersion, MakeInt64( 4, 7, 0, 700 ) ) >= 0 ) // Win9x version
{
// TODO: find win2k version
// ddraw.dll is the DX7.0 version, so we must be at least DX7.0
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 7;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
}
// Switch off the dinput version
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\dinput.dll") );
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
if( CompareLargeInts( llFileVersion, MakeInt64( 4, 7, 0, 716 ) ) >= 0 ) // Win9x version
{
// ddraw.dll is the DX7.0 version, so we must be at least DX7.0a
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 7;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT('a');
bFound = true;
}
}
// Switch off the ddraw version
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\ddraw.dll") );
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
if( (HIWORD(llFileVersion.HighPart) == 4 && CompareLargeInts( llFileVersion, MakeInt64( 4, 8, 0, 400 ) ) >= 0) || // Win9x version
(HIWORD(llFileVersion.HighPart) == 5 && CompareLargeInts( llFileVersion, MakeInt64( 5, 1, 2258, 400 ) ) >= 0) ) // Win2k/WinXP version
{
// ddraw.dll is the DX8.0 version, so we must be at least DX8.0 or DX8.0a (no redist change)
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 8;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
}
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\d3d8.dll"));
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
if( (HIWORD(llFileVersion.HighPart) == 4 && CompareLargeInts( llFileVersion, MakeInt64( 4, 8, 1, 881 ) ) >= 0) || // Win9x version
(HIWORD(llFileVersion.HighPart) == 5 && CompareLargeInts( llFileVersion, MakeInt64( 5, 1, 2600, 881 ) ) >= 0) ) // Win2k/WinXP version
{
// d3d8.dll is the DX8.1 version, so we must be at least DX8.1
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 8;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 1;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
if( (HIWORD(llFileVersion.HighPart) == 4 && CompareLargeInts( llFileVersion, MakeInt64( 4, 8, 1, 901 ) ) >= 0) || // Win9x version
(HIWORD(llFileVersion.HighPart) == 5 && CompareLargeInts( llFileVersion, MakeInt64( 5, 1, 2600, 901 ) ) >= 0) ) // Win2k/WinXP version
{
// d3d8.dll is the DX8.1a version, so we must be at least DX8.1a
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 8;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 1;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT('a');
bFound = true;
}
}
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\mpg2splt.ax"));
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
if( CompareLargeInts( llFileVersion, MakeInt64( 6, 3, 1, 885 ) ) >= 0 ) // Win9x/Win2k/WinXP version
{
// quartz.dll is the DX8.1b version, so we must be at least DX8.1b
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 8;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 1;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT('b');
bFound = true;
}
}
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\dpnet.dll"));
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
if( (HIWORD(llFileVersion.HighPart) == 4 && CompareLargeInts( llFileVersion, MakeInt64( 4, 9, 0, 134 ) ) >= 0) || // Win9x version
(HIWORD(llFileVersion.HighPart) == 5 && CompareLargeInts( llFileVersion, MakeInt64( 5, 2, 3677, 134 ) ) >= 0) ) // Win2k/WinXP version
{
// dpnet.dll is the DX8.2 version, so we must be at least DX8.2
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 8;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 2;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
}
_tcscpy( szFile, szPath );
_tcscat( szFile, TEXT("\\d3d9.dll"));
if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) )
{
// File exists, but be at least DX9
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 9;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
bFound = true;
}
}
if( !bFound )
{
// No DirectX installed
if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 0;
if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0;
if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' ');
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: GetFileVersion()
// Desc: Returns ULARGE_INTEGER with a file version of a file, or a failure code.
//-----------------------------------------------------------------------------
HRESULT GetFileVersion( TCHAR* szPath, ULARGE_INTEGER* pllFileVersion )
{
if( szPath == NULL || pllFileVersion == NULL )
return E_INVALIDARG;
DWORD dwHandle;
UINT cb;
cb = GetFileVersionInfoSize( szPath, &dwHandle );
if (cb > 0)
{
BYTE* pFileVersionBuffer = new BYTE[cb];
if( pFileVersionBuffer == NULL )
return E_OUTOFMEMORY;
if (GetFileVersionInfo( szPath, 0, cb, pFileVersionBuffer))
{
VS_FIXEDFILEINFO* pVersion = NULL;
if (VerQueryValue(pFileVersionBuffer, TEXT("\\"), (VOID**)&pVersion, &cb) &&
pVersion != NULL)
{
pllFileVersion->HighPart = pVersion->dwFileVersionMS;
pllFileVersion->LowPart = pVersion->dwFileVersionLS;
delete[] pFileVersionBuffer;
return S_OK;
}
}
delete[] pFileVersionBuffer;
}
return E_FAIL;
}
//-----------------------------------------------------------------------------
// Name: MakeInt64()
// Desc: Returns a ULARGE_INTEGER where a<<48|b<<32|c<<16|d<<0
//-----------------------------------------------------------------------------
ULARGE_INTEGER MakeInt64( WORD a, WORD b, WORD c, WORD d )
{
ULARGE_INTEGER ull;
ull.HighPart = MAKELONG(b,a);
ull.LowPart = MAKELONG(d,c);
return ull;
}
//-----------------------------------------------------------------------------
// Name: CompareLargeInts()
// Desc: Returns 1 if ullParam1 > ullParam2
// Returns 0 if ullParam1 = ullParam2
// Returns -1 if ullParam1 < ullParam2
//-----------------------------------------------------------------------------
int CompareLargeInts( ULARGE_INTEGER ullParam1, ULARGE_INTEGER ullParam2 )
{
if( ullParam1.HighPart > ullParam2.HighPart )
return 1;
if( ullParam1.HighPart < ullParam2.HighPart )
return -1;
if( ullParam1.LowPart > ullParam2.LowPart )
return 1;
if( ullParam1.LowPart < ullParam2.LowPart )
return -1;
return 0;
}