Click here to Skip to main content
15,896,154 members
Articles / Multimedia / DirectX

Endogine sprite engine

Rate me:
Please Sign up or sign in to vote.
4.84/5 (53 votes)
17 Jul 200615 min read 717.9K   22.1K   216  
Sprite engine for D3D and GDI+ (with several game examples).
using System;
using System.Collections.Generic;
using System.Text;

namespace Endogine.ResourceManagement
{
    public abstract class Shaders
    {
        protected Dictionary<string, Shader> _aliasToEffect;
        protected Dictionary<string, Shader> _filenameToEffect;

        public Shaders()
        {
            this._aliasToEffect = new Dictionary<string, Shader>();
            this._filenameToEffect = new Dictionary<string, Shader>();
        }

        public abstract Shader Load(string filename, string alias);
        public Shader Load(string filename)
        {
            return this.Load(filename, filename);
        }
        public abstract Shader Create(string implementation, string alias);


        public void Reload(string alias)
        {
        }

        public abstract void Unload(string alias);


        protected bool CheckLoad(string filename, string alias)
        {
            //TODO: keep track of file date - we might want to reload the same file after changes.
            if (this._filenameToEffect.ContainsKey(filename))
                return false;

            if (!System.IO.File.Exists(filename))
                throw new System.IO.FileNotFoundException("D3D shader file not found: " + filename);

            return true;
        }
        protected void AddShader(Shader shader, string filename, string alias)
        {
            this._aliasToEffect.Add(alias, shader);
            this._filenameToEffect.Add(filename, shader);
        }

        public Shader this[string alias]
        {
            get
            {
                if (this._aliasToEffect.ContainsKey(alias))
                    return this._aliasToEffect[alias];

                if (this._filenameToEffect.ContainsKey(alias))
                    return this._filenameToEffect[alias];

                return null;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Sweden Sweden
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions