gfxGLShader.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "gfx/gl/gfxGLShader.h"
  24. #include "gfx/gl/gfxGLVertexAttribLocation.h"
  25. #include "gfx/gl/gfxGLDevice.h"
  26. #include "core/frameAllocator.h"
  27. #include "core/stream/fileStream.h"
  28. #include "core/strings/stringFunctions.h"
  29. #include "math/mPoint2.h"
  30. #include "gfx/gfxStructs.h"
  31. #include "console/console.h"
  32. #define CHECK_AARG(pos, name) static StringTableEntry attr_##name = StringTable->insert(#name); if (argName == attr_##name) { glBindAttribLocation(mProgram, pos, attr_##name); continue; }
  33. class GFXGLShaderConstHandle : public GFXShaderConstHandle
  34. {
  35. friend class GFXGLShader;
  36. public:
  37. GFXGLShaderConstHandle( GFXGLShader *shader );
  38. GFXGLShaderConstHandle( GFXGLShader *shader, const GFXShaderConstDesc &desc, GLuint loc, S32 samplerNum );
  39. virtual ~GFXGLShaderConstHandle();
  40. void reinit( const GFXShaderConstDesc &desc, GLuint loc, S32 samplerNum );
  41. const String& getName() const { return mDesc.name; }
  42. GFXShaderConstType getType() const { return mDesc.constType; }
  43. U32 getArraySize() const { return mDesc.arraySize; }
  44. U32 getSize() const;
  45. void setValid( bool valid ) { mValid = valid; }
  46. /// @warning This will always return the value assigned when the shader was
  47. /// initialized. If the value is later changed this method won't reflect that.
  48. S32 getSamplerRegister() const { return mSamplerNum; }
  49. GFXShaderConstDesc mDesc;
  50. GFXGLShader* mShader;
  51. GLuint mLocation;
  52. U32 mOffset;
  53. U32 mSize;
  54. S32 mSamplerNum;
  55. bool mInstancingConstant;
  56. };
  57. GFXGLShaderConstHandle::GFXGLShaderConstHandle( GFXGLShader *shader )
  58. : mShader( shader ), mLocation(0), mOffset(0), mSize(0), mSamplerNum(-1), mInstancingConstant(false)
  59. {
  60. mValid = false;
  61. }
  62. static U32 shaderConstTypeSize(GFXShaderConstType type)
  63. {
  64. switch(type)
  65. {
  66. case GFXSCT_Float:
  67. case GFXSCT_Int:
  68. case GFXSCT_Sampler:
  69. case GFXSCT_SamplerCube:
  70. return 4;
  71. case GFXSCT_Float2:
  72. case GFXSCT_Int2:
  73. return 8;
  74. case GFXSCT_Float3:
  75. case GFXSCT_Int3:
  76. return 12;
  77. case GFXSCT_Float4:
  78. case GFXSCT_Int4:
  79. return 16;
  80. case GFXSCT_Float2x2:
  81. return 16;
  82. case GFXSCT_Float3x3:
  83. return 36;
  84. case GFXSCT_Float4x3:
  85. return 48;
  86. case GFXSCT_Float4x4:
  87. return 64;
  88. default:
  89. AssertFatal(false,"shaderConstTypeSize - Unrecognized constant type");
  90. return 0;
  91. }
  92. }
  93. GFXGLShaderConstHandle::GFXGLShaderConstHandle( GFXGLShader *shader, const GFXShaderConstDesc &desc, GLuint loc, S32 samplerNum )
  94. : mShader(shader), mInstancingConstant(false)
  95. {
  96. reinit(desc, loc, samplerNum);
  97. }
  98. void GFXGLShaderConstHandle::reinit( const GFXShaderConstDesc& desc, GLuint loc, S32 samplerNum )
  99. {
  100. mDesc = desc;
  101. mLocation = loc;
  102. mSamplerNum = samplerNum;
  103. mOffset = 0;
  104. mInstancingConstant = false;
  105. U32 elemSize = shaderConstTypeSize(mDesc.constType);
  106. AssertFatal(elemSize, "GFXGLShaderConst::GFXGLShaderConst - elemSize is 0");
  107. mSize = mDesc.arraySize * elemSize;
  108. mValid = true;
  109. }
  110. U32 GFXGLShaderConstHandle::getSize() const
  111. {
  112. return mSize;
  113. }
  114. GFXGLShaderConstHandle::~GFXGLShaderConstHandle()
  115. {
  116. }
  117. GFXGLShaderConstBuffer::GFXGLShaderConstBuffer(GFXGLShader* shader, U32 bufSize, U8* existingConstants)
  118. {
  119. mShader = shader;
  120. mBuffer = new U8[bufSize];
  121. mWasLost = true;
  122. // Copy the existing constant buffer to preserve sampler numbers
  123. /// @warning This preserves a lot more than sampler numbers, obviously. If there
  124. /// is any code that assumes a new constant buffer will have everything set to
  125. /// 0, it will break.
  126. dMemcpy(mBuffer, existingConstants, bufSize);
  127. }
  128. GFXGLShaderConstBuffer::~GFXGLShaderConstBuffer()
  129. {
  130. delete[] mBuffer;
  131. if ( mShader )
  132. mShader->_unlinkBuffer( this );
  133. }
  134. template<typename ConstType>
  135. void GFXGLShaderConstBuffer::internalSet(GFXShaderConstHandle* handle, const ConstType& param)
  136. {
  137. AssertFatal(handle, "GFXGLShaderConstBuffer::internalSet - Handle is NULL!" );
  138. AssertFatal(handle->isValid(), "GFXGLShaderConstBuffer::internalSet - Handle is not valid!" );
  139. AssertFatal(dynamic_cast<GFXGLShaderConstHandle*>(handle), "GFXGLShaderConstBuffer::set - Incorrect const buffer type");
  140. GFXGLShaderConstHandle* _glHandle = static_cast<GFXGLShaderConstHandle*>(handle);
  141. AssertFatal(mShader == _glHandle->mShader, "GFXGLShaderConstBuffer::set - Should only set handles which are owned by our shader");
  142. U8 *buf = mBuffer + _glHandle->mOffset;
  143. if(_glHandle->mInstancingConstant)
  144. buf = mInstPtr + _glHandle->mOffset;
  145. dMemcpy(buf, &param, sizeof(ConstType));
  146. }
  147. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const F32 fv)
  148. {
  149. internalSet(handle, fv);
  150. }
  151. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point2F& fv)
  152. {
  153. internalSet(handle, fv);
  154. }
  155. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point3F& fv)
  156. {
  157. internalSet(handle, fv);
  158. }
  159. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point4F& fv)
  160. {
  161. internalSet(handle, fv);
  162. }
  163. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const PlaneF& fv)
  164. {
  165. internalSet(handle, fv);
  166. }
  167. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const ColorF& fv)
  168. {
  169. internalSet(handle, fv);
  170. }
  171. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const S32 fv)
  172. {
  173. internalSet(handle, fv);
  174. }
  175. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point2I& fv)
  176. {
  177. internalSet(handle, fv);
  178. }
  179. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point3I& fv)
  180. {
  181. internalSet(handle, fv);
  182. }
  183. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point4I& fv)
  184. {
  185. internalSet(handle, fv);
  186. }
  187. template<typename ConstType>
  188. void GFXGLShaderConstBuffer::internalSet(GFXShaderConstHandle* handle, const AlignedArray<ConstType>& fv)
  189. {
  190. AssertFatal(handle, "GFXGLShaderConstBuffer::internalSet - Handle is NULL!" );
  191. AssertFatal(handle->isValid(), "GFXGLShaderConstBuffer::internalSet - Handle is not valid!" );
  192. AssertFatal(dynamic_cast<GFXGLShaderConstHandle*>(handle), "GFXGLShaderConstBuffer::set - Incorrect const buffer type");
  193. GFXGLShaderConstHandle* _glHandle = static_cast<GFXGLShaderConstHandle*>(handle);
  194. AssertFatal(mShader == _glHandle->mShader, "GFXGLShaderConstBuffer::set - Should only set handles which are owned by our shader");
  195. AssertFatal(!_glHandle->mInstancingConstant, "GFXGLShaderConstBuffer::set - Instancing not supported for array");
  196. const U8* fvBuffer = static_cast<const U8*>(fv.getBuffer());
  197. for(U32 i = 0; i < fv.size(); ++i)
  198. {
  199. dMemcpy(mBuffer + _glHandle->mOffset + i * sizeof(ConstType), fvBuffer, sizeof(ConstType));
  200. fvBuffer += fv.getElementSize();
  201. }
  202. }
  203. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<F32>& fv)
  204. {
  205. internalSet(handle, fv);
  206. }
  207. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point2F>& fv)
  208. {
  209. internalSet(handle, fv);
  210. }
  211. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point3F>& fv)
  212. {
  213. internalSet(handle, fv);
  214. }
  215. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point4F>& fv)
  216. {
  217. internalSet(handle, fv);
  218. }
  219. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<S32>& fv)
  220. {
  221. internalSet(handle, fv);
  222. }
  223. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point2I>& fv)
  224. {
  225. internalSet(handle, fv);
  226. }
  227. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point3I>& fv)
  228. {
  229. internalSet(handle, fv);
  230. }
  231. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point4I>& fv)
  232. {
  233. internalSet(handle, fv);
  234. }
  235. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const MatrixF& mat, const GFXShaderConstType matType)
  236. {
  237. AssertFatal(handle, "GFXGLShaderConstBuffer::set - Handle is NULL!" );
  238. AssertFatal(handle->isValid(), "GFXGLShaderConstBuffer::set - Handle is not valid!" );
  239. AssertFatal(dynamic_cast<GFXGLShaderConstHandle*>(handle), "GFXGLShaderConstBuffer::set - Incorrect const buffer type");
  240. GFXGLShaderConstHandle* _glHandle = static_cast<GFXGLShaderConstHandle*>(handle);
  241. AssertFatal(mShader == _glHandle->mShader, "GFXGLShaderConstBuffer::set - Should only set handles which are owned by our shader");
  242. AssertFatal(!_glHandle->mInstancingConstant || matType == GFXSCT_Float4x4, "GFXGLShaderConstBuffer::set - Only support GFXSCT_Float4x4 for instancing");
  243. switch(matType)
  244. {
  245. case GFXSCT_Float2x2:
  246. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[0] = mat[0];
  247. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[1] = mat[1];
  248. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[2] = mat[4];
  249. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[3] = mat[5];
  250. break;
  251. case GFXSCT_Float3x3:
  252. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[0] = mat[0];
  253. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[1] = mat[1];
  254. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[2] = mat[2];
  255. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[3] = mat[4];
  256. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[4] = mat[5];
  257. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[5] = mat[6];
  258. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[6] = mat[8];
  259. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[7] = mat[9];
  260. reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[8] = mat[10];
  261. break;
  262. case GFXSCT_Float4x3:
  263. dMemcpy(mBuffer + _glHandle->mOffset, (const F32*)mat, (sizeof(F32) * 12));// matrix with end row chopped off
  264. break;
  265. case GFXSCT_Float4x4:
  266. {
  267. if(_glHandle->mInstancingConstant)
  268. {
  269. MatrixF transposed;
  270. mat.transposeTo(transposed);
  271. dMemcpy( mInstPtr + _glHandle->mOffset, (const F32*)transposed, sizeof(MatrixF) );
  272. return;
  273. }
  274. dMemcpy(mBuffer + _glHandle->mOffset, (const F32*)mat, sizeof(MatrixF));
  275. break;
  276. }
  277. default:
  278. AssertFatal(false, "GFXGLShaderConstBuffer::set - Invalid matrix type");
  279. break;
  280. }
  281. }
  282. void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const MatrixF* mat, const U32 arraySize, const GFXShaderConstType matrixType)
  283. {
  284. AssertFatal(handle, "GFXGLShaderConstBuffer::set - Handle is NULL!" );
  285. AssertFatal(handle->isValid(), "GFXGLShaderConstBuffer::set - Handle is not valid!" );
  286. GFXGLShaderConstHandle* _glHandle = static_cast<GFXGLShaderConstHandle*>(handle);
  287. AssertFatal(mShader == _glHandle->mShader, "GFXGLShaderConstBuffer::set - Should only set handles which are owned by our shader");
  288. AssertFatal(!_glHandle->mInstancingConstant, "GFXGLShaderConstBuffer::set - Instancing not supported for matrix arrays");
  289. switch (matrixType) {
  290. case GFXSCT_Float4x3:
  291. // Copy each item with the last row chopped off
  292. for (int i = 0; i<arraySize; i++)
  293. {
  294. dMemcpy(mBuffer + _glHandle->mOffset + (i*(sizeof(F32) * 12)), (F32*)(mat + i), sizeof(F32) * 12);
  295. }
  296. break;
  297. case GFXSCT_Float4x4:
  298. dMemcpy(mBuffer + _glHandle->mOffset, (F32*)mat, _glHandle->getSize());
  299. break;
  300. default:
  301. AssertFatal(false, "GFXGLShaderConstBuffer::set - setting array of non 4x4 matrices!");
  302. break;
  303. }
  304. }
  305. void GFXGLShaderConstBuffer::activate()
  306. {
  307. PROFILE_SCOPE(GFXGLShaderConstBuffer_activate);
  308. mShader->setConstantsFromBuffer(this);
  309. mWasLost = false;
  310. }
  311. const String GFXGLShaderConstBuffer::describeSelf() const
  312. {
  313. return String();
  314. }
  315. void GFXGLShaderConstBuffer::onShaderReload( GFXGLShader *shader )
  316. {
  317. AssertFatal( shader == mShader, "GFXGLShaderConstBuffer::onShaderReload, mismatched shaders!" );
  318. delete[] mBuffer;
  319. mBuffer = new U8[mShader->mConstBufferSize];
  320. dMemset(mBuffer, 0, mShader->mConstBufferSize);
  321. mWasLost = true;
  322. }
  323. GFXGLShader::GFXGLShader() :
  324. mVertexShader(0),
  325. mPixelShader(0),
  326. mProgram(0),
  327. mConstBufferSize(0),
  328. mConstBuffer(NULL)
  329. {
  330. }
  331. GFXGLShader::~GFXGLShader()
  332. {
  333. clearShaders();
  334. for(HandleMap::Iterator i = mHandles.begin(); i != mHandles.end(); i++)
  335. delete i->value;
  336. delete[] mConstBuffer;
  337. }
  338. void GFXGLShader::clearShaders()
  339. {
  340. glDeleteProgram(mProgram);
  341. glDeleteShader(mVertexShader);
  342. glDeleteShader(mPixelShader);
  343. mProgram = 0;
  344. mVertexShader = 0;
  345. mPixelShader = 0;
  346. }
  347. bool GFXGLShader::_init()
  348. {
  349. PROFILE_SCOPE(GFXGLShader_Init);
  350. // Don't initialize empty shaders.
  351. if ( mVertexFile.isEmpty() && mPixelFile.isEmpty() )
  352. return false;
  353. clearShaders();
  354. mProgram = glCreateProgram();
  355. // Set the macros and add the global ones.
  356. Vector<GFXShaderMacro> macros;
  357. macros.merge( mMacros );
  358. macros.merge( smGlobalMacros );
  359. // Add the shader version to the macros.
  360. const U32 mjVer = (U32)mFloor( mPixVersion );
  361. const U32 mnVer = (U32)( ( mPixVersion - F32( mjVer ) ) * 10.01f );
  362. macros.increment();
  363. macros.last().name = "TORQUE_SM";
  364. macros.last().value = String::ToString( mjVer * 10 + mnVer );
  365. macros.increment();
  366. macros.last().name = "TORQUE_VERTEX_SHADER";
  367. macros.last().value = "";
  368. // Default to true so we're "successful" if a vertex/pixel shader wasn't specified.
  369. bool compiledVertexShader = true;
  370. bool compiledPixelShader = true;
  371. // Compile the vertex and pixel shaders if specified.
  372. if(!mVertexFile.isEmpty())
  373. compiledVertexShader = initShader(mVertexFile, true, macros);
  374. macros.last().name = "TORQUE_PIXEL_SHADER";
  375. if(!mPixelFile.isEmpty())
  376. compiledPixelShader = initShader(mPixelFile, false, macros);
  377. // If either shader was present and failed to compile, bail.
  378. if(!compiledVertexShader || !compiledPixelShader)
  379. return false;
  380. // Link it!
  381. glLinkProgram( mProgram );
  382. GLint activeAttribs = 0;
  383. glGetProgramiv(mProgram, GL_ACTIVE_ATTRIBUTES, &activeAttribs );
  384. GLint maxLength;
  385. glGetProgramiv(mProgram, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength);
  386. FrameTemp<GLchar> tempData(maxLength+1);
  387. *tempData.address() = '\0';
  388. // Check atributes
  389. for (U32 i=0; i<activeAttribs; i++)
  390. {
  391. GLint size;
  392. GLenum type;
  393. glGetActiveAttrib(mProgram, i, maxLength + 1, NULL, &size, &type, tempData.address());
  394. StringTableEntry argName = StringTable->insert(tempData.address());
  395. CHECK_AARG(Torque::GL_VertexAttrib_Position, vPosition);
  396. CHECK_AARG(Torque::GL_VertexAttrib_Normal, vNormal);
  397. CHECK_AARG(Torque::GL_VertexAttrib_Color, vColor);
  398. CHECK_AARG(Torque::GL_VertexAttrib_Tangent, vTangent);
  399. CHECK_AARG(Torque::GL_VertexAttrib_TangentW, vTangentW);
  400. CHECK_AARG(Torque::GL_VertexAttrib_Binormal, vBinormal);
  401. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord0, vTexCoord0);
  402. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord1, vTexCoord1);
  403. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord2, vTexCoord2);
  404. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord3, vTexCoord3);
  405. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord4, vTexCoord4);
  406. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord5, vTexCoord5);
  407. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord6, vTexCoord6);
  408. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord7, vTexCoord7);
  409. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord8, vTexCoord8);
  410. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord9, vTexCoord9);
  411. }
  412. //always have OUT_col
  413. glBindFragDataLocation(mProgram, 0, "OUT_col");
  414. // Check OUT_colN
  415. for(U32 i=1;i<4;i++)
  416. {
  417. char buffer[10];
  418. dSprintf(buffer, sizeof(buffer), "OUT_col%u",i);
  419. GLint location = glGetFragDataLocation(mProgram, buffer);
  420. if(location>0)
  421. glBindFragDataLocation(mProgram, i, buffer);
  422. }
  423. // Link it again!
  424. glLinkProgram( mProgram );
  425. GLint linkStatus;
  426. glGetProgramiv( mProgram, GL_LINK_STATUS, &linkStatus );
  427. // Dump the info log to the console
  428. U32 logLength = 0;
  429. glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, (GLint*)&logLength);
  430. if ( logLength )
  431. {
  432. FrameAllocatorMarker fam;
  433. char* log = (char*)fam.alloc( logLength );
  434. glGetProgramInfoLog( mProgram, logLength, NULL, log );
  435. if ( linkStatus == GL_FALSE )
  436. {
  437. if ( smLogErrors )
  438. {
  439. Con::errorf( "GFXGLShader::init - Error linking shader!" );
  440. Con::errorf( "Program %s / %s: %s",
  441. mVertexFile.getFullPath().c_str(), mPixelFile.getFullPath().c_str(), log);
  442. }
  443. }
  444. else if ( smLogWarnings )
  445. {
  446. Con::warnf( "Program %s / %s: %s",
  447. mVertexFile.getFullPath().c_str(), mPixelFile.getFullPath().c_str(), log);
  448. }
  449. }
  450. // If we failed to link, bail.
  451. if ( linkStatus == GL_FALSE )
  452. return false;
  453. initConstantDescs();
  454. initHandles();
  455. // Notify Buffers we might have changed in size.
  456. // If this was our first init then we won't have any activeBuffers
  457. // to worry about unnecessarily calling.
  458. Vector<GFXShaderConstBuffer*>::iterator biter = mActiveBuffers.begin();
  459. for ( ; biter != mActiveBuffers.end(); biter++ )
  460. ((GFXGLShaderConstBuffer*)(*biter))->onShaderReload( this );
  461. return true;
  462. }
  463. void GFXGLShader::initConstantDescs()
  464. {
  465. mConstants.clear();
  466. GLint numUniforms;
  467. glGetProgramiv(mProgram, GL_ACTIVE_UNIFORMS, &numUniforms);
  468. GLint maxNameLength;
  469. glGetProgramiv(mProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameLength);
  470. if(!maxNameLength)
  471. return;
  472. FrameTemp<GLchar> uniformName(maxNameLength);
  473. for(U32 i = 0; i < numUniforms; i++)
  474. {
  475. GLint size;
  476. GLenum type;
  477. glGetActiveUniform(mProgram, i, maxNameLength, NULL, &size, &type, uniformName);
  478. GFXShaderConstDesc desc;
  479. desc.name = String((char*)uniformName);
  480. // Remove array brackets from the name
  481. desc.name = desc.name.substr(0, desc.name.find('['));
  482. // Insert $ to match D3D behavior of having a $ prepended to parameters to main.
  483. desc.name.insert(0, '$');
  484. desc.arraySize = size;
  485. switch(type)
  486. {
  487. case GL_FLOAT:
  488. desc.constType = GFXSCT_Float;
  489. break;
  490. case GL_FLOAT_VEC2:
  491. desc.constType = GFXSCT_Float2;
  492. break;
  493. case GL_FLOAT_VEC3:
  494. desc.constType = GFXSCT_Float3;
  495. break;
  496. case GL_FLOAT_VEC4:
  497. desc.constType = GFXSCT_Float4;
  498. break;
  499. case GL_INT:
  500. desc.constType = GFXSCT_Int;
  501. break;
  502. case GL_INT_VEC2:
  503. desc.constType = GFXSCT_Int2;
  504. break;
  505. case GL_INT_VEC3:
  506. desc.constType = GFXSCT_Int3;
  507. break;
  508. case GL_INT_VEC4:
  509. desc.constType = GFXSCT_Int4;
  510. break;
  511. case GL_FLOAT_MAT2:
  512. desc.constType = GFXSCT_Float2x2;
  513. break;
  514. case GL_FLOAT_MAT3:
  515. desc.constType = GFXSCT_Float3x3;
  516. break;
  517. case GL_FLOAT_MAT4:
  518. desc.constType = GFXSCT_Float4x4;
  519. break;
  520. case GL_FLOAT_MAT4x3: // jamesu - columns, rows
  521. desc.constType = GFXSCT_Float4x3;
  522. break;
  523. case GL_SAMPLER_1D:
  524. case GL_SAMPLER_2D:
  525. case GL_SAMPLER_3D:
  526. case GL_SAMPLER_1D_SHADOW:
  527. case GL_SAMPLER_2D_SHADOW:
  528. desc.constType = GFXSCT_Sampler;
  529. break;
  530. case GL_SAMPLER_CUBE:
  531. desc.constType = GFXSCT_SamplerCube;
  532. break;
  533. default:
  534. AssertFatal(false, "GFXGLShader::initConstantDescs - unrecognized uniform type");
  535. // If we don't recognize the constant don't add its description.
  536. continue;
  537. }
  538. mConstants.push_back(desc);
  539. }
  540. }
  541. void GFXGLShader::initHandles()
  542. {
  543. // Mark all existing handles as invalid.
  544. // Those that are found when parsing the descriptions will then be marked valid again.
  545. for ( HandleMap::Iterator iter = mHandles.begin(); iter != mHandles.end(); ++iter )
  546. (iter->value)->setValid( false );
  547. mValidHandles.clear();
  548. // Loop through all ConstantDescriptions,
  549. // if they aren't in the HandleMap add them, if they are reinitialize them.
  550. for ( U32 i = 0; i < mConstants.size(); i++ )
  551. {
  552. GFXShaderConstDesc &desc = mConstants[i];
  553. // Index element 1 of the name to skip the '$' we inserted earier.
  554. GLint loc = glGetUniformLocation(mProgram, &desc.name.c_str()[1]);
  555. AssertFatal(loc != -1, "");
  556. HandleMap::Iterator handle = mHandles.find(desc.name);
  557. S32 sampler = -1;
  558. if(desc.constType == GFXSCT_Sampler || desc.constType == GFXSCT_SamplerCube)
  559. {
  560. S32 idx = mSamplerNamesOrdered.find_next(desc.name);
  561. AssertFatal(idx != -1, "");
  562. sampler = idx; //assignedSamplerNum++;
  563. }
  564. if ( handle != mHandles.end() )
  565. {
  566. handle->value->reinit( desc, loc, sampler );
  567. }
  568. else
  569. {
  570. mHandles[desc.name] = new GFXGLShaderConstHandle( this, desc, loc, sampler );
  571. }
  572. }
  573. // Loop through handles once more to set their offset and calculate our
  574. // constBuffer size.
  575. if ( mConstBuffer )
  576. delete[] mConstBuffer;
  577. mConstBufferSize = 0;
  578. for ( HandleMap::Iterator iter = mHandles.begin(); iter != mHandles.end(); ++iter )
  579. {
  580. GFXGLShaderConstHandle* handle = iter->value;
  581. if ( handle->isValid() )
  582. {
  583. mValidHandles.push_back(handle);
  584. handle->mOffset = mConstBufferSize;
  585. mConstBufferSize += handle->getSize();
  586. }
  587. }
  588. mConstBuffer = new U8[mConstBufferSize];
  589. dMemset(mConstBuffer, 0, mConstBufferSize);
  590. // Set our program so uniforms are assigned properly.
  591. glUseProgram(mProgram);
  592. // Iterate through uniforms to set sampler numbers.
  593. for (HandleMap::Iterator iter = mHandles.begin(); iter != mHandles.end(); ++iter)
  594. {
  595. GFXGLShaderConstHandle* handle = iter->value;
  596. if(handle->isValid() && (handle->getType() == GFXSCT_Sampler || handle->getType() == GFXSCT_SamplerCube))
  597. {
  598. // Set sampler number on our program.
  599. glUniform1i(handle->mLocation, handle->mSamplerNum);
  600. // Set sampler in constant buffer so it does not get unset later.
  601. dMemcpy(mConstBuffer + handle->mOffset, &handle->mSamplerNum, handle->getSize());
  602. }
  603. }
  604. glUseProgram(0);
  605. //instancing
  606. if (!mInstancingFormat)
  607. return;
  608. U32 offset = 0;
  609. for ( U32 i=0; i < mInstancingFormat->getElementCount(); i++ )
  610. {
  611. const GFXVertexElement &element = mInstancingFormat->getElement( i );
  612. String constName = String::ToString( "$%s", element.getSemantic().c_str() );
  613. HandleMap::Iterator handle = mHandles.find(constName);
  614. if ( handle != mHandles.end() )
  615. {
  616. AssertFatal(0, "");
  617. }
  618. else
  619. {
  620. GFXShaderConstDesc desc;
  621. desc.name = constName;
  622. desc.arraySize = 1;
  623. switch(element.getType())
  624. {
  625. case GFXDeclType_Float4:
  626. desc.constType = GFXSCT_Float4;
  627. break;
  628. default:
  629. desc.constType = GFXSCT_Float;
  630. break;
  631. }
  632. GFXGLShaderConstHandle *h = new GFXGLShaderConstHandle( this, desc, -1, -1 );
  633. h->mInstancingConstant = true;
  634. h->mOffset = offset;
  635. mHandles[constName] = h;
  636. offset += element.getSizeInBytes();
  637. ++i;
  638. // If this is a matrix we will have 2 or 3 more of these
  639. // semantics with the same name after it.
  640. for ( ; i < mInstancingFormat->getElementCount(); i++ )
  641. {
  642. const GFXVertexElement &nextElement = mInstancingFormat->getElement( i );
  643. if ( nextElement.getSemantic() != element.getSemantic() )
  644. {
  645. i--;
  646. break;
  647. }
  648. ++desc.arraySize;
  649. if(desc.arraySize == 4 && desc.constType == GFXSCT_Float4)
  650. {
  651. desc.arraySize = 1;
  652. desc.constType = GFXSCT_Float4x4;
  653. }
  654. offset += nextElement.getSizeInBytes();
  655. }
  656. }
  657. }
  658. }
  659. GFXShaderConstHandle* GFXGLShader::getShaderConstHandle(const String& name)
  660. {
  661. HandleMap::Iterator i = mHandles.find(name);
  662. if(i != mHandles.end())
  663. return i->value;
  664. else
  665. {
  666. GFXGLShaderConstHandle* handle = new GFXGLShaderConstHandle( this );
  667. mHandles[ name ] = handle;
  668. return handle;
  669. }
  670. }
  671. GFXShaderConstHandle* GFXGLShader::findShaderConstHandle(const String& name)
  672. {
  673. HandleMap::Iterator i = mHandles.find(name);
  674. if(i != mHandles.end())
  675. return i->value;
  676. else
  677. {
  678. return NULL;
  679. }
  680. }
  681. void GFXGLShader::setConstantsFromBuffer(GFXGLShaderConstBuffer* buffer)
  682. {
  683. for(Vector<GFXGLShaderConstHandle*>::iterator i = mValidHandles.begin(); i != mValidHandles.end(); ++i)
  684. {
  685. GFXGLShaderConstHandle* handle = *i;
  686. AssertFatal(handle, "GFXGLShader::setConstantsFromBuffer - Null handle");
  687. if(handle->mInstancingConstant)
  688. continue;
  689. // Don't set if the value has not be changed.
  690. if(dMemcmp(mConstBuffer + handle->mOffset, buffer->mBuffer + handle->mOffset, handle->getSize()) == 0)
  691. continue;
  692. // Copy new value into our const buffer and set in GL.
  693. dMemcpy(mConstBuffer + handle->mOffset, buffer->mBuffer + handle->mOffset, handle->getSize());
  694. switch(handle->mDesc.constType)
  695. {
  696. case GFXSCT_Float:
  697. glUniform1fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
  698. break;
  699. case GFXSCT_Float2:
  700. glUniform2fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
  701. break;
  702. case GFXSCT_Float3:
  703. glUniform3fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
  704. break;
  705. case GFXSCT_Float4:
  706. glUniform4fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
  707. break;
  708. case GFXSCT_Int:
  709. case GFXSCT_Sampler:
  710. case GFXSCT_SamplerCube:
  711. glUniform1iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
  712. break;
  713. case GFXSCT_Int2:
  714. glUniform2iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
  715. break;
  716. case GFXSCT_Int3:
  717. glUniform3iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
  718. break;
  719. case GFXSCT_Int4:
  720. glUniform4iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
  721. break;
  722. case GFXSCT_Float2x2:
  723. glUniformMatrix2fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
  724. break;
  725. case GFXSCT_Float3x3:
  726. glUniformMatrix3fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
  727. break;
  728. case GFXSCT_Float4x3:
  729. // NOTE: To save a transpose here we could store the matrix transposed (i.e. column major) in the constant buffer.
  730. // See _mesa_uniform_matrix in the mesa source for the correct transpose algorithm for a 4x3 matrix.
  731. glUniformMatrix4x3fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
  732. break;
  733. case GFXSCT_Float4x4:
  734. glUniformMatrix4fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
  735. break;
  736. default:
  737. AssertFatal(0,"");
  738. break;
  739. }
  740. }
  741. }
  742. GFXShaderConstBufferRef GFXGLShader::allocConstBuffer()
  743. {
  744. GFXGLShaderConstBuffer* buffer = new GFXGLShaderConstBuffer(this, mConstBufferSize, mConstBuffer);
  745. buffer->registerResourceWithDevice(getOwningDevice());
  746. mActiveBuffers.push_back( buffer );
  747. return buffer;
  748. }
  749. void GFXGLShader::useProgram()
  750. {
  751. glUseProgram(mProgram);
  752. }
  753. void GFXGLShader::zombify()
  754. {
  755. clearShaders();
  756. dMemset(mConstBuffer, 0, mConstBufferSize);
  757. }
  758. char* GFXGLShader::_handleIncludes( const Torque::Path& path, FileStream *s )
  759. {
  760. // TODO: The #line pragma on GLSL takes something called a
  761. // "source-string-number" which it then never explains.
  762. //
  763. // Until i resolve this mystery i disabled this.
  764. //
  765. //String linePragma = String::ToString( "#line 1 \r\n");
  766. //U32 linePragmaLen = linePragma.length();
  767. U32 shaderLen = s->getStreamSize();
  768. char* buffer = (char*)dMalloc(shaderLen + 1);
  769. //dStrncpy( buffer, linePragma.c_str(), linePragmaLen );
  770. s->read(shaderLen, buffer);
  771. buffer[shaderLen] = 0;
  772. char* p = dStrstr(buffer, "#include");
  773. while(p)
  774. {
  775. char* q = p;
  776. p += 8;
  777. if(dIsspace(*p))
  778. {
  779. U32 n = 0;
  780. while(dIsspace(*p)) ++p;
  781. AssertFatal(*p == '"', "Bad #include directive");
  782. ++p;
  783. static char includeFile[256];
  784. while(*p != '"')
  785. {
  786. AssertFatal(*p != 0, "Bad #include directive");
  787. includeFile[n++] = *p++;
  788. AssertFatal(n < sizeof(includeFile), "#include directive too long");
  789. }
  790. ++p;
  791. includeFile[n] = 0;
  792. // First try it as a local file.
  793. Torque::Path includePath = Torque::Path::Join(path.getPath(), '/', includeFile);
  794. includePath = Torque::Path::CompressPath(includePath);
  795. FileStream includeStream;
  796. if ( !includeStream.open( includePath, Torque::FS::File::Read ) )
  797. {
  798. // Try again assuming the path is absolute
  799. // and/or relative.
  800. includePath = String( includeFile );
  801. includePath = Torque::Path::CompressPath(includePath);
  802. if ( !includeStream.open( includePath, Torque::FS::File::Read ) )
  803. {
  804. AssertISV(false, avar("failed to open include '%s'.", includePath.getFullPath().c_str()));
  805. if ( smLogErrors )
  806. Con::errorf( "GFXGLShader::_handleIncludes - Failed to open include '%s'.",
  807. includePath.getFullPath().c_str() );
  808. // Fail... don't return the buffer.
  809. dFree(buffer);
  810. return NULL;
  811. }
  812. }
  813. char* includedText = _handleIncludes(includePath, &includeStream);
  814. // If a sub-include fails... cleanup and return.
  815. if ( !includedText )
  816. {
  817. dFree(buffer);
  818. return NULL;
  819. }
  820. // TODO: Disabled till this is fixed correctly.
  821. //
  822. // Count the number of lines in the file
  823. // before the include.
  824. /*
  825. U32 includeLine = 0;
  826. {
  827. char* nl = dStrstr( buffer, "\n" );
  828. while ( nl )
  829. {
  830. includeLine++;
  831. nl = dStrstr( nl, "\n" );
  832. if(nl) ++nl;
  833. }
  834. }
  835. */
  836. String manip(buffer);
  837. manip.erase(q-buffer, p-q);
  838. String sItx(includedText);
  839. // TODO: Disabled till this is fixed correctly.
  840. //
  841. // Add a new line pragma to restore the proper
  842. // file and line number after the include.
  843. //sItx += String::ToString( "\r\n#line %d \r\n", includeLine );
  844. dFree(includedText);
  845. manip.insert(q-buffer, sItx);
  846. char* manipBuf = dStrdup(manip.c_str());
  847. p = manipBuf + (q - buffer);
  848. dFree(buffer);
  849. buffer = manipBuf;
  850. }
  851. p = dStrstr(p, "#include");
  852. }
  853. return buffer;
  854. }
  855. bool GFXGLShader::_loadShaderFromStream( GLuint shader,
  856. const Torque::Path &path,
  857. FileStream *s,
  858. const Vector<GFXShaderMacro> &macros )
  859. {
  860. Vector<char*> buffers;
  861. Vector<U32> lengths;
  862. // The GLSL version declaration must go first!
  863. const char *versionDecl = "#version 150\r\n";
  864. buffers.push_back( dStrdup( versionDecl ) );
  865. lengths.push_back( dStrlen( versionDecl ) );
  866. if(GFXGL->mCapabilities.shaderModel5)
  867. {
  868. const char *extension = "#extension GL_ARB_gpu_shader5 : enable\r\n";
  869. buffers.push_back( dStrdup( extension ) );
  870. lengths.push_back( dStrlen( extension ) );
  871. }
  872. const char *newLine = "\r\n";
  873. buffers.push_back( dStrdup( newLine ) );
  874. lengths.push_back( dStrlen( newLine ) );
  875. // Now add all the macros.
  876. for( U32 i = 0; i < macros.size(); i++ )
  877. {
  878. if(macros[i].name.isEmpty()) // TODO OPENGL
  879. continue;
  880. String define = String::ToString( "#define %s %s\n", macros[i].name.c_str(), macros[i].value.c_str() );
  881. buffers.push_back( dStrdup( define.c_str() ) );
  882. lengths.push_back( define.length() );
  883. }
  884. // Now finally add the shader source.
  885. U32 shaderLen = s->getStreamSize();
  886. char *buffer = _handleIncludes(path, s);
  887. if ( !buffer )
  888. return false;
  889. buffers.push_back(buffer);
  890. lengths.push_back(shaderLen);
  891. glShaderSource(shader, buffers.size(), (const GLchar**)const_cast<const char**>(buffers.address()), NULL);
  892. #if defined(TORQUE_DEBUG) && defined(TORQUE_DEBUG_GFX)
  893. FileStream stream;
  894. if ( !stream.open( path.getFullPath()+"_DEBUG", Torque::FS::File::Write ) )
  895. {
  896. AssertISV(false, avar("GFXGLShader::initShader - failed to write debug shader '%s'.", path.getFullPath().c_str()));
  897. }
  898. for(int i = 0; i < buffers.size(); ++i)
  899. stream.writeText(buffers[i]);
  900. #endif
  901. // Cleanup the shader source buffer.
  902. for ( U32 i=0; i < buffers.size(); i++ )
  903. dFree( buffers[i] );
  904. glCompileShader(shader);
  905. return true;
  906. }
  907. bool GFXGLShader::initShader( const Torque::Path &file,
  908. bool isVertex,
  909. const Vector<GFXShaderMacro> &macros )
  910. {
  911. PROFILE_SCOPE(GFXGLShader_CompileShader);
  912. GLuint activeShader = glCreateShader(isVertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
  913. if(isVertex)
  914. mVertexShader = activeShader;
  915. else
  916. mPixelShader = activeShader;
  917. glAttachShader(mProgram, activeShader);
  918. // Ok it's not in the shader gen manager, so ask Torque for it
  919. FileStream stream;
  920. if ( !stream.open( file, Torque::FS::File::Read ) )
  921. {
  922. AssertISV(false, avar("GFXGLShader::initShader - failed to open shader '%s'.", file.getFullPath().c_str()));
  923. if ( smLogErrors )
  924. Con::errorf( "GFXGLShader::initShader - Failed to open shader file '%s'.",
  925. file.getFullPath().c_str() );
  926. return false;
  927. }
  928. if ( !_loadShaderFromStream( activeShader, file, &stream, macros ) )
  929. return false;
  930. GLint compile;
  931. glGetShaderiv(activeShader, GL_COMPILE_STATUS, &compile);
  932. // Dump the info log to the console
  933. U32 logLength = 0;
  934. glGetShaderiv(activeShader, GL_INFO_LOG_LENGTH, (GLint*)&logLength);
  935. GLint compileStatus = GL_TRUE;
  936. if ( logLength )
  937. {
  938. FrameAllocatorMarker fam;
  939. char* log = (char*)fam.alloc(logLength);
  940. glGetShaderInfoLog(activeShader, logLength, NULL, log);
  941. // Always print errors
  942. glGetShaderiv( activeShader, GL_COMPILE_STATUS, &compileStatus );
  943. if ( compileStatus == GL_FALSE )
  944. {
  945. if ( smLogErrors )
  946. {
  947. Con::errorf( "GFXGLShader::initShader - Error compiling shader!" );
  948. Con::errorf( "Program %s: %s", file.getFullPath().c_str(), log );
  949. }
  950. }
  951. else if ( smLogWarnings )
  952. Con::warnf( "Program %s: %s", file.getFullPath().c_str(), log );
  953. }
  954. return compileStatus != GL_FALSE;
  955. }
  956. /// Returns our list of shader constants, the material can get this and just set the constants it knows about
  957. const Vector<GFXShaderConstDesc>& GFXGLShader::getShaderConstDesc() const
  958. {
  959. PROFILE_SCOPE(GFXGLShader_GetShaderConstants);
  960. return mConstants;
  961. }
  962. /// Returns the alignment value for constType
  963. U32 GFXGLShader::getAlignmentValue(const GFXShaderConstType constType) const
  964. {
  965. // Alignment is the same thing as size for us.
  966. return shaderConstTypeSize(constType);
  967. }
  968. const String GFXGLShader::describeSelf() const
  969. {
  970. String ret;
  971. ret = String::ToString(" Program: %i", mProgram);
  972. ret += String::ToString(" Vertex Path: %s", mVertexFile.getFullPath().c_str());
  973. ret += String::ToString(" Pixel Path: %s", mPixelFile.getFullPath().c_str());
  974. return ret;
  975. }