CmCgProgram.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __CgProgram_H__
  25. #define __CgProgram_H__
  26. #include "CmPrerequisites.h"
  27. #include <Cg/cg.h>
  28. #include "CmHighLevelGpuProgram.h"
  29. namespace CamelotFramework {
  30. /** Specialisation of HighLevelGpuProgram to provide support for nVidia's CG language.
  31. @remarks
  32. In its current state Cg only acts as a translator and internally creates either a HLSL
  33. or a GLSL object. Cg doesn't support SM5 for GLSL (only Nvidia cards are supported,
  34. which makes it very much useless for majority of projects).
  35. */
  36. class CM_EXPORT CgProgram : public HighLevelGpuProgram
  37. {
  38. public:
  39. ~CgProgram();
  40. /** Gets the entry point defined for this program. */
  41. const String& getEntryPoint(void) const { return mEntryPoint; }
  42. /// Overridden from GpuProgram
  43. bool isSupported(void) const;
  44. /// Overridden from GpuProgram
  45. const String& getLanguage(void) const;
  46. /**
  47. * @copydoc HighLevelGpuProgram::getBindingDelegate().
  48. */
  49. GpuProgramPtr getBindingDelegate();
  50. /**
  51. * @copydoc HighLevelGpuProgram::createParameters().
  52. */
  53. GpuParamsPtr createParameters();
  54. protected:
  55. friend class CgProgramFactory;
  56. /// The CG context to use, passed in by factory
  57. CGcontext mCgContext;
  58. /// Program handle
  59. CGprogram mCgProgram;
  60. String mSelectedProfile;
  61. CGprofile mSelectedCgProfile;
  62. CgProgram(CGcontext context, const String& source, const String& entryPoint, const String& language,
  63. GpuProgramType gptype, GpuProgramProfile profile, const Vector<HGpuProgInclude>::type* includes,
  64. bool isAdjacencyInfoRequired = false);
  65. /** Internal load implementation, must be implemented by subclasses.
  66. */
  67. void loadFromSource(void);
  68. /**
  69. * @copydoc GpuProgram::unload_internal()
  70. */
  71. void unload_internal(void);
  72. /**
  73. * @brief Cg acts only like a wrapper to a rendersystem specific program.
  74. * This returns the actual program we are wrapping.
  75. */
  76. HighLevelGpuProgramPtr getWrappedProgram() const;
  77. /// Internal method which works out which profile to use for this program
  78. void selectProfile(void);
  79. /************************************************************************/
  80. /* SERIALIZATION */
  81. /************************************************************************/
  82. public:
  83. friend class CgProgramRTTI;
  84. static RTTITypeBase* getRTTIStatic();
  85. virtual RTTITypeBase* getRTTI() const;
  86. };
  87. /** Utility function, checks Cg for errors, throw exception if detected.
  88. @param ogreMethod Ogre method name, as Class::method
  89. @param errorTextPrefix The text to prefix the Cg error text with
  90. */
  91. void checkForCgError(const String& ogreMethod, const String& errorTextPrefix, CGcontext context);
  92. }
  93. #endif