Advertisement Jump to content
Sign in to follow this  

How do you do this? (C# question)

This topic is 4964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok I got a problem that is hard to summarize in the subject line. I got a class Renderer that has a property RenderState. The RenderState property gets or sets a RenderState class that has information about the render state. So I can call: renderer.RenderState = renderStateVar; Or change a specific state: renderer.RenderState.FillMode = fillModeVar; I got a class DX9Renderer that derives from Renderer. Whenever the render state var is changed I want the DX9Renderer to update the directx 9 renderer state. No problem so far, I just override set_RenderState. But I also want the renderer to change the directx 9 render state when RenderState.FillMode is set. I'm not sure how to implement this in a good way. Any ideas?

Share this post

Link to post
Share on other sites
Add an event delegate to RenderState, which you can subscribe to with your Renderer class. Whenever a variable in RenderState is changed, invoke the delegate, informing anyone who is listening.

Of course, every time you set the entire "renderer.RenderState" property, you will need to set the new RenderState objects's event to point to your callback method... but that could be done in your RenderState property.

Kind of like this.. (disclaimer: I'm just wingin' this off the top of my head.. I havn't done C# delegates for a while, so syntax might not be right on.)

delegate void OnStateChangeDelegate();
class RenderState {
// ...
public OnStateChangeDelegate OnChange;

// fillmode property
public void FillMode {
set {
if(NULL != OnChange)

class DX9Renderer {

// RenderState property
public void RenderState {
set {
// add the delegate to the RenderState
RenderState r = (RenderState)value;
r.OnChange = new OnStateChangeDelegate(this.OnRenderStateChange);

// we set a whole new renderstate, update the renderer

public void OnRenderStateChange()
// Update Dx9 renderer

// .. .elsewhere
DX9Renderer renderer = new DX9Renderer();
RenderState newState = new RenderState();

renderer.RenderState = newState; // OnRenderStateChange called.
newState.FillMode = something; // OnRenderStateChange called via delegate.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!