コード例 #1
0
ファイル: Resource.cs プロジェクト: KoMaTo3/csgl
        public static Resource Get( string fileName )
        {
            foreach( var res in Resource.resourceList ) {
            if( res.name == fileName ) {
              Console.WriteLine( "Resource: getted old resource '{0}'", res );
              return res;
            }
              }

              Resource result = null;

              byte [] data;
              try {
            data = File.ReadAllBytes( fileName );
              } catch( Exception ) {
            Console.WriteLine( "[ERROR] Resource.Get - failed to load file '{0}'", fileName );
            return result;
              }

              string extension = Path.GetExtension( fileName ).ToLower();
              Console.WriteLine( "Resource: {0}", extension );
              switch( extension ) {
            case ".vs":
              {
            result = new ResourceShader( fileName, System.Text.Encoding.Default.GetString( data ), ShaderType.VertexShader );
              }
            break; //vs
            case ".fs":
              {
            result = new ResourceShader( fileName, System.Text.Encoding.Default.GetString( data ), ShaderType.FragmentShader );
              }
            break; //fs
            case ".sp":
              {
            result = new ResourceShaderProgram( fileName, System.Text.Encoding.Default.GetString( data ) );
            Console.WriteLine( "ResourceShaderProgram loaded" );
              }
            break; //sp
            case ".tga":
              {
            result = new ResourceImage( fileName, data );
              }
            break; //tga
            case ".tex":
              {
            result = new ResourceTexture( fileName, System.Text.Encoding.Default.GetString( data ) );
              }
            break; //tex
            case ".mat":
              {
            result = new ResourceMaterial( fileName, System.Text.Encoding.Default.GetString( data ) );
              }
            break; //mat
            case ".mesh":
              {
            result = new ResourceMesh( fileName, System.Text.Encoding.Default.GetString( data ) );
              }
            break; //mesh
            case ".model":
              {
            result = new ResourceModel( fileName, System.Text.Encoding.Default.GetString( data ) );
              }
            break; //model
              }//switch extension

              if( result != null ) {
            result.name = fileName;
            result.id = Resource._lastId++;
            Resource.resourceList.Add( result );
            Console.WriteLine( "+resource: {0}", Resource.resourceList.Count );
              }

              return result;
        }
コード例 #2
0
        public static Resource Get(string fileName)
        {
            foreach (var res in Resource.resourceList)
            {
                if (res.name == fileName)
                {
                    Console.WriteLine("Resource: getted old resource '{0}'", res);
                    return(res);
                }
            }

            Resource result = null;

            byte [] data;
            try {
                data = File.ReadAllBytes(fileName);
            } catch (Exception) {
                Console.WriteLine("[ERROR] Resource.Get - failed to load file '{0}'", fileName);
                return(result);
            }

            string extension = Path.GetExtension(fileName).ToLower();

            Console.WriteLine("Resource: {0}", extension);
            switch (extension)
            {
            case ".vs":
            {
                result = new ResourceShader(fileName, System.Text.Encoding.Default.GetString(data), ShaderType.VertexShader);
            }
            break; //vs

            case ".fs":
            {
                result = new ResourceShader(fileName, System.Text.Encoding.Default.GetString(data), ShaderType.FragmentShader);
            }
            break; //fs

            case ".sp":
            {
                result = new ResourceShaderProgram(fileName, System.Text.Encoding.Default.GetString(data));
                Console.WriteLine("ResourceShaderProgram loaded");
            }
            break; //sp

            case ".tga":
            {
                result = new ResourceImage(fileName, data);
            }
            break; //tga

            case ".tex":
            {
                result = new ResourceTexture(fileName, System.Text.Encoding.Default.GetString(data));
            }
            break; //tex

            case ".mat":
            {
                result = new ResourceMaterial(fileName, System.Text.Encoding.Default.GetString(data));
            }
            break; //mat

            case ".mesh":
            {
                result = new ResourceMesh(fileName, System.Text.Encoding.Default.GetString(data));
            }
            break; //mesh

            case ".model":
            {
                result = new ResourceModel(fileName, System.Text.Encoding.Default.GetString(data));
            }
            break; //model
            }//switch extension

            if (result != null)
            {
                result.name = fileName;
                result.id   = Resource._lastId++;
                Resource.resourceList.Add(result);
                Console.WriteLine("+resource: {0}", Resource.resourceList.Count);
            }

            return(result);
        }