Helper class with common methods for use in the Cg plugin.
예제 #1
0
        /// <summary>
        ///    Internal constructor.
        /// </summary>
        internal CgProgramFactory()
        {
            // create the Cg context
            cgContext = Cg.cgCreateContext();

            CgHelper.CheckCgError("Error creating Cg context.", cgContext);
        }
예제 #2
0
        /// <summary>
        ///    Unloads the Cg program.
        /// </summary>
        protected override void UnloadHighLevelImpl()
        {
            // destroy this program if it had been loaded
            if (cgProgram != IntPtr.Zero)
            {
                Cg.cgDestroyProgram(cgProgram);

                CgHelper.CheckCgError(string.Format("Error unloading CgProgram named '{0}'", this.name), cgContext);
                cgProgram = IntPtr.Zero;
            }
        }
예제 #3
0
파일: CgProgram.cs 프로젝트: suntabu/axiom
        protected void CompileMicrocode()
        {
            // Create Cg Program

            if (this.selectedCgProfile == Cg.CG_PROFILE_UNKNOWN)
            {
                LogManager.Instance.Write("Attempted to load Cg program '" + _name + "', but no suported profile was found. ");
                return;
            }

            BuildArgs();
            // deal with includes
            String sourceToUse = ResolveCgIncludes(source, this, fileName);

            var cgProgram = Cg.cgCreateProgram(this.cgContext, Cg.CG_SOURCE, sourceToUse, this.selectedCgProfile, this.entry, this.cgArguments);

            // Test
            //LogManager::getSingleton().logMessage(cgGetProgramString(mCgProgram, CG_COMPILED_PROGRAM));

            // Check for errors
            CgHelper.CheckCgError("Unable to compile Cg program " + _name + ": ", this.cgContext);

            var error = Cg.cgGetError();

            if (error == Cg.CG_NO_ERROR)
            {
                // get program string (result of cg compile)
                this.programString = Cg.cgGetProgramString(cgProgram, Cg.CG_COMPILED_PROGRAM);

                // get params
                this.parametersMap.Clear();
                RecurseParams(Cg.cgGetFirstParameter(cgProgram, Cg.CG_PROGRAM));
                RecurseParams(Cg.cgGetFirstParameter(cgProgram, Cg.CG_GLOBAL));

                // Unload Cg Program - we don't need it anymore
                Cg.cgDestroyProgram(cgProgram);
                CgHelper.CheckCgError("Error while unloading Cg program " + _name + ": ", this.cgContext);
                cgProgram = IntPtr.Zero;

                /*
                 * if ( GpuProgramManager.Instance.SaveMicrocodesToCache )
                 * {
                 *  AddMicrocodeToCache();
                 * }*/
            }
        }
예제 #4
0
        protected void SelectProfile()
        {
            selectedProfile   = "";
            selectedCgProfile = Cg.CG_PROFILE_UNKNOWN;

            for (int i = 0; i < profiles.Length; i++)
            {
                if (GpuProgramManager.Instance.IsSyntaxSupported(profiles[i]))
                {
                    selectedProfile   = profiles[i];
                    selectedCgProfile = Cg.cgGetProfile(selectedProfile);

                    CgHelper.CheckCgError("Unable to find Cg profile enum for program " + name, cgContext);

                    break;
                }
            }
        }
예제 #5
0
파일: CgProgram.cs 프로젝트: suntabu/axiom
        protected void SelectProfile()
        {
            this.selectedProfile   = "";
            this.selectedCgProfile = Cg.CG_PROFILE_UNKNOWN;

            if (this.profiles != null)
            {
                foreach (var i in this.profiles)
                {
                    if (GpuProgramManager.Instance.IsSyntaxSupported(i))
                    {
                        this.selectedProfile   = i;
                        this.selectedCgProfile = Cg.cgGetProfile(this.selectedProfile);

                        CgHelper.CheckCgError("Unable to find Cg profile enum for program " + Name, this.cgContext);

                        break;
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        protected override void LoadFromSource()
        {
            SelectProfile();

            string[] args = null;

            // This option causes an error with the CG 1.3 compiler
            if (selectedCgProfile == Cg.CG_PROFILE_VS_1_1)
            {
                args = new string[] { "-profileopts", "dcls", null };
            }

            // create the Cg program
            cgProgram = Cg.cgCreateProgram(cgContext, Cg.CG_SOURCE, source, selectedCgProfile, entry, args);

            string cgErrStr = CgHelper.FormatCgError("Unable to compile Cg program " + name, cgContext);

            if (cgErrStr != null)
            {
                LogManager.Instance.Write("Unable to compile CG program {0}:\n{1}", name, cgErrStr);
                CgHelper.CheckCgError("Unable to compile Cg program " + name, cgContext);
            }
        }