Merge branch 'master' into master

This commit is contained in:
la
2026-03-02 12:49:45 +10:00
committed by GitHub
36 changed files with 3665 additions and 3747 deletions
+2 -2
View File
@@ -2,6 +2,8 @@
#include "4J_Render.h"
#include "Renderer.h"
C4JRender RenderManager;
void C4JRender::Tick()
{
#if _DEBUG
@@ -477,5 +479,3 @@ void C4JRender::Resume()
{
InternalRenderManager.Resume();
}
C4JRender RenderManager;
+1 -1
View File
@@ -22,7 +22,7 @@ void main(
*/
static unsigned char PS_ForceLOD_Data[] =
static unsigned char g_main_PS_ForceLOD[] =
{
0x44, 0x58, 0x42, 0x43, 0x8A, 0x1E, 0x45, 0x87, 0xE0, 0xB2,
0xDE, 0x2C, 0x00, 0x06, 0x9B, 0x08, 0x7F, 0x92, 0xEA, 0xE6,
+1 -1
View File
@@ -11,7 +11,7 @@ void main(
*/
static unsigned char PS_ScreenClear_Data[] =
static unsigned char g_main_PS_ScreenClear[] =
{
0x44, 0x58, 0x42, 0x43, 0xF5, 0xD0, 0x7D, 0x98, 0xF4, 0x78,
0x62, 0xB1, 0x25, 0x1A, 0x74, 0x57, 0xF0, 0x48, 0x57, 0x90,
+1 -1
View File
@@ -12,7 +12,7 @@ void main(
*/
static unsigned char PS_ScreenSpace_Data[] =
static unsigned char g_main_PS_ScreenSpace[] =
{
0x44, 0x58, 0x42, 0x43, 0xB8, 0xC0, 0x6E, 0x7D, 0xDE, 0x9F,
0x85, 0xBA, 0x86, 0xB9, 0x41, 0xAB, 0xCA, 0x09, 0x13, 0x95,
+1 -1
View File
@@ -30,7 +30,7 @@ void main(
*/
static unsigned char PS_Standard_Data[] =
static unsigned char g_main_PS_Standard[] =
{
0x44, 0x58, 0x42, 0x43, 0x3E, 0xD7, 0x47, 0x3D, 0x43, 0x30,
0xB0, 0x7E, 0x8F, 0xF4, 0xBD, 0xA7, 0xCA, 0xCF, 0x70, 0x12,
@@ -23,7 +23,7 @@ void main(
*/
static unsigned char PS_TextureProjection_Data[] =
static unsigned char g_main_PS_TextureProjection[] =
{
0x44, 0x58, 0x42, 0x43, 0x31, 0x2E, 0x38, 0xEB, 0x1E, 0x13,
0x9F, 0xFA, 0xC3, 0x6B, 0xC2, 0x09, 0xD6, 0xCC, 0xBF, 0x4E,
+408 -406
View File
@@ -4,448 +4,450 @@
#include <unordered_map>
#include <vector>
#define MATRIX_MODE_MODELVIEW 0
#define MATRIX_MODE_MODELVIEW_PROJECTION 1
#define MATRIX_MODE_MODELVIEW_TEXTURE 2
#define MATRIX_MODE_MODELVIEW_CBUFF 3
#define MATRIX_MODE_MODELVIEW_MAX 4
#define STACK_TYPES 4
#define STACK_SIZE 16
#define MAX_MIP_LEVELS 5
#define MAX_TEXTURES 512
#define NUM_COMMAND_HANDLES 0x800000
#define MAX_COMMAND_BUFFERS 16000
class Renderer
{
public:
struct Context;
struct CommandBuffer;
void Tick();
void UpdateGamma(unsigned short usGamma);
void MatrixMode(int type);
void MatrixSetIdentity();
void MatrixTranslate(float x, float y, float z);
void MatrixRotate(float angle, float x, float y, float z);
void MatrixScale(float x, float y, float z);
void MatrixPerspective(float fovy, float aspect, float zNear, float zFar);
void MatrixOrthogonal(float left, float right, float bottom, float top, float zNear, float zFar);
void MatrixPop();
void MatrixPush();
void MatrixMult(float* mat);
const float* MatrixGet(int type);
void Set_matrixDirty();
void Initialise(ID3D11Device* pDevice, IDXGISwapChain* pSwapChain);
ID3D11DeviceContext* InitialiseContext(bool fromPresent);
void StartFrame();
void DoScreenGrabOnNextPresent();
void Present();
void Clear(int flags, D3D11_RECT* pRect);
void SetClearColour(const float colourRGBA[4]);
bool IsWidescreen();
bool IsHiDef();
void CaptureThumbnail(ImageFileBuffer* pngOut);
void CaptureScreen(ImageFileBuffer* jpgOut, XSOCIAL_PREVIEWIMAGE* previewOut);
void BeginConditionalSurvey(int identifier);
void EndConditionalSurvey();
void BeginConditionalRendering(int identifier);
void EndConditionalRendering();
void DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count, void* dataIn, C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType);
void DrawVertexBuffer(C4JRender::ePrimitiveType PrimitiveType, int count, ID3D11Buffer* buffer, C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType);
void CBuffLockStaticCreations();
int CBuffCreate(int count);
void CBuffDelete(int first, int count);
void CBuffStart(int index, bool full);
void CBuffClear(int index);
int CBuffSize(int index);
void CBuffEnd();
bool CBuffCall(int index, bool full);
void CBuffTick();
void CBuffDeferredModeStart();
void CBuffDeferredModeEnd();
int TextureCreate();
void TextureFree(int idx);
void TextureBind(int idx);
void TextureBindVertex(int idx);
void TextureSetTextureLevels(int levels);
int TextureGetTextureLevels();
void TextureSetParam(int param, int value);
void TextureDynamicUpdateStart();
void TextureDynamicUpdateEnd();
void TextureData(int width, int height, void* data, int level, C4JRender::eTextureFormat format);
void TextureDataUpdate(int xoffset, int yoffset, int width, int height, void* data, int level);
HRESULT LoadTextureData(const char* szFilename, D3DXIMAGE_INFO* pSrcInfo, int** ppDataOut);
HRESULT LoadTextureData(BYTE* pbData, DWORD dwBytes, D3DXIMAGE_INFO* pSrcInfo, int** ppDataOut);
HRESULT SaveTextureData(const char* szFilename, D3DXIMAGE_INFO* pSrcInfo, int* ppDataOut);
HRESULT SaveTextureDataToMemory(void* pOutput, int outputCapacity, int* outputLength, int width, int height, int* ppDataIn);
void TextureGetStats();
ID3D11ShaderResourceView* TextureGetTexture(int idx);
void StateSetColour(float r, float g, float b, float a);
void StateSetDepthMask(bool enable);
void StateSetBlendEnable(bool enable);
void StateSetBlendFunc(int src, int dst);
void StateSetBlendFactor(unsigned int colour);
void StateSetAlphaFunc(int func, float param);
void StateSetDepthFunc(int func);
void StateSetFaceCull(bool enable);
void StateSetFaceCullCW(bool enable);
void StateSetLineWidth(float width);
void StateSetWriteEnable(bool red, bool green, bool blue, bool alpha);
void StateSetDepthTestEnable(bool enable);
void StateSetAlphaTestEnable(bool enable);
void StateSetDepthSlopeAndBias(float slope, float bias);
void StateSetFogEnable(bool enable);
void StateSetFogMode(int mode);
void StateSetFogNearDistance(float dist);
void StateSetFogFarDistance(float dist);
void StateSetFogDensity(float density);
void StateSetFogColour(float red, float green, float blue);
void StateSetLightingEnable(bool enable);
void StateSetVertexTextureUV(float u, float v);
void StateSetLightColour(int light, float red, float green, float blue);
void StateSetLightAmbientColour(float red, float green, float blue);
void StateSetLightDirection(int light, float x, float y, float z);
void StateSetLightEnable(int light, bool enable);
void StateSetViewport(C4JRender::eViewportType viewportType);
void StateSetEnableViewportClipPlanes(bool enable);
void StateSetTexGenCol(int col, float x, float y, float z, float w, bool eyeSpace);
void StateSetStencil(D3D11_COMPARISON_FUNC function, uint8_t stencil_ref, uint8_t stencil_func_mask, uint8_t stencil_write_mask);
void StateSetForceLOD(int LOD);
void BeginEvent(LPCWSTR eventName);
void EndEvent();
void Suspend();
bool Suspended();
void Resume();
void StateUpdate();
struct Context;
struct CommandBuffer;
void UpdateGamma(unsigned short usGamma);
void MatrixMode(int type);
void MatrixSetIdentity();
void MatrixTranslate(float x, float y, float z);
void MatrixRotate(float angle, float x, float y, float z);
void MatrixScale(float x, float y, float z);
void MatrixPerspective(float fovy, float aspect, float zNear, float zFar);
void MatrixOrthogonal(float left, float right, float bottom, float top, float zNear, float zFar);
void MatrixPop();
void MatrixPush();
void MatrixMult(float *mat);
const float *MatrixGet(int type);
void Set_matrixDirty();
void Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain);
ID3D11DeviceContext *InitialiseContext(bool fromPresent);
void StartFrame();
void DoScreenGrabOnNextPresent();
void Present();
void Clear(int flags, D3D11_RECT *pRect);
void SetClearColour(const float colourRGBA[4]);
bool IsWidescreen();
bool IsHiDef();
void CaptureThumbnail(ImageFileBuffer *pngOut);
void CaptureScreen(ImageFileBuffer *jpgOut, XSOCIAL_PREVIEWIMAGE *previewOut);
void BeginConditionalSurvey(int identifier);
void EndConditionalSurvey();
void BeginConditionalRendering(int identifier);
void EndConditionalRendering();
void DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count, void *dataIn, C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType);
void DrawVertexBuffer(C4JRender::ePrimitiveType PrimitiveType, int count, ID3D11Buffer *buffer, C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType);
void CBuffLockStaticCreations();
int CBuffCreate(int count);
void CBuffDelete(int first, int count);
void CBuffStart(int index, bool full);
void CBuffClear(int index);
int CBuffSize(int index);
void CBuffEnd();
bool CBuffCall(int index, bool full);
void CBuffTick();
void CBuffDeferredModeStart();
void CBuffDeferredModeEnd();
int TextureCreate();
void TextureFree(int idx);
void TextureBind(int idx);
void TextureBindVertex(int idx);
void TextureSetTextureLevels(int levels);
int TextureGetTextureLevels();
void TextureSetParam(int param, int value);
void TextureDynamicUpdateStart();
void TextureDynamicUpdateEnd();
void TextureData(int width, int height, void *data, int level, C4JRender::eTextureFormat format);
void TextureDataUpdate(int xoffset, int yoffset, int width, int height, void *data, int level);
HRESULT LoadTextureData(const char *szFilename, D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut);
HRESULT LoadTextureData(BYTE *pbData, DWORD dwBytes, D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut);
HRESULT SaveTextureData(const char *szFilename, D3DXIMAGE_INFO *pSrcInfo, int *ppDataOut);
HRESULT SaveTextureDataToMemory(void *pOutput, int outputCapacity, int *outputLength, int width, int height, int *ppDataIn);
void TextureGetStats();
ID3D11ShaderResourceView *TextureGetTexture(int idx);
void StateSetColour(float r, float g, float b, float a);
void StateSetDepthMask(bool enable);
void StateSetBlendEnable(bool enable);
void StateSetBlendFunc(int src, int dst);
void StateSetBlendFactor(unsigned int colour);
void StateSetAlphaFunc(int func, float param);
void StateSetDepthFunc(int func);
void StateSetFaceCull(bool enable);
void StateSetFaceCullCW(bool enable);
void StateSetLineWidth(float width);
void StateSetWriteEnable(bool red, bool green, bool blue, bool alpha);
void StateSetDepthTestEnable(bool enable);
void StateSetAlphaTestEnable(bool enable);
void StateSetDepthSlopeAndBias(float slope, float bias);
void StateSetFogEnable(bool enable);
void StateSetFogMode(int mode);
void StateSetFogNearDistance(float dist);
void StateSetFogFarDistance(float dist);
void StateSetFogDensity(float density);
void StateSetFogColour(float red, float green, float blue);
void StateSetLightingEnable(bool enable);
void StateSetVertexTextureUV(float u, float v);
void StateSetLightColour(int light, float red, float green, float blue);
void StateSetLightAmbientColour(float red, float green, float blue);
void StateSetLightDirection(int light, float x, float y, float z);
void StateSetLightEnable(int light, bool enable);
void StateSetViewport(C4JRender::eViewportType viewportType);
void StateSetEnableViewportClipPlanes(bool enable);
void StateSetTexGenCol(int col, float x, float y, float z, float w, bool eyeSpace);
void StateSetStencil(D3D11_COMPARISON_FUNC function, uint8_t stencil_ref, uint8_t stencil_func_mask, uint8_t stencil_write_mask);
void StateSetForceLOD(int LOD);
void BeginEvent(LPCWSTR eventName);
void EndEvent();
void Suspend();
bool Suspended();
void Resume();
void StateUpdate();
private:
void SetupShaders();
void ConvertLinearToPng(ImageFileBuffer* pngOut, unsigned char* linearData, unsigned int width, unsigned int height);
void DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType, C4JRender::ePrimitiveType primitiveType, int* count, bool* drawIndexed);
void UpdateTexGenState();
void UpdateLightingState();
void UpdateViewportState();
void UpdateFogState();
void UpdateTextureState(bool vertexSampler);
void MultWithStack(DirectX::XMMATRIX matrix);
ID3D11DepthStencilState* GetManagedDepthStencilState();
ID3D11BlendState* GetManagedBlendState();
ID3D11RasterizerState* GetManagedRasterizerState();
ID3D11SamplerState* GetManagedSamplerState();
void DeleteInternalBuffer(int index);
Renderer::Context& getContext();
static D3D11_PRIMITIVE_TOPOLOGY* m_Topologies;
static DXGI_FORMAT textureFormats[C4JRender::MAX_TEXTURE_FORMATS];
void SetupShaders();
void ConvertLinearToPng(ImageFileBuffer *pngOut, unsigned char *linearData, unsigned int width, unsigned int height);
void DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType, C4JRender::ePrimitiveType primitiveType, int *count,
bool *drawIndexed);
void UpdateTexGenState();
void UpdateLightingState();
void UpdateViewportState();
void UpdateFogState();
void UpdateTextureState(bool vertexSampler);
void MultWithStack(DirectX::XMMATRIX matrix);
ID3D11DepthStencilState *GetManagedDepthStencilState();
ID3D11BlendState *GetManagedBlendState();
ID3D11RasterizerState *GetManagedRasterizerState();
ID3D11SamplerState *GetManagedSamplerState();
void DeleteInternalBuffer(int index);
Renderer::Context &getContext();
static D3D11_PRIMITIVE_TOPOLOGY *m_Topologies;
static DXGI_FORMAT textureFormats[C4JRender::MAX_TEXTURE_FORMATS];
public:
struct Texture
{
bool allocated;
ID3D11Texture2D *texture;
ID3D11ShaderResourceView *view;
DWORD textureFlags;
DWORD mipLevels;
DWORD textureFormat;
DWORD samplerParams;
};
struct Texture
{
bool allocated;
ID3D11Texture2D* texture;
ID3D11ShaderResourceView* view;
DWORD textureFlags;
DWORD mipLevels;
DWORD textureFormat;
DWORD samplerParams;
};
struct TexgenCBuffer
{
DirectX::XMMATRIX unk0;
DirectX::XMMATRIX unk1;
};
struct TexgenCBuffer
{
DirectX::XMMATRIX unk0;
DirectX::XMMATRIX unk1;
};
enum eCommandType
{
COMMAND_ADD_MATRIX,
COMMAND_ADD_VERTICES,
COMMAND_BIND_TEXTURE,
COMMAND_SET_COLOR,
COMMAND_SET_DEPTH_FUNC,
COMMAND_SET_DEPTH_MASK,
COMMAND_SET_DEPTH_TEST,
COMMAND_SET_LIGHTING_ENABLE,
COMMAND_SET_LIGHT_ENABLE,
COMMAND_SET_LIGHT_DIRECTION,
COMMAND_SET_LIGHT_COLOUR,
COMMAND_SET_LIGHT_AMBIENT_COLOUR,
COMMAND_SET_BLEND_ENABLE,
COMMAND_SET_BLEND_FUNC,
COMMAND_SET_BLEND_FACTOR,
COMMAND_SET_FACE_CULL,
};
enum eCommandType
{
COMMAND_ADD_MATRIX,
COMMAND_ADD_VERTICES,
COMMAND_BIND_TEXTURE,
COMMAND_SET_COLOR,
COMMAND_SET_DEPTH_FUNC,
COMMAND_SET_DEPTH_MASK,
COMMAND_SET_DEPTH_TEST,
COMMAND_SET_LIGHTING_ENABLE,
COMMAND_SET_LIGHT_ENABLE,
COMMAND_SET_LIGHT_DIRECTION,
COMMAND_SET_LIGHT_COLOUR,
COMMAND_SET_LIGHT_AMBIENT_COLOUR,
COMMAND_SET_BLEND_ENABLE,
COMMAND_SET_BLEND_FUNC,
COMMAND_SET_BLEND_FACTOR,
COMMAND_SET_FACE_CULL,
};
struct CommandBuffer
{
CommandBuffer(bool full);
~CommandBuffer();
void StartRecording();
void EndRecording(ID3D11Device *device);
std::uint64_t GetAllocated();
bool IsBusy();
void AddMatrix(const float *matrix);
void AddVertices(unsigned int stride, unsigned int count, void *dataIn, Renderer::Context &c);
void BindTexture(int idx);
void SetColor(float r, float g, float b, float a);
void SetDepthFunc(int func);
void SetDepthMask(bool enable);
void SetDepthTestEnable(bool enable);
void SetLightingEnable(bool enable);
void SetLightEnable(int light, bool enable);
void SetLightDirection(int light, float x, float y, float z);
void SetLightColour(int light, float r, float g, float b);
void SetLightAmbientColour(float r, float g, float b);
void SetBlendEnable(bool enable);
void SetBlendFunc(int src, int dst);
void SetBlendFactor(unsigned int factor);
void SetFaceCull(bool enable);
void Render(C4JRender::eVertexType vType, Renderer::Context &c, int primitiveType);
struct CommandBuffer
{
CommandBuffer(bool full);
~CommandBuffer();
void StartRecording();
void EndRecording(ID3D11Device* device);
std::uint64_t GetAllocated();
bool IsBusy();
void AddMatrix(const float* matrix);
void AddVertices(unsigned int stride, unsigned int count, void* dataIn, Renderer::Context& context);
void BindTexture(int idx);
void SetColor(float r, float g, float b, float a);
void SetDepthFunc(int func);
void SetDepthMask(bool enable);
void SetDepthTestEnable(bool enable);
void SetLightingEnable(bool enable);
void SetLightEnable(int light, bool enable);
void SetLightDirection(int light, float x, float y, float z);
void SetLightColour(int light, float r, float g, float b);
void SetLightAmbientColour(float r, float g, float b);
void SetBlendEnable(bool enable);
void SetBlendFunc(int src, int dst);
void SetBlendFactor(unsigned int factor);
void SetFaceCull(bool enable);
void Render(C4JRender::eVertexType vertexType, Renderer::Context& context, int primitiveType);
struct Command
{
Renderer::eCommandType m_command_type;
BYTE commandPadding[12];
struct Command
{
Renderer::eCommandType m_command_type;
BYTE commandPadding[12];
union
{
BYTE data[64];
union
{
BYTE data[64];
struct
{
float m_matrix[16];
// DirectX::XMMATRIX m_matrix;
} add_matrix;
struct
{
float m_matrix[16];
//DirectX::XMMATRIX m_matrix;
} add_matrix;
struct
{
unsigned int m_vertex_index_start;
unsigned int m_vertex_count;
} add_vertices;
struct
{
unsigned int m_vertex_index_start;
unsigned int m_vertex_count;
} add_vertices;
struct
{
unsigned int m_texture_index;
} bind_texture;
struct
{
unsigned int m_texture_index;
} bind_texture;
struct
{
float m_color[4];
} set_color;
struct
{
float m_color[4];
} set_color;
struct
{
int m_depth_func;
} set_depth_func;
struct
{
int m_depth_func;
} set_depth_func;
struct
{
bool m_enable;
} set_depth_mask;
struct
{
bool m_enable;
} set_depth_mask;
struct
{
bool m_enable;
} set_depth_test;
struct
{
bool m_enable;
} set_depth_test;
struct
{
bool m_enable;
} set_lighting_enable;
struct
{
bool m_enable;
} set_lighting_enable;
struct
{
int m_light_index;
bool m_enable;
} set_light_enable;
struct
{
int m_light_index;
bool m_enable;
} set_light_enable;
struct
{
int m_light_index;
float padding[3];
float m_direction[4];
} set_light_direction;
struct
{
int m_light_index;
float padding[3];
float m_direction[4];
} set_light_direction;
struct
{
int m_light_index;
float m_color[3];
} set_light_colour;
struct
{
int m_light_index;
float m_color[3];
} set_light_colour;
struct
{
BYTE padding;
float m_color[3];
} set_light_ambient_colour;
struct
{
BYTE padding;
float m_color[3];
} set_light_ambient_colour;
struct
{
bool m_enable;
} set_blend_enable;
struct
{
bool m_enable;
} set_blend_enable;
struct
{
int m_src;
int m_dst;
} set_blend_func;
struct
{
int m_src;
int m_dst;
} set_blend_func;
struct
{
unsigned int m_blend_factor;
} set_blend_factor;
struct
{
unsigned int m_blend_factor;
} set_blend_factor;
struct
{
bool m_enable;
} set_face_cull;
};
};
ID3D11Buffer *m_vertexBuffer;
void *m_vertexData;
std::uint64_t m_vertexDataLength;
std::vector<Command> m_commands;
std::uint64_t m_allocated;
BYTE isActive;
};
struct
{
bool m_enable;
} set_face_cull;
};
};
ID3D11Buffer* m_vertexBuffer;
void* m_vertexData;
std::uint64_t m_vertexDataLength;
std::vector<Command> m_commands;
std::uint64_t m_allocated;
BYTE isActive;
BYTE paddingAfterActive[7];
struct DeferredCBuff
{
Renderer::CommandBuffer *m_command_buf;
int m_vertex_index;
int m_vertex_type;
int m_primitive_type;
DirectX::XMMATRIX m_matrix;
};
struct Context
{
static const unsigned int VERTEX_BUFFER_SIZE = 0x100000;
};
Context(ID3D11Device *device, ID3D11DeviceContext *deviceContext);
struct DeferredCBuff
{
Renderer::CommandBuffer* m_command_buf;
int m_vertex_index;
int m_vertex_type;
int m_primitive_type;
DirectX::XMMATRIX m_matrix;
};
ID3D11DeviceContext *m_pDeviceContext;
ID3DUserDefinedAnnotation *userAnnotation;
DWORD annotateDepth;
DirectX::XMMATRIX matrixStacks[MATRIX_MODE_MODELVIEW_MAX][STACK_SIZE];
bool matrixDirty[MATRIX_MODE_MODELVIEW_MAX];
DWORD stackPos[MATRIX_MODE_MODELVIEW_MAX];
DWORD stackType;
DWORD textureIdx;
BYTE faceCullEnabled;
BYTE depthTestEnabled;
BYTE alphaTestEnabled;
float alphaReference;
BYTE depthWriteEnabled;
BYTE fogEnabled;
float fogNearDistance;
float fogFarDistance;
float fogDensity;
float fogColourRed;
float fogColourBlue;
float fogColourGreen;
DWORD fogMode;
BYTE lightingEnabled;
BYTE lightEnabled[2];
BYTE lightingDirty;
DWORD forcedLOD;
BYTE paddingAfterForceLOD[4];
DirectX::XMFLOAT4 lightDirection[2];
DirectX::XMFLOAT4 lightColour[2];
DirectX::XMFLOAT4 lightAmbientColour;
ID3D11Buffer *m_modelViewMatrix;
ID3D11Buffer *m_localTransformMatrix;
ID3D11Buffer *m_projectionMatrix;
ID3D11Buffer *m_textureMatrix;
ID3D11Buffer *m_vertexTexcoordBuffer;
ID3D11Buffer *m_fogParamsBuffer;
ID3D11Buffer *m_lightingStateBuffer;
ID3D11Buffer *m_texGenMatricesBuffer;
ID3D11Buffer *m_compressedTranslationBuffer;
ID3D11Buffer *m_thumbnailBoundsBuffer;
ID3D11Buffer *m_tintColorBuffer;
ID3D11Buffer *m_fogColourBuffer;
ID3D11Buffer *m_unkColorBuffer;
ID3D11Buffer *m_alphaTestBuffer;
ID3D11Buffer *m_clearColorBuffer;
ID3D11Buffer *m_forcedLODBuffer;
uint64_t dynamicVertexBase;
DWORD dynamicVertexOffset;
ID3D11Buffer *dynamicVertexBuffer;
DirectX::XMMATRIX texGenMatrices[2];
Renderer::CommandBuffer *commandBuffer;
DWORD recordingBufferIndex;
DWORD recordingVertexType;
DWORD recordingPrimitiveType;
BYTE deferredModeEnabled;
std::vector<DeferredCBuff> deferredBuffers;
D3D11_BLEND_DESC blendDesc;
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
D3D11_RASTERIZER_DESC rasterizerDesc;
float blendFactor[4];
};
struct Context
{
Context(ID3D11Device* device, ID3D11DeviceContext* deviceContext);
static DWORD tlsIdx;
static unsigned int s_auiWidths[MAX_MIP_LEVELS + 1];
static unsigned int s_auiHeights[MAX_MIP_LEVELS + 1];
static D3D11_INPUT_ELEMENT_DESC g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1[5];
static D3D11_INPUT_ELEMENT_DESC g_vertex_PTN_Elements_Compressed[2];
static D3D11_PRIMITIVE_TOPOLOGY g_topologies[C4JRender::PRIMITIVE_TYPE_COUNT];
static int totalAlloc;
static _RTL_CRITICAL_SECTION totalAllocCS;
ID3D11DeviceContext* m_pDeviceContext;
ID3DUserDefinedAnnotation* userAnnotation;
DWORD contextStateFlags;
BYTE paddingAfterFlags[12];
DirectX::XMMATRIX matrixStacks[4][16];
bool matrixDirty[4];
DWORD matrixStackDepth[4];
DWORD matrixModeType;
DWORD boundTextureIndex;
BYTE faceCullEnabled;
BYTE depthTestEnabled;
BYTE alphaTestEnabled;
float alphaReference;
BYTE depthWriteEnabled;
BYTE fogEnabled;
BYTE paddingAfterFogFlags[2];
float fogNearDistance;
float fogFarDistance;
float fogDensity;
float fogColourRed;
float fogColourBlue;
float fogColourGreen;
DWORD fogMode;
BYTE lightingEnabled;
BYTE lightEnabled[2];
BYTE lightingDirty;
DWORD forcedLOD;
BYTE paddingAfterForceLOD[4];
DirectX::XMFLOAT4 lightDirection[2];
DirectX::XMFLOAT4 lightColour[2];
DirectX::XMFLOAT4 lightAmbientColour;
ID3D11Buffer* cbMatrix0;
ID3D11Buffer* cbMatrix1;
ID3D11Buffer* cbMatrix2;
ID3D11Buffer* cbMatrix3;
ID3D11Buffer* cbVertexTexcoord;
ID3D11Buffer* cbFogParams;
ID3D11Buffer* cbLighting;
ID3D11Buffer* cbTexGen;
ID3D11Buffer* cbAux0;
ID3D11Buffer* cbAux1;
ID3D11Buffer* cbColour;
ID3D11Buffer* cbFogColour;
ID3D11Buffer* cbAux2;
ID3D11Buffer* cbAlphaTest;
ID3D11Buffer* cbAux3;
ID3D11Buffer* cbAux4;
uint64_t dynamicVertexBase;
DWORD dynamicVertexOffset;
BYTE paddingAfterDynamicOffset[4];
ID3D11Buffer* dynamicVertexBuffer;
BYTE paddingBeforeTexGen[8];
DirectX::XMMATRIX texGenMatrices[2];
Renderer::CommandBuffer* commandBuffer;
DWORD recordingBufferIndex;
DWORD recordingVertexType;
DWORD recordingPrimitiveType;
BYTE deferredModeEnabled;
BYTE paddingAfterDeferredModeEnabled[3];
std::vector<DeferredCBuff> deferredBuffers;
D3D11_BLEND_DESC blendDesc;
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
D3D11_RASTERIZER_DESC rasterizerDesc;
float blendFactor[4];
DWORD reservedContext0;
DWORD reservedContext1;
};
static DWORD tlsIdx;
static unsigned int s_auiWidths[MAX_MIP_LEVELS + 1];
static unsigned int s_auiHeights[MAX_MIP_LEVELS + 1];
static D3D11_INPUT_ELEMENT_DESC g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1[5];
static D3D11_INPUT_ELEMENT_DESC g_vertex_PTN_Elements_Compressed[2];
static D3D11_PRIMITIVE_TOPOLOGY g_topologies[C4JRender::PRIMITIVE_TYPE_COUNT];
static int totalAlloc;
static _RTL_CRITICAL_SECTION totalAllocCS;
float m_fClearColor[4];
ID3D11Device* m_pDevice;
ID3D11DeviceContext* m_pDeviceContext;
IDXGISwapChain* m_pSwapChain;
ID3D11RenderTargetView* renderTargetView;
ID3D11RenderTargetView* renderTargetViews[4];
ID3D11ShaderResourceView* renderTargetShaderResourceView;
ID3D11ShaderResourceView* renderTargetShaderResourceViews[4];
ID3D11Texture2D* renderTargetTextures[4];
ID3D11DepthStencilView* depthStencilView;
ID3D11VertexShader** vertexShaderTable;
ID3D11VertexShader* screenSpaceVertexShader;
ID3D11VertexShader* screenClearVertexShader;
ID3D11PixelShader** pixelShaderTable;
ID3D11PixelShader* screenSpacePixelShader;
ID3D11PixelShader* screenClearPixelShader;
unsigned int* vertexStrideTable;
ID3D11InputLayout** inputLayoutTable;
ID3D11Buffer* quadIndexBuffer;
ID3D11Buffer* fanIndexBuffer;
DWORD defaultTextureIndex;
WORD reservedRendererWord0;
BYTE paddingAfterRendererWord0[2];
DWORD presentCount;
BYTE rendererFlag0;
BYTE paddingAfterRendererFlag0[3];
_RTL_CRITICAL_SECTION rtl_critical_section100;
DWORD activeVertexType;
DWORD activePixelType;
C4JRender::eViewportType m_ViewportType;
BYTE reservedRendererByte0;
BYTE paddingAfterViewportType[3];
Renderer::Texture m_textures[MAX_TEXTURES];
DWORD backBufferWidth;
DWORD backBufferHeight;
BYTE reservedRendererByte1;
BYTE paddingAfterRendererByte1[3];
DWORD reservedRendererDword1;
void* reservedRendererPtr2;
void* reservedRendererPtr3;
uint64_t reservedRendererPtr1;
void* reservedRendererPtr4;
void* reservedRendererPtr5;
void* reservedRendererPtr6;
DWORD reservedRendererDword2;
DWORD reservedRendererDword3;
std::unordered_map<int, ID3D11BlendState*> managedBlendStates;
std::unordered_map<int, ID3D11DepthStencilState*> managedDepthStencilStates;
std::unordered_map<int, ID3D11SamplerState*> managedSamplerStates;
std::unordered_map<int, ID3D11RasterizerState*> managedRasterizerStates;
bool m_bShouldScreenGrabNextFrame;
BYTE m_bSuspended;
BYTE paddingAfterSuspendState[2];
float m_fClearColor[4];
ID3D11Device *m_pDevice;
ID3D11DeviceContext *m_pDeviceContext;
IDXGISwapChain *m_pSwapChain;
ID3D11RenderTargetView *renderTargetView;
ID3D11RenderTargetView *renderTargetViews[4];
ID3D11ShaderResourceView *renderTargetShaderResourceView;
ID3D11ShaderResourceView *renderTargetShaderResourceViews[4];
ID3D11Texture2D *renderTargetTextures[4];
ID3D11DepthStencilView *depthStencilView;
ID3D11VertexShader **vertexShaderTable;
ID3D11VertexShader *screenSpaceVertexShader;
ID3D11VertexShader *screenClearVertexShader;
ID3D11PixelShader **pixelShaderTable;
ID3D11PixelShader *screenSpacePixelShader;
ID3D11PixelShader *screenClearPixelShader;
unsigned int *vertexStrideTable;
ID3D11InputLayout **inputLayoutTable;
ID3D11Buffer *quadIndexBuffer;
ID3D11Buffer *fanIndexBuffer;
DWORD defaultTextureIndex;
WORD reservedRendererWord0;
BYTE paddingAfterRendererWord0[2];
DWORD presentCount;
BYTE rendererFlag0;
BYTE paddingAfterRendererFlag0[3];
_RTL_CRITICAL_SECTION rtl_critical_section100;
DWORD activeVertexType;
DWORD activePixelType;
C4JRender::eViewportType m_ViewportType;
BYTE reservedRendererByte0;
BYTE paddingAfterViewportType[3];
Renderer::Texture m_textures[512];
DWORD backBufferWidth;
DWORD backBufferHeight;
BYTE reservedRendererByte1;
BYTE paddingAfterRendererByte1[3];
DWORD reservedRendererDword1;
int16_t *m_commandHandleToIndex;
CommandBuffer **m_commandBuffers;
uint8_t *m_commandPrimitiveTypes;
DirectX::XMMATRIX *m_commandMatrices;
int *m_commandIndexToHandle;
uint8_t *m_commandVertexTypes;
DWORD reservedRendererDword2;
DWORD reservedRendererDword3;
std::unordered_map<int, ID3D11BlendState *> managedBlendStates;
std::unordered_map<int, ID3D11DepthStencilState *> managedDepthStencilStates;
std::unordered_map<int, ID3D11SamplerState *> managedSamplerStates;
std::unordered_map<int, ID3D11RasterizerState *> managedRasterizerStates;
BYTE shouldScreenGrabNextFrame;
BYTE suspended;
BYTE paddingAfterSuspendState[2];
};
// Singleton
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+62 -54
View File
@@ -3,109 +3,117 @@
#include <cstring>
const float* Renderer::MatrixGet(int type)
const float *Renderer::MatrixGet(int type)
{
Context& context = this->getContext();
const int depth = context.matrixStackDepth[type];
return reinterpret_cast<const float*>(&context.matrixStacks[type][depth]);
Context &c = this->getContext();
const int depth = c.stackPos[type];
return reinterpret_cast<const float *>(&c.matrixStacks[type][depth]);
}
void Renderer::MatrixMode(int type)
{
Context& context = this->getContext();
context.matrixModeType = type;
Context &c = this->getContext();
assert(type >= 0);
assert(type < STACK_TYPES);
c.stackType = type;
}
void Renderer::MatrixMult(float* mat)
void Renderer::MatrixMult(float *mat)
{
DirectX::XMMATRIX matrix;
std::memcpy(&matrix, mat, sizeof(matrix));
this->MultWithStack(matrix);
DirectX::XMMATRIX matrix;
std::memcpy(&matrix, mat, sizeof(matrix));
this->MultWithStack(matrix);
}
void Renderer::MatrixOrthogonal(float left, float right, float bottom, float top, float zNear, float zFar)
{
const DirectX::XMMATRIX matrix = DirectX::XMMatrixOrthographicOffCenterRH(left, right, bottom, top, zNear, zFar);
this->MultWithStack(matrix);
const DirectX::XMMATRIX matrix = DirectX::XMMatrixOrthographicOffCenterRH(left, right, bottom, top, zNear, zFar);
this->MultWithStack(matrix);
}
void Renderer::MatrixPerspective(float fovy, float aspect, float zNear, float zFar)
{
const float fovRadians = fovy * (3.14159274f / 180.0f);
const DirectX::XMMATRIX matrix = DirectX::XMMatrixPerspectiveFovRH(fovRadians, aspect, zNear, zFar);
this->MultWithStack(matrix);
const float fovRadians = fovy * (3.14159274f / 180.0f);
const DirectX::XMMATRIX matrix = DirectX::XMMatrixPerspectiveFovRH(fovRadians, aspect, zNear, zFar);
this->MultWithStack(matrix);
}
void Renderer::MatrixPop()
{
Context& context = this->getContext();
const int mode = context.matrixModeType;
--context.matrixStackDepth[mode];
context.matrixDirty[mode] = true;
Context &c = this->getContext();
assert(c.stackPos[c.stackType] > 0);
const int mode = c.stackType;
--c.stackPos[mode];
c.matrixDirty[mode] = true;
}
void Renderer::MatrixPush()
{
Context& context = this->getContext();
const int mode = context.matrixModeType;
const int depth = context.matrixStackDepth[mode];
context.matrixStacks[mode][depth + 1] = context.matrixStacks[mode][depth];
++context.matrixStackDepth[mode];
Context &c = this->getContext();
assert(c.stackPos[c.stackType] < (STACK_SIZE - 1));
const int mode = c.stackType;
const int depth = c.stackPos[mode];
c.matrixStacks[mode][depth + 1] = c.matrixStacks[mode][depth];
++c.stackPos[mode];
}
void Renderer::MatrixRotate(float angle, float x, float y, float z)
{
const DirectX::XMVECTOR axis = DirectX::XMVectorSet(x, y, z, 0.0f);
const DirectX::XMMATRIX matrix = DirectX::XMMatrixRotationAxis(axis, angle);
this->MultWithStack(matrix);
const DirectX::XMVECTOR axis = DirectX::XMVectorSet(x, y, z, 0.0f);
const DirectX::XMMATRIX matrix = DirectX::XMMatrixRotationAxis(axis, angle);
this->MultWithStack(matrix);
}
void Renderer::MatrixScale(float x, float y, float z)
{
const DirectX::XMMATRIX matrix = DirectX::XMMatrixScaling(x, y, z);
this->MultWithStack(matrix);
const DirectX::XMMATRIX matrix = DirectX::XMMatrixScaling(x, y, z);
this->MultWithStack(matrix);
}
void Renderer::MatrixSetIdentity()
{
Context& context = this->getContext();
const int mode = context.matrixModeType;
const int depth = context.matrixStackDepth[mode];
context.matrixStacks[mode][depth] = DirectX::XMMatrixIdentity();
context.matrixDirty[mode] = true;
Context &c = this->getContext();
const int mode = c.stackType;
const int depth = c.stackPos[mode];
c.matrixStacks[mode][depth] = DirectX::XMMatrixIdentity();
c.matrixDirty[mode] = true;
}
void Renderer::MatrixTranslate(float x, float y, float z)
{
const DirectX::XMMATRIX matrix = DirectX::XMMatrixTranslation(x, y, z);
this->MultWithStack(matrix);
const DirectX::XMMATRIX matrix = DirectX::XMMatrixTranslation(x, y, z);
this->MultWithStack(matrix);
}
void Renderer::MultWithStack(DirectX::XMMATRIX matrix)
{
Context& context = this->getContext();
const int mode = context.matrixModeType;
const int depth = context.matrixStackDepth[mode];
DirectX::XMMATRIX& current = context.matrixStacks[mode][depth];
current = DirectX::XMMatrixMultiply(matrix, current);
context.matrixDirty[mode] = true;
Context &c = this->getContext();
const int mode = c.stackType;
const int depth = c.stackPos[mode];
DirectX::XMMATRIX &current = c.matrixStacks[mode][depth];
current = DirectX::XMMatrixMultiply(matrix, current);
c.matrixDirty[mode] = true;
}
void Renderer::Set_matrixDirty()
{
Context& context = this->getContext();
const DirectX::XMMATRIX identity = DirectX::XMMatrixIdentity();
Context &c = this->getContext();
const DirectX::XMMATRIX identity = DirectX::XMMatrixIdentity();
context.matrixStacks[0][0] = identity;
context.matrixStacks[1][0] = identity;
context.matrixStacks[2][0] = identity;
context.matrixStacks[3][0] = identity;
c.matrixStacks[MATRIX_MODE_MODELVIEW][0] = identity;
c.matrixStacks[MATRIX_MODE_MODELVIEW_PROJECTION][0] = identity;
c.matrixStacks[MATRIX_MODE_MODELVIEW_TEXTURE][0] = identity;
c.matrixStacks[MATRIX_MODE_MODELVIEW_CBUFF][0] = identity;
context.matrixDirty[0] = true;
context.matrixDirty[1] = true;
context.matrixDirty[2] = true;
context.matrixDirty[3] = true;
c.matrixDirty[MATRIX_MODE_MODELVIEW] = true;
c.matrixDirty[MATRIX_MODE_MODELVIEW_PROJECTION] = true;
c.matrixDirty[MATRIX_MODE_MODELVIEW_TEXTURE] = true;
c.matrixDirty[MATRIX_MODE_MODELVIEW_CBUFF] = true;
activeVertexType = 0xFFFFFFFFu;
activePixelType = 0xFFFFFFFFu;
activeVertexType = 0xFFFFFFFFu;
activePixelType = 0xFFFFFFFFu;
}
File diff suppressed because it is too large Load Diff
+135 -144
View File
@@ -5,181 +5,172 @@
#include <cstdio>
#include <cstring>
D3D11_PRIMITIVE_TOPOLOGY* Renderer::m_Topologies = nullptr;
D3D11_PRIMITIVE_TOPOLOGY *Renderer::m_Topologies = nullptr;
void Renderer::DrawVertexBuffer(
C4JRender::ePrimitiveType PrimitiveType,
int count,
ID3D11Buffer* buffer,
C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType)
void Renderer::DrawVertexBuffer(C4JRender::ePrimitiveType PrimitiveType, int count, ID3D11Buffer *buffer, C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType)
{
Renderer::Context& context = this->getContext();
ID3D11DeviceContext* d3d11 = context.m_pDeviceContext;
Renderer::Context &c = this->getContext();
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
int drawCount = count;
bool indexed = false;
this->DrawVertexSetup(vType, psType, PrimitiveType, &drawCount, &indexed);
this->StateUpdate();
int drawCount = count;
bool indexed = false;
this->DrawVertexSetup(vType, psType, PrimitiveType, &drawCount, &indexed);
this->StateUpdate();
const UINT stride = vertexStrideTable[vType];
const UINT offset = 0;
d3d11->IASetVertexBuffers(0, 1, &buffer, &stride, &offset);
const UINT stride = vertexStrideTable[vType];
const UINT offset = 0;
d3d11->IASetVertexBuffers(0, 1, &buffer, &stride, &offset);
if (indexed)
{
d3d11->DrawIndexed(drawCount, 0, 0);
}
else
{
d3d11->Draw(count, 0);
}
if (indexed)
{
d3d11->DrawIndexed(drawCount, 0, 0);
}
else
{
d3d11->Draw(count, 0);
}
}
void Renderer::DrawVertexSetup(
C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType,
C4JRender::ePrimitiveType PrimitiveType,
int* count,
bool* indexed)
void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType, C4JRender::ePrimitiveType PrimitiveType, int *count,
bool *indexed)
{
Renderer::Context& context = this->getContext();
ID3D11DeviceContext* d3d11 = context.m_pDeviceContext;
Renderer::Context &c = this->getContext();
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
C4JRender::eVertexType effectiveVertexType = vType;
if (effectiveVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && context.lightingEnabled)
{
effectiveVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
}
C4JRender::eVertexType effectiveVertexType = vType;
if (effectiveVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && c.lightingEnabled)
{
effectiveVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
}
if (effectiveVertexType != activeVertexType)
{
d3d11->VSSetShader(vertexShaderTable[effectiveVertexType], nullptr, 0);
d3d11->IASetInputLayout(inputLayoutTable[effectiveVertexType]);
activeVertexType = effectiveVertexType;
}
if (effectiveVertexType != activeVertexType)
{
d3d11->VSSetShader(vertexShaderTable[effectiveVertexType], nullptr, 0);
d3d11->IASetInputLayout(inputLayoutTable[effectiveVertexType]);
activeVertexType = effectiveVertexType;
}
if (psType != activePixelType)
{
d3d11->PSSetShader(pixelShaderTable[psType], nullptr, 0);
activePixelType = psType;
}
if (psType != activePixelType)
{
d3d11->PSSetShader(pixelShaderTable[psType], nullptr, 0);
activePixelType = psType;
}
D3D11_MAPPED_SUBRESOURCE mapped = {};
D3D11_MAPPED_SUBRESOURCE mapped = {};
if (context.matrixDirty[0])
{
d3d11->Map(context.cbMatrix0, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
std::memcpy(mapped.pData, this->MatrixGet(0), sizeof(DirectX::XMMATRIX));
d3d11->Unmap(context.cbMatrix0, 0);
context.matrixDirty[0] = false;
}
if (c.matrixDirty[MATRIX_MODE_MODELVIEW])
{
d3d11->Map(c.m_modelViewMatrix, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
std::memcpy(mapped.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW), sizeof(DirectX::XMMATRIX));
d3d11->Unmap(c.m_modelViewMatrix, 0);
c.matrixDirty[MATRIX_MODE_MODELVIEW] = false;
}
if (context.matrixDirty[1])
{
d3d11->Map(context.cbMatrix2, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
std::memcpy(mapped.pData, this->MatrixGet(1), sizeof(DirectX::XMMATRIX));
d3d11->Unmap(context.cbMatrix2, 0);
context.matrixDirty[1] = false;
}
if (c.matrixDirty[MATRIX_MODE_MODELVIEW_PROJECTION])
{
d3d11->Map(c.m_projectionMatrix, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
std::memcpy(mapped.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW_PROJECTION), sizeof(DirectX::XMMATRIX));
d3d11->Unmap(c.m_projectionMatrix, 0);
c.matrixDirty[MATRIX_MODE_MODELVIEW_PROJECTION] = false;
}
if (context.matrixDirty[2])
{
d3d11->Map(context.cbMatrix3, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
std::memcpy(mapped.pData, this->MatrixGet(2), sizeof(DirectX::XMMATRIX));
d3d11->Unmap(context.cbMatrix3, 0);
context.matrixDirty[2] = false;
}
if (c.matrixDirty[MATRIX_MODE_MODELVIEW_TEXTURE])
{
d3d11->Map(c.m_textureMatrix, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
std::memcpy(mapped.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW_TEXTURE), sizeof(DirectX::XMMATRIX));
d3d11->Unmap(c.m_textureMatrix, 0);
c.matrixDirty[MATRIX_MODE_MODELVIEW_TEXTURE] = false;
}
this->UpdateFogState();
this->UpdateViewportState();
this->UpdateLightingState();
this->UpdateTexGenState();
this->UpdateFogState();
this->UpdateViewportState();
this->UpdateLightingState();
this->UpdateTexGenState();
d3d11->IASetPrimitiveTopology(m_Topologies[PrimitiveType]);
d3d11->IASetPrimitiveTopology(m_Topologies[PrimitiveType]);
if (PrimitiveType == C4JRender::PRIMITIVE_TYPE_QUAD_LIST)
{
d3d11->IASetIndexBuffer(quadIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
*count = (*count * 6) / 4;
*indexed = true;
return;
}
if (PrimitiveType == C4JRender::PRIMITIVE_TYPE_QUAD_LIST)
{
d3d11->IASetIndexBuffer(quadIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
*count = (*count * 6) / 4;
*indexed = true;
return;
}
if (PrimitiveType == C4JRender::PRIMITIVE_TYPE_TRIANGLE_FAN)
{
d3d11->IASetIndexBuffer(fanIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
*count = (*count - 2) * 3;
*indexed = true;
return;
}
if (PrimitiveType == C4JRender::PRIMITIVE_TYPE_TRIANGLE_FAN)
{
d3d11->IASetIndexBuffer(fanIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
*count = (*count - 2) * 3;
*indexed = true;
return;
}
d3d11->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0);
*indexed = false;
d3d11->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0);
*indexed = false;
}
void Renderer::DrawVertices(
C4JRender::ePrimitiveType PrimitiveType,
int count,
void* vertices,
C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType)
void Renderer::DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count, void *vertices, C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType)
{
Renderer::Context& context = this->getContext();
ID3D11DeviceContext* d3d11 = context.m_pDeviceContext;
Renderer::CommandBuffer* commandBuffer = context.commandBuffer;
Renderer::Context &c = this->getContext();
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
Renderer::CommandBuffer *commandBuffer = c.commandBuffer;
if (commandBuffer != nullptr)
{
C4JRender::eVertexType effectiveVertexType = vType;
if (effectiveVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && context.lightingEnabled)
{
effectiveVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
}
if (commandBuffer != nullptr)
{
C4JRender::eVertexType effectiveVertexType = vType;
if (effectiveVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && c.lightingEnabled)
{
effectiveVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
}
context.recordingPrimitiveType = PrimitiveType;
context.recordingVertexType = effectiveVertexType;
const UINT stride = vertexStrideTable[effectiveVertexType];
commandBuffer->AddVertices(stride, static_cast<UINT>(count), vertices, context);
return;
}
c.recordingPrimitiveType = PrimitiveType;
c.recordingVertexType = effectiveVertexType;
const UINT stride = vertexStrideTable[effectiveVertexType];
commandBuffer->AddVertices(stride, static_cast<UINT>(count), vertices, c);
return;
}
int drawCount = count;
bool indexed = false;
this->DrawVertexSetup(vType, psType, PrimitiveType, &drawCount, &indexed);
int drawCount = count;
bool indexed = false;
this->DrawVertexSetup(vType, psType, PrimitiveType, &drawCount, &indexed);
const UINT stride = vertexStrideTable[vType];
const UINT copySize = stride * static_cast<UINT>(count);
if (context.dynamicVertexOffset + copySize > 0x100000u)
{
context.dynamicVertexOffset = 0;
}
const UINT stride = vertexStrideTable[vType];
const UINT vertexBytes = stride * static_cast<UINT>(count);
D3D11_MAPPED_SUBRESOURCE mapped = {};
const D3D11_MAP mapType = context.dynamicVertexOffset == 0 ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE;
const HRESULT hr = d3d11->Map(context.dynamicVertexBuffer, 0, mapType, 0, &mapped);
if (hr != 0)
{
std::printf("ERROR: 0x%x\n", static_cast<unsigned int>(hr));
}
assert(vertexBytes <= Context::VERTEX_BUFFER_SIZE);
std::memcpy(static_cast<std::uint8_t*>(mapped.pData) + context.dynamicVertexOffset, vertices, copySize);
d3d11->Unmap(context.dynamicVertexBuffer, 0);
if (c.dynamicVertexOffset + vertexBytes > Context::VERTEX_BUFFER_SIZE)
{
c.dynamicVertexOffset = 0;
}
this->StateUpdate();
D3D11_MAPPED_SUBRESOURCE mapped = {};
const D3D11_MAP mapType = c.dynamicVertexOffset == 0 ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE;
const HRESULT hr = d3d11->Map(c.dynamicVertexBuffer, 0, mapType, 0, &mapped);
if (hr != 0)
{
std::printf("ERROR: 0x%x\n", static_cast<unsigned int>(hr));
}
ID3D11Buffer* dynamicBuffer = context.dynamicVertexBuffer;
const UINT vertexOffset = context.dynamicVertexOffset;
d3d11->IASetVertexBuffers(0, 1, &dynamicBuffer, &stride, &vertexOffset);
std::memcpy(static_cast<std::uint8_t *>(mapped.pData) + c.dynamicVertexOffset, vertices, vertexBytes);
d3d11->Unmap(c.dynamicVertexBuffer, 0);
if (indexed)
{
d3d11->DrawIndexed(drawCount, 0, 0);
}
else
{
d3d11->Draw(count, 0);
}
this->StateUpdate();
context.dynamicVertexOffset += copySize;
ID3D11Buffer *dynamicBuffer = c.dynamicVertexBuffer;
const UINT vertexOffset = c.dynamicVertexOffset;
d3d11->IASetVertexBuffers(0, 1, &dynamicBuffer, &stride, &vertexOffset);
if (indexed)
{
d3d11->DrawIndexed(drawCount, 0, 0);
}
else
{
d3d11->Draw(count, 0);
}
c.dynamicVertexOffset += vertexBytes;
}
+1 -1
View File
@@ -37,7 +37,7 @@ void main(
*/
static unsigned char VS_Compressed_Data[] =
static unsigned char g_main_VS_Compressed[] =
{
0x44, 0x58, 0x42, 0x43, 0x1F, 0x76, 0x17, 0xC2, 0xF2, 0x5A,
0x47, 0x81, 0x55, 0xD3, 0x6E, 0xD1, 0x0A, 0xB0, 0xBF, 0x4A,
@@ -35,7 +35,7 @@ void main(
*/
static unsigned char VS_PF3_TF2_CB4_NB4_XW1_Data[] =
static unsigned char g_main_VS_PF3_TF2_CB4_NB4_XW1[] =
{
0x44, 0x58, 0x42, 0x43, 0x83, 0x66, 0x28, 0xAB, 0x3F, 0xFA,
0xEB, 0x49, 0x6F, 0xE0, 0x81, 0x37, 0x2A, 0x0E, 0x62, 0x6E,
@@ -43,7 +43,7 @@ void main(
*/
static unsigned char VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data[] =
static unsigned char g_main_VS_PF3_TF2_CB4_NB4_XW1_LIGHTING[] =
{
0x44, 0x58, 0x42, 0x43, 0x94, 0x85, 0x62, 0xA8, 0x82, 0x54,
0xB8, 0xE6, 0x16, 0x24, 0x6D, 0x3A, 0xB4, 0x0D, 0x4A, 0x7C,
@@ -36,7 +36,7 @@ void main(
*/
static unsigned char VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data[] =
static unsigned char g_main_VS_PF3_TF2_CB4_NB4_XW1_TEXGEN[] =
{
0x44, 0x58, 0x42, 0x43, 0xD7, 0x13, 0x1B, 0xCA, 0xDF, 0xE8,
0xA9, 0xCC, 0xDA, 0x19, 0x1B, 0x6D, 0x0C, 0x53, 0xED, 0xEE,
+1 -1
View File
@@ -13,7 +13,7 @@ void main(
}
*/
static unsigned char VS_ScreenClear_Data[] =
static unsigned char g_main_VS_ScreenClear[] =
{
0x44, 0x58, 0x42, 0x43, 0xFB, 0x82, 0xC7, 0xF7, 0x5E, 0x97,
0x42, 0x30, 0xDA, 0xAE, 0x62, 0x79, 0x54, 0x21, 0x37, 0xA2,
+1 -1
View File
@@ -21,7 +21,7 @@ void main(
*/
static unsigned char VS_ScreenSpace_Data[] =
static unsigned char g_main_VS_ScreenSpace[] =
{
0x44, 0x58, 0x42, 0x43, 0xB6, 0x90, 0x0F, 0x5D, 0x1E, 0x08,
0xBC, 0x0E, 0xCD, 0x1F, 0xED, 0xD0, 0xAE, 0x45, 0x7E, 0xDA,