• Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Sign in to follow this  


Well, I've been off work this week (You might have noticed me posting slightly less o the forums [lol]). But for a change, I actually got some coding done. Hooray!

Firstly, my engine can now use vertex shaders quite happily. Only models use them at the moment, not sprites - but I'll get around to that fairly soon. I was actually quite surprised at how easy vertex shaders are to use, and it also got me thinking that I really need a way to precompile shaders instead of compiling them at load time, although I don't know if that's likely to cause any problems; or rather if D3DX does any optimisation for the card when it's compiling. But I'll burn that bridge when I come to it.

I've also got MD2 model loading working, and animaion, and a helper class to handle animation sequences. Some example code:

// Load model
EModel::SP pModel = new EModel(L"gladiator.mdl");
m_pModelAnim = new EModelAnimator(pModel, 1000.0f / 15.0f); // Animate at 15 FPS

// Main loop:
EInput& input = EInput::Get();
else if(input.WasKeyTapped('B'))
else if(input.WasKeyTapped('C'))

Touching a model will create the context for the model, which will load it from the resource pack, get the shader (load and compile it if needed), and set up the VB and IB for the model. The SetSequence() function has an optional parameter that lets you specify if you want to blend to the new sequence, or just snap to it, defaulting to "blend".

And yes, yes, I know I've got singletonitus. I've been doing a bit of tidying up in the engine code, E.g. passing a PGraphics reference to PVertexBuffer::Create() instead of using the singleton Get() function, but there's still quite a few singletons that I think fit perfectly well with the singleton pattern. Those are:

  • EInput - Keyboard and mouse input

  • EResourceManager - Unpacks, caches and returns resources from the pack file

  • EGraphics - Graphics system

  • EAudio - Audio manager

I know someone's going to have something to say about my "manager" classes, particularly graphics and input. But my reasoning is there will only ever be one output device. There will only ever be one input and audio system, and they need to be referenced from all over the app (Primarily for convenience, the game class could store them internally I suppose).

Anyway, I still heart singletons. And they haven't shat on me (yet).
Sign in to follow this  


Recommended Comments

Original post by Evil Steve
I really need a way to precompile shaders instead of compiling them at load time, although I don't know if that's likely to cause any problems; or rather if D3DX does any optimisation for the card when it's compiling.

It is the recommend way to precompile shaders. The shader compiler doesn’t care about the hardware in your system.

Share this comment

Link to comment
Original post by LachlanL
Maybe I'm being naive here, but does precompiling shaders really save you that much time?
Stepping over the D3DXCompileShader() call in the debugger, it takes a noticible time (maybe 250ms - 500ms). So I'd assume that it does, yes.

And that's only to compile this shader:

// Basic.vsh - Basic vertex shader. Performs basic transform of vertices

float4x4 mWorldViewProj; // World * View * Projection transformation
float4 Diffuse; // Diffuse colour for vertices


struct VS_OUTPUT
float4 Position : POSITION; // Vertex position
float4 Diffuse : COLOR0; // Vertex diffuse color
float2 Tex0 : TEXCOORD0; // Texture coordinates

// Shader entry point
VS_OUTPUT Main( float4 Position : POSITION0,
float3 Normal : NORMAL0,
float2 Tex0 : TEXCOORD0)

Output.Position = mul(Position, mWorldViewProj);
Output.Diffuse = Diffuse;
Output.Tex0 = Tex0;

return Output;


(Yes, I know it's ignoring normals [smile])

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement