default index buffer is now in DEFAULT pool

This commit is contained in:
UnknownShadow200 2018-04-20 19:19:32 +10:00
parent aaf1e66b97
commit 1bb335675f
17 changed files with 66 additions and 45 deletions

View File

@ -57,7 +57,6 @@ namespace ClassicalSharp {
Components.Add(Mode); Components.Add(Mode);
Input = new InputHandler(this); Input = new InputHandler(this);
defaultIb = Graphics.MakeDefaultIb();
ParticleManager = new ParticleManager(); Components.Add(ParticleManager); ParticleManager = new ParticleManager(); Components.Add(ParticleManager);
TabList = new TabList(); Components.Add(TabList); TabList = new TabList(); Components.Add(TabList);
LoadOptions(); LoadOptions();

View File

@ -107,7 +107,6 @@ namespace ClassicalSharp {
public PickedPos SelectedPos = new PickedPos(), CameraClipPos = new PickedPos(); public PickedPos SelectedPos = new PickedPos(), CameraClipPos = new PickedPos();
public ModelCache ModelCache; public ModelCache ModelCache;
internal string skinServer; internal string skinServer;
internal int defaultIb;
public OtherEvents Events = new OtherEvents(); public OtherEvents Events = new OtherEvents();
public EntityEvents EntityEvents = new EntityEvents(); public EntityEvents EntityEvents = new EntityEvents();
public WorldEvents WorldEvents = new WorldEvents(); public WorldEvents WorldEvents = new WorldEvents();

View File

@ -292,7 +292,7 @@ namespace ClassicalSharp {
frameTimer.Start(); frameTimer.Start();
Graphics.BeginFrame(this); Graphics.BeginFrame(this);
Graphics.BindIb(defaultIb); Graphics.BindIb(Graphics.defaultIb);
accumulator += delta; accumulator += delta;
Vertices = 0; Vertices = 0;
Mode.BeginFrame(delta); Mode.BeginFrame(delta);
@ -424,7 +424,6 @@ namespace ClassicalSharp {
for (int i = 0; i < Components.Count; i++) for (int i = 0; i < Components.Count; i++)
Components[i].Dispose(); Components[i].Dispose();
Graphics.DeleteIb(ref defaultIb);
Drawer2D.DisposeInstance(); Drawer2D.DisposeInstance();
Graphics.Dispose(); Graphics.Dispose();

View File

@ -55,7 +55,7 @@ namespace ClassicalSharp.GraphicsAPI {
CustomMipmapsLevels = true; CustomMipmapsLevels = true;
caps = device.Capabilities; caps = device.Capabilities;
SetDefaultRenderStates(); SetDefaultRenderStates();
InitDynamicBuffers(); InitCommon();
} }
void FindCompatibleFormat(int adapter) { void FindCompatibleFormat(int adapter) {
@ -305,7 +305,7 @@ namespace ClassicalSharp.GraphicsAPI {
public override int CreateIb(IntPtr indices, int indicesCount) { public override int CreateIb(IntPtr indices, int indicesCount) {
int size = indicesCount * sizeof(ushort); int size = indicesCount * sizeof(ushort);
DataBuffer buffer = device.CreateIndexBuffer(size, Usage.WriteOnly, DataBuffer buffer = device.CreateIndexBuffer(size, Usage.WriteOnly,
Format.Index16, Pool.Managed); Format.Index16, Pool.Default);
buffer.SetData(indices, size, LockFlags.None); buffer.SetData(indices, size, LockFlags.None);
return GetOrExpand(ref iBuffers, buffer, iBufferSize); return GetOrExpand(ref iBuffers, buffer, iBufferSize);
} }

View File

@ -7,31 +7,42 @@ namespace ClassicalSharp.GraphicsAPI {
/// <summary> Abstracts a 3D graphics rendering API. </summary> /// <summary> Abstracts a 3D graphics rendering API. </summary>
public abstract unsafe partial class IGraphicsApi { public abstract unsafe partial class IGraphicsApi {
protected void InitDynamicBuffers() { public int defaultIb;
protected void InitCommon() {
quadVb = CreateDynamicVb(VertexFormat.P3fC4b, 4); quadVb = CreateDynamicVb(VertexFormat.P3fC4b, 4);
texVb = CreateDynamicVb(VertexFormat.P3fT2fC4b, 4); texVb = CreateDynamicVb(VertexFormat.P3fT2fC4b, 4);
const int maxIndices = 65536 / 4 * 6;
ushort* indices = stackalloc ushort[maxIndices];
MakeIndices(indices, maxIndices);
defaultIb = CreateIb((IntPtr)indices, maxIndices);
}
protected void DisposeCommon() {
DeleteVb(ref quadVb);
DeleteVb(ref texVb);
DeleteIb(ref defaultIb);
} }
public virtual void Dispose() { public virtual void Dispose() {
DeleteVb(ref quadVb); DisposeCommon();
DeleteVb(ref texVb);
} }
public void LoseContext(string reason) { public void LoseContext(string reason) {
LostContext = true; LostContext = true;
Utils.LogDebug("Lost graphics context" + reason); Utils.LogDebug("Lost graphics context" + reason);
if (ContextLost != null) ContextLost();
DeleteVb(ref quadVb); if (ContextLost != null) ContextLost();
DeleteVb(ref texVb); DisposeCommon();
} }
public void RecreateContext() { public void RecreateContext() {
LostContext = false; LostContext = false;
Utils.LogDebug("Recreating graphics context"); Utils.LogDebug("Recreating graphics context");
if (ContextRecreated != null) ContextRecreated();
InitDynamicBuffers(); if (ContextRecreated != null) ContextRecreated();
InitCommon();
} }
@ -149,13 +160,6 @@ namespace ClassicalSharp.GraphicsAPI {
if (hadFog) Fog = true; if (hadFog) Fog = true;
} }
internal unsafe int MakeDefaultIb() {
const int maxIndices = 65536 / 4 * 6;
ushort* indices = stackalloc ushort[maxIndices];
MakeIndices(indices, maxIndices);
return CreateIb((IntPtr)indices, maxIndices);
}
internal unsafe void MakeIndices(ushort* indices, int iCount) { internal unsafe void MakeIndices(ushort* indices, int iCount) {
int element = 0; int element = 0;
for (int i = 0; i < iCount; i += 6) { for (int i = 0; i < iCount; i += 6) {

View File

@ -30,7 +30,7 @@ namespace ClassicalSharp.GraphicsAPI {
glLists = Options.GetBool(OptionsKey.ForceOldOpenGL, false); glLists = Options.GetBool(OptionsKey.ForceOldOpenGL, false);
CustomMipmapsLevels = !glLists; CustomMipmapsLevels = !glLists;
CheckVboSupport(); CheckVboSupport();
base.InitDynamicBuffers(); base.InitCommon();
setupBatchFuncCol4b = SetupVbPos3fCol4b; setupBatchFuncCol4b = SetupVbPos3fCol4b;
setupBatchFuncTex2fCol4b = SetupVbPos3fTex2fCol4b; setupBatchFuncTex2fCol4b = SetupVbPos3fTex2fCol4b;

View File

@ -17,7 +17,7 @@ namespace ClassicalSharp.GraphicsAPI {
int texDims; int texDims;
GL.GetInteger(All.MaxTextureSize, &texDims); GL.GetInteger(All.MaxTextureSize, &texDims);
textureDims = texDims; textureDims = texDims;
base.InitDynamicBuffers(); base.InitCommon();
// TODO: Support mipmaps // TODO: Support mipmaps
setupBatchFuncCol4b = SetupVbPos3fCol4b; setupBatchFuncCol4b = SetupVbPos3fCol4b;

13
src/Client/Audio.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef CC_AUDIO_H
#define CC_AUDIO_H
#include "GameStructs.h"
/* Manages playing sound and music.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
IGameComponent Audio_MakeComponent(void);
void Audio_SetMusic(Int32 volume);
void Audio_SetSounds(Int32 volume);
void Audio_PlayDigSound(UInt8 type);
void Audio_PlayStepSound(UInt8 type);
#endif

View File

@ -181,6 +181,7 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="2DStructs.h" /> <ClInclude Include="2DStructs.h" />
<ClInclude Include="AsyncDownloader.h" /> <ClInclude Include="AsyncDownloader.h" />
<ClInclude Include="Audio.h" />
<ClInclude Include="AxisLinesRenderer.h" /> <ClInclude Include="AxisLinesRenderer.h" />
<ClInclude Include="BlockID.h" /> <ClInclude Include="BlockID.h" />
<ClInclude Include="Block.h" /> <ClInclude Include="Block.h" />

View File

@ -366,6 +366,9 @@
<ClInclude Include="TexturePack.h"> <ClInclude Include="TexturePack.h">
<Filter>Header Files\TexturePack</Filter> <Filter>Header Files\TexturePack</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Audio.h">
<Filter>Header Files\Game</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Noise.c"> <ClCompile Include="Noise.c">

View File

@ -56,7 +56,7 @@ void D3D9_FreeResource(GfxResourceID* resource) {
UInt8 logMsgBuffer[String_BufferSize(STRING_SIZE * 2)]; UInt8 logMsgBuffer[String_BufferSize(STRING_SIZE * 2)];
String logMsg = String_InitAndClearArray(logMsgBuffer); String logMsg = String_InitAndClearArray(logMsgBuffer);
String_AppendConst(&logMsg, "D3D9 Resource has outstanding references! ID: "); String_AppendConst(&logMsg, "D3D9 Resource has outstanding references! ID: ");
String_AppendInt32(&logMsg, id); String_AppendInt64(&logMsg, (Int64)(*resource));
Platform_Log(&logMsg); Platform_Log(&logMsg);
} }
@ -158,7 +158,12 @@ void Gfx_Init(void) {
D3D9_SetDefaultRenderStates(); D3D9_SetDefaultRenderStates();
GfxCommon_Init(); GfxCommon_Init();
} }
void Gfx_Free(void) { GfxCommon_Free(); }
void Gfx_Free(void) {
GfxCommon_Free();
D3D9_FreeResource(&device);
D3D9_FreeResource(&d3d);
}
void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp, Int32 lvl) { void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp, Int32 lvl) {
D3DLOCKED_RECT rect; D3DLOCKED_RECT rect;
@ -468,7 +473,7 @@ GfxResourceID Gfx_CreateIb(void* indices, Int32 indicesCount) {
Int32 size = indicesCount * sizeof(UInt16); Int32 size = indicesCount * sizeof(UInt16);
IDirect3DIndexBuffer9* ibuffer; IDirect3DIndexBuffer9* ibuffer;
ReturnCode hresult = IDirect3DDevice9_CreateIndexBuffer(device, size, D3DUSAGE_WRITEONLY, ReturnCode hresult = IDirect3DDevice9_CreateIndexBuffer(device, size, D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_MANAGED, &ibuffer, NULL); D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ibuffer, NULL);
ErrorHandler_CheckOrFail(hresult, "D3D9_CreateIb"); ErrorHandler_CheckOrFail(hresult, "D3D9_CreateIb");
D3D9_SetIbData(ibuffer, indices, size, "D3D9_CreateIb - Lock", "D3D9_CreateIb - Unlock"); D3D9_SetIbData(ibuffer, indices, size, "D3D9_CreateIb - Lock", "D3D9_CreateIb - Unlock");

View File

@ -14,7 +14,7 @@
#include "ModelCache.h" #include "ModelCache.h"
#include "Physics.h" #include "Physics.h"
#include "IModel.h" #include "IModel.h"
#include "Audio.h"
/*########################################################################################################################* /*########################################################################################################################*
*----------------------------------------------------AnimatedComponent----------------------------------------------------* *----------------------------------------------------AnimatedComponent----------------------------------------------------*
@ -1261,7 +1261,7 @@ void SoundComp_Tick(bool wasOnGround) {
if (!sounds_AnyNonAir) soundPos = Vector3_BigPos(); if (!sounds_AnyNonAir) soundPos = Vector3_BigPos();
if (p->Base.OnGround && (SoundComp_DoPlaySound(p, soundPos) || !wasOnGround)) { if (p->Base.OnGround && (SoundComp_DoPlaySound(p, soundPos) || !wasOnGround)) {
AudioPlayer_PlayStepSound(sounds_Type); Audio_PlayStepSound(sounds_Type);
sounds_LastPos = soundPos; sounds_LastPos = soundPos;
} }
} }

View File

@ -37,6 +37,7 @@
#include "PickedPosRenderer.h" #include "PickedPosRenderer.h"
#include "GraphicsCommon.h" #include "GraphicsCommon.h"
#include "Menus.h" #include "Menus.h"
#include "Audio.h"
IGameComponent Game_Components[26]; IGameComponent Game_Components[26];
Int32 Game_ComponentsCount; Int32 Game_ComponentsCount;
@ -401,7 +402,6 @@ void Game_Load(void) {
comp = GameMode_MakeComponent(); Game_AddComponent(&comp); comp = GameMode_MakeComponent(); Game_AddComponent(&comp);
InputHandler_Init(); InputHandler_Init();
defaultIb = Graphics.MakeDefaultIb();
comp = Particles_MakeComponent(); Game_AddComponent(&comp); comp = Particles_MakeComponent(); Game_AddComponent(&comp);
comp = TabList_MakeComponent(); Game_AddComponent(&comp); comp = TabList_MakeComponent(); Game_AddComponent(&comp);
@ -468,7 +468,7 @@ void Game_Load(void) {
Gfx_SetAlphaTestFunc(COMPARE_FUNC_GREATER, 0.5f); Gfx_SetAlphaTestFunc(COMPARE_FUNC_GREATER, 0.5f);
comp = PickedPosRenderer_MakeComponent(); Game_AddComponent(&comp); comp = PickedPosRenderer_MakeComponent(); Game_AddComponent(&comp);
comp = AudioPlayer_MakeComponent(); Game_AddComponent(&comp); comp = Audio_MakeComponent(); Game_AddComponent(&comp);
comp = AxisLinesRenderer_MakeComponent(); Game_AddComponent(&comp); comp = AxisLinesRenderer_MakeComponent(); Game_AddComponent(&comp);
comp = SkyboxRenderer_MakeComponent(); Game_AddComponent(&comp); comp = SkyboxRenderer_MakeComponent(); Game_AddComponent(&comp);
@ -632,7 +632,7 @@ void Game_RenderFrame(Real64 delta) {
Stopwatch_Start(&game_frameTimer); Stopwatch_Start(&game_frameTimer);
Gfx_BeginFrame(); Gfx_BeginFrame();
Graphics.BindIb(defaultIb); Gfx_BindIb(GfxCommon_defaultIb);
Game_Accumulator += delta; Game_Accumulator += delta;
Game_Vertices = 0; Game_Vertices = 0;
GameMode_BeginFrame(delta); GameMode_BeginFrame(delta);
@ -688,7 +688,6 @@ void Game_Free(void) {
Game_Components[i].Free(); Game_Components[i].Free();
} }
Graphics.DeleteIb(&defaultIb);
Drawer2D_Free(); Drawer2D_Free();
Gfx_Free(); Gfx_Free();

View File

@ -10,11 +10,16 @@
void GfxCommon_Init(void) { void GfxCommon_Init(void) {
GfxCommon_quadVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FC4B, 4); GfxCommon_quadVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FC4B, 4);
GfxCommon_texVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, 4); GfxCommon_texVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, 4);
UInt16 indices[GFX_MAX_INDICES];
GfxCommon_MakeIndices(indices, GFX_MAX_INDICES);
GfxCommon_defaultIb = Gfx_CreateIb(indices, GFX_MAX_INDICES);
} }
void GfxCommon_Free(void) { void GfxCommon_Free(void) {
Gfx_DeleteVb(&GfxCommon_quadVb); Gfx_DeleteVb(&GfxCommon_quadVb);
Gfx_DeleteVb(&GfxCommon_texVb); Gfx_DeleteVb(&GfxCommon_texVb);
Gfx_DeleteIb(&GfxCommon_defaultIb);
} }
void GfxCommon_LoseContext(STRING_PURE String* reason) { void GfxCommon_LoseContext(STRING_PURE String* reason) {
@ -126,12 +131,6 @@ void GfxCommon_Mode3D(void) {
if (gfx_hadFog) Gfx_SetFog(true); if (gfx_hadFog) Gfx_SetFog(true);
} }
GfxResourceID GfxCommon_MakeDefaultIb(void) {
UInt16 indices[GFX_MAX_INDICES];
GfxCommon_MakeIndices(indices, GFX_MAX_INDICES);
return Gfx_CreateIb(indices, GFX_MAX_INDICES);
}
void GfxCommon_MakeIndices(UInt16* indices, Int32 iCount) { void GfxCommon_MakeIndices(UInt16* indices, Int32 iCount) {
Int32 element = 0, i; Int32 element = 0, i;

View File

@ -8,6 +8,7 @@
*/ */
typedef struct Texture_ Texture; typedef struct Texture_ Texture;
GfxResourceID GfxCommon_defaultIb;
void GfxCommon_Init(void); void GfxCommon_Init(void);
void GfxCommon_Free(void); void GfxCommon_Free(void);
void GfxCommon_LoseContext(STRING_PURE String* reason); void GfxCommon_LoseContext(STRING_PURE String* reason);
@ -29,9 +30,7 @@ void GfxCommon_Make2DQuad(Texture* tex, PackedCol col, VertexP3fT2fC4b** vertice
void GfxCommon_Mode2D(Int32 width, Int32 height); void GfxCommon_Mode2D(Int32 width, Int32 height);
void GfxCommon_Mode3D(void); void GfxCommon_Mode3D(void);
GfxResourceID GfxCommon_MakeDefaultIb(void);
void GfxCommon_MakeIndices(UInt16* indices, Int32 iCount); void GfxCommon_MakeIndices(UInt16* indices, Int32 iCount);
void GfxCommon_SetupAlphaState(UInt8 draw); void GfxCommon_SetupAlphaState(UInt8 draw);
void GfxCommon_RestoreAlphaState(UInt8 draw); void GfxCommon_RestoreAlphaState(UInt8 draw);

View File

@ -25,6 +25,7 @@
#include "BlockPhysics.h" #include "BlockPhysics.h"
#include "MapRenderer.h" #include "MapRenderer.h"
#include "TexturePack.h" #include "TexturePack.h"
#include "Audio.h"
#define LIST_SCREEN_ITEMS 5 #define LIST_SCREEN_ITEMS 5
#define LIST_SCREEN_BUTTONS (LIST_SCREEN_ITEMS + 3) #define LIST_SCREEN_BUTTONS (LIST_SCREEN_ITEMS + 3)
@ -2170,7 +2171,7 @@ const UInt8* ViewDist_Names[ViewDist_Count] = { "TINY", "SHORT", "NORMAL", "FAR"
void ClassicOptionsScreen_GetMusic(STRING_TRANSIENT String* v) { Menu_GetBool(v, Game_MusicVolume > 0); } void ClassicOptionsScreen_GetMusic(STRING_TRANSIENT String* v) { Menu_GetBool(v, Game_MusicVolume > 0); }
void ClassicOptionsScreen_SetMusic(STRING_PURE String* v) { void ClassicOptionsScreen_SetMusic(STRING_PURE String* v) {
Game_MusicVolume = String_CaselessEqualsConst(v, "ON") ? 100 : 0; Game_MusicVolume = String_CaselessEqualsConst(v, "ON") ? 100 : 0;
AudioPlayer_SetMusic(Game_MusicVolume); Audio_SetMusic(Game_MusicVolume);
Options_SetInt32(OPT_MUSIC_VOLUME, Game_MusicVolume); Options_SetInt32(OPT_MUSIC_VOLUME, Game_MusicVolume);
} }
@ -2202,7 +2203,7 @@ void ClassicOptionsScreen_SetPhysics(STRING_PURE String* v) {
void ClassicOptionsScreen_GetSounds(STRING_TRANSIENT String* v) { Menu_GetBool(v, Game_SoundsVolume > 0); } void ClassicOptionsScreen_GetSounds(STRING_TRANSIENT String* v) { Menu_GetBool(v, Game_SoundsVolume > 0); }
void ClassicOptionsScreen_SetSounds(STRING_PURE String* v) { void ClassicOptionsScreen_SetSounds(STRING_PURE String* v) {
Game_SoundsVolume = String_CaselessEqualsConst(v, "ON") ? 100 : 0; Game_SoundsVolume = String_CaselessEqualsConst(v, "ON") ? 100 : 0;
AudioPlayer_SetSounds(Game_SoundsVolume); Audio_SetSounds(Game_SoundsVolume);
Options_SetInt32(OPT_SOUND_VOLUME, Game_SoundsVolume); Options_SetInt32(OPT_SOUND_VOLUME, Game_SoundsVolume);
} }
@ -2755,14 +2756,14 @@ void MiscOptionsScreen_GetMusic(STRING_TRANSIENT String* v) { String_AppendInt32
void MiscOptionsScreen_SetMusic(STRING_PURE String* v) { void MiscOptionsScreen_SetMusic(STRING_PURE String* v) {
Game_MusicVolume = Menu_Int32(v); Game_MusicVolume = Menu_Int32(v);
Options_Set(OPT_MUSIC_VOLUME, v); Options_Set(OPT_MUSIC_VOLUME, v);
AudioPlayer_SetMusic(Game_MusicVolume); Audio_SetMusic(Game_MusicVolume);
} }
void MiscOptionsScreen_GetSounds(STRING_TRANSIENT String* v) { String_AppendInt32(v, Game_SoundsVolume); } void MiscOptionsScreen_GetSounds(STRING_TRANSIENT String* v) { String_AppendInt32(v, Game_SoundsVolume); }
void MiscOptionsScreen_SetSounds(STRING_PURE String* v) { void MiscOptionsScreen_SetSounds(STRING_PURE String* v) {
Game_SoundsVolume = Menu_Int32(v); Game_SoundsVolume = Menu_Int32(v);
Options_Set(OPT_SOUND_VOLUME, v); Options_Set(OPT_SOUND_VOLUME, v);
AudioPlayer_SetSounds(Game_SoundsVolume); Audio_SetSounds(Game_SoundsVolume);
} }
void MiscOptionsScreen_GetViewBob(STRING_TRANSIENT String* v) { Menu_GetBool(v, Game_ViewBobbing); } void MiscOptionsScreen_GetViewBob(STRING_TRANSIENT String* v) { Menu_GetBool(v, Game_ViewBobbing); }

View File

@ -58,7 +58,7 @@ typedef struct FontDesc_ { void* Handle; UInt16 Size, Style; } FontDesc;
#define Int32_MaxValue ((Int32)2147483647L) #define Int32_MaxValue ((Int32)2147483647L)
#define UInt32_MaxValue ((UInt32)4294967295UL) #define UInt32_MaxValue ((UInt32)4294967295UL)
#define USE_DX false #define USE_DX true
#if USE_DX #if USE_DX
typedef void* GfxResourceID; typedef void* GfxResourceID;