gfxGLShader.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  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 LinearColorF& 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. macros.increment();
  360. macros.last().name = "TORQUE_SM";
  361. macros.last().value = 40;
  362. macros.increment();
  363. macros.last().name = "TORQUE_VERTEX_SHADER";
  364. macros.last().value = "";
  365. // Default to true so we're "successful" if a vertex/pixel shader wasn't specified.
  366. bool compiledVertexShader = true;
  367. bool compiledPixelShader = true;
  368. // Compile the vertex and pixel shaders if specified.
  369. if(!mVertexFile.isEmpty())
  370. compiledVertexShader = initShader(mVertexFile, true, macros);
  371. macros.last().name = "TORQUE_PIXEL_SHADER";
  372. if(!mPixelFile.isEmpty())
  373. compiledPixelShader = initShader(mPixelFile, false, macros);
  374. // If either shader was present and failed to compile, bail.
  375. if(!compiledVertexShader || !compiledPixelShader)
  376. return false;
  377. // Link it!
  378. glLinkProgram( mProgram );
  379. GLint activeAttribs = 0;
  380. glGetProgramiv(mProgram, GL_ACTIVE_ATTRIBUTES, &activeAttribs );
  381. GLint maxLength;
  382. glGetProgramiv(mProgram, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength);
  383. FrameTemp<GLchar> tempData(maxLength+1);
  384. *tempData.address() = '\0';
  385. // Check atributes
  386. for (U32 i=0; i<activeAttribs; i++)
  387. {
  388. GLint size;
  389. GLenum type;
  390. glGetActiveAttrib(mProgram, i, maxLength + 1, NULL, &size, &type, tempData.address());
  391. StringTableEntry argName = StringTable->insert(tempData.address());
  392. CHECK_AARG(Torque::GL_VertexAttrib_Position, vPosition);
  393. CHECK_AARG(Torque::GL_VertexAttrib_Normal, vNormal);
  394. CHECK_AARG(Torque::GL_VertexAttrib_Color, vColor);
  395. CHECK_AARG(Torque::GL_VertexAttrib_Tangent, vTangent);
  396. CHECK_AARG(Torque::GL_VertexAttrib_TangentW, vTangentW);
  397. CHECK_AARG(Torque::GL_VertexAttrib_Binormal, vBinormal);
  398. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord0, vTexCoord0);
  399. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord1, vTexCoord1);
  400. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord2, vTexCoord2);
  401. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord3, vTexCoord3);
  402. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord4, vTexCoord4);
  403. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord5, vTexCoord5);
  404. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord6, vTexCoord6);
  405. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord7, vTexCoord7);
  406. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord8, vTexCoord8);
  407. CHECK_AARG(Torque::GL_VertexAttrib_TexCoord9, vTexCoord9);
  408. }
  409. //always have OUT_col
  410. glBindFragDataLocation(mProgram, 0, "OUT_col");
  411. // Check OUT_colN
  412. for(U32 i=1;i<4;i++)
  413. {
  414. char buffer[10];
  415. dSprintf(buffer, sizeof(buffer), "OUT_col%u",i);
  416. GLint location = glGetFragDataLocation(mProgram, buffer);
  417. if(location>0)
  418. glBindFragDataLocation(mProgram, i, buffer);
  419. }
  420. // Link it again!
  421. glLinkProgram( mProgram );
  422. GLint linkStatus;
  423. glGetProgramiv( mProgram, GL_LINK_STATUS, &linkStatus );
  424. // Dump the info log to the console
  425. U32 logLength = 0;
  426. glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, (GLint*)&logLength);
  427. if ( logLength )
  428. {
  429. FrameAllocatorMarker fam;
  430. char* log = (char*)fam.alloc( logLength );
  431. glGetProgramInfoLog( mProgram, logLength, NULL, log );
  432. if ( linkStatus == GL_FALSE )
  433. {
  434. if ( smLogErrors )
  435. {
  436. Con::errorf( "GFXGLShader::init - Error linking shader!" );
  437. Con::errorf( "Program %s / %s: %s",
  438. mVertexFile.getFullPath().c_str(), mPixelFile.getFullPath().c_str(), log);
  439. }
  440. }
  441. else if ( smLogWarnings )
  442. {
  443. Con::warnf( "Program %s / %s: %s",
  444. mVertexFile.getFullPath().c_str(), mPixelFile.getFullPath().c_str(), log);
  445. }
  446. }
  447. // If we failed to link, bail.
  448. if ( linkStatus == GL_FALSE )
  449. return false;
  450. initConstantDescs();
  451. initHandles();
  452. // Notify Buffers we might have changed in size.
  453. // If this was our first init then we won't have any activeBuffers
  454. // to worry about unnecessarily calling.
  455. Vector<GFXShaderConstBuffer*>::iterator biter = mActiveBuffers.begin();
  456. for ( ; biter != mActiveBuffers.end(); biter++ )
  457. ((GFXGLShaderConstBuffer*)(*biter))->onShaderReload( this );
  458. return true;
  459. }
  460. void GFXGLShader::initConstantDescs()
  461. {
  462. mConstants.clear();
  463. GLint numUniforms;
  464. glGetProgramiv(mProgram, GL_ACTIVE_UNIFORMS, &numUniforms);
  465. GLint maxNameLength;
  466. glGetProgramiv(mProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameLength);
  467. if(!maxNameLength)
  468. return;
  469. FrameTemp<GLchar> uniformName(maxNameLength);
  470. for(U32 i = 0; i < numUniforms; i++)
  471. {
  472. GLint size;
  473. GLenum type;
  474. glGetActiveUniform(mProgram, i, maxNameLength, NULL, &size, &type, uniformName);
  475. GFXShaderConstDesc desc;
  476. desc.name = String((char*)uniformName);
  477. // Remove array brackets from the name
  478. desc.name = desc.name.substr(0, desc.name.find('['));
  479. // Insert $ to match D3D behavior of having a $ prepended to parameters to main.
  480. desc.name.insert(0, '$');
  481. desc.arraySize = size;
  482. switch(type)
  483. {
  484. case GL_FLOAT:
  485. desc.constType = GFXSCT_Float;
  486. break;
  487. case GL_FLOAT_VEC2:
  488. desc.constType = GFXSCT_Float2;
  489. break;
  490. case GL_FLOAT_VEC3:
  491. desc.constType = GFXSCT_Float3;
  492. break;
  493. case GL_FLOAT_VEC4:
  494. desc.constType = GFXSCT_Float4;
  495. break;
  496. case GL_INT:
  497. desc.constType = GFXSCT_Int;
  498. break;
  499. case GL_INT_VEC2:
  500. desc.constType = GFXSCT_Int2;
  501. break;
  502. case GL_INT_VEC3:
  503. desc.constType = GFXSCT_Int3;
  504. break;
  505. case GL_INT_VEC4:
  506. desc.constType = GFXSCT_Int4;
  507. break;
  508. case GL_FLOAT_MAT2:
  509. desc.constType = GFXSCT_Float2x2;
  510. break;
  511. case GL_FLOAT_MAT3:
  512. desc.constType = GFXSCT_Float3x3;
  513. break;
  514. case GL_FLOAT_MAT4:
  515. desc.constType = GFXSCT_Float4x4;
  516. break;
  517. case GL_FLOAT_MAT4x3: // jamesu - columns, rows
  518. desc.constType = GFXSCT_Float4x3;
  519. break;
  520. case GL_SAMPLER_1D:
  521. case GL_SAMPLER_2D:
  522. case GL_SAMPLER_3D:
  523. case GL_SAMPLER_1D_SHADOW:
  524. case GL_SAMPLER_2D_SHADOW:
  525. desc.constType = GFXSCT_Sampler;
  526. break;
  527. case GL_SAMPLER_CUBE:
  528. desc.constType = GFXSCT_SamplerCube;
  529. break;
  530. default:
  531. AssertFatal(false, "GFXGLShader::initConstantDescs - unrecognized uniform type");
  532. // If we don't recognize the constant don't add its description.
  533. continue;
  534. }
  535. mConstants.push_back(desc);
  536. }
  537. }
  538. void GFXGLShader::initHandles()
  539. {
  540. // Mark all existing handles as invalid.
  541. // Those that are found when parsing the descriptions will then be marked valid again.
  542. for ( HandleMap::Iterator iter = mHandles.begin(); iter != mHandles.end(); ++iter )
  543. (iter->value)->setValid( false );
  544. mValidHandles.clear();
  545. // Loop through all ConstantDescriptions,
  546. // if they aren't in the HandleMap add them, if they are reinitialize them.
  547. for ( U32 i = 0; i < mConstants.size(); i++ )
  548. {
  549. GFXShaderConstDesc &desc = mConstants[i];
  550. // Index element 1 of the name to skip the '$' we inserted earier.
  551. GLint loc = glGetUniformLocation(mProgram, &desc.name.c_str()[1]);
  552. AssertFatal(loc != -1, "");
  553. HandleMap::Iterator handle = mHandles.find(desc.name);
  554. S32 sampler = -1;
  555. if(desc.constType == GFXSCT_Sampler || desc.constType == GFXSCT_SamplerCube)
  556. {
  557. S32 idx = mSamplerNamesOrdered.find_next(desc.name);
  558. AssertFatal(idx != -1, "");
  559. sampler = idx; //assignedSamplerNum++;
  560. }
  561. if ( handle != mHandles.end() )
  562. {
  563. handle->value->reinit( desc, loc, sampler );
  564. }
  565. else
  566. {
  567. mHandles[desc.name] = new GFXGLShaderConstHandle( this, desc, loc, sampler );
  568. }
  569. }
  570. // Loop through handles once more to set their offset and calculate our
  571. // constBuffer size.
  572. if ( mConstBuffer )
  573. delete[] mConstBuffer;
  574. mConstBufferSize = 0;
  575. for ( HandleMap::Iterator iter = mHandles.begin(); iter != mHandles.end(); ++iter )
  576. {
  577. GFXGLShaderConstHandle* handle = iter->value;
  578. if ( handle->isValid() )
  579. {
  580. mValidHandles.push_back(handle);
  581. handle->mOffset = mConstBufferSize;
  582. mConstBufferSize += handle->getSize();
  583. }
  584. }
  585. mConstBuffer = new U8[mConstBufferSize];
  586. dMemset(mConstBuffer, 0, mConstBufferSize);
  587. // Set our program so uniforms are assigned properly.
  588. glUseProgram(mProgram);
  589. // Iterate through uniforms to set sampler numbers.
  590. for (HandleMap::Iterator iter = mHandles.begin(); iter != mHandles.end(); ++iter)
  591. {
  592. GFXGLShaderConstHandle* handle = iter->value;
  593. if(handle->isValid() && (handle->getType() == GFXSCT_Sampler || handle->getType() == GFXSCT_SamplerCube))
  594. {
  595. // Set sampler number on our program.
  596. glUniform1i(handle->mLocation, handle->mSamplerNum);
  597. // Set sampler in constant buffer so it does not get unset later.
  598. dMemcpy(mConstBuffer + handle->mOffset, &handle->mSamplerNum, handle->getSize());
  599. }
  600. }
  601. glUseProgram(0);
  602. //instancing
  603. if (!mInstancingFormat)
  604. return;
  605. U32 offset = 0;
  606. for ( U32 i=0; i < mInstancingFormat->getElementCount(); i++ )
  607. {
  608. const GFXVertexElement &element = mInstancingFormat->getElement( i );
  609. String constName = String::ToString( "$%s", element.getSemantic().c_str() );
  610. HandleMap::Iterator handle = mHandles.find(constName);
  611. if ( handle != mHandles.end() )
  612. {
  613. AssertFatal(0, "");
  614. }
  615. else
  616. {
  617. GFXShaderConstDesc desc;
  618. desc.name = constName;
  619. desc.arraySize = 1;
  620. switch(element.getType())
  621. {
  622. case GFXDeclType_Float4:
  623. desc.constType = GFXSCT_Float4;
  624. break;
  625. default:
  626. desc.constType = GFXSCT_Float;
  627. break;
  628. }
  629. GFXGLShaderConstHandle *h = new GFXGLShaderConstHandle( this, desc, -1, -1 );
  630. h->mInstancingConstant = true;
  631. h->mOffset = offset;
  632. mHandles[constName] = h;
  633. offset += element.getSizeInBytes();
  634. ++i;
  635. // If this is a matrix we will have 2 or 3 more of these
  636. // semantics with the same name after it.
  637. for ( ; i < mInstancingFormat->getElementCount(); i++ )
  638. {
  639. const GFXVertexElement &nextElement = mInstancingFormat->getElement( i );
  640. if ( nextElement.getSemantic() != element.getSemantic() )
  641. {
  642. i--;
  643. break;
  644. }
  645. ++desc.arraySize;
  646. if(desc.arraySize == 4 && desc.constType == GFXSCT_Float4)
  647. {
  648. desc.arraySize = 1;
  649. desc.constType = GFXSCT_Float4x4;
  650. }
  651. offset += nextElement.getSizeInBytes();
  652. }
  653. }
  654. }
  655. }
  656. GFXShaderConstHandle* GFXGLShader::getShaderConstHandle(const String& name)
  657. {
  658. HandleMap::Iterator i = mHandles.find(name);
  659. if(i != mHandles.end())
  660. return i->value;
  661. else
  662. {
  663. GFXGLShaderConstHandle* handle = new GFXGLShaderConstHandle( this );
  664. mHandles[ name ] = handle;
  665. return handle;
  666. }
  667. }
  668. GFXShaderConstHandle* GFXGLShader::findShaderConstHandle(const String& name)
  669. {
  670. HandleMap::Iterator i = mHandles.find(name);
  671. if(i != mHandles.end())
  672. return i->value;
  673. else
  674. {
  675. return NULL;
  676. }
  677. }
  678. void GFXGLShader::setConstantsFromBuffer(GFXGLShaderConstBuffer* buffer)
  679. {
  680. for(Vector<GFXGLShaderConstHandle*>::iterator i = mValidHandles.begin(); i != mValidHandles.end(); ++i)
  681. {
  682. GFXGLShaderConstHandle* handle = *i;
  683. AssertFatal(handle, "GFXGLShader::setConstantsFromBuffer - Null handle");
  684. if(handle->mInstancingConstant)
  685. continue;
  686. // Don't set if the value has not be changed.
  687. if(dMemcmp(mConstBuffer + handle->mOffset, buffer->mBuffer + handle->mOffset, handle->getSize()) == 0)
  688. continue;
  689. // Copy new value into our const buffer and set in GL.
  690. dMemcpy(mConstBuffer + handle->mOffset, buffer->mBuffer + handle->mOffset, handle->getSize());
  691. switch(handle->mDesc.constType)
  692. {
  693. case GFXSCT_Float:
  694. glUniform1fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
  695. break;
  696. case GFXSCT_Float2:
  697. glUniform2fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
  698. break;
  699. case GFXSCT_Float3:
  700. glUniform3fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
  701. break;
  702. case GFXSCT_Float4:
  703. glUniform4fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
  704. break;
  705. case GFXSCT_Int:
  706. case GFXSCT_Sampler:
  707. case GFXSCT_SamplerCube:
  708. glUniform1iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
  709. break;
  710. case GFXSCT_Int2:
  711. glUniform2iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
  712. break;
  713. case GFXSCT_Int3:
  714. glUniform3iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
  715. break;
  716. case GFXSCT_Int4:
  717. glUniform4iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
  718. break;
  719. case GFXSCT_Float2x2:
  720. glUniformMatrix2fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
  721. break;
  722. case GFXSCT_Float3x3:
  723. glUniformMatrix3fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
  724. break;
  725. case GFXSCT_Float4x3:
  726. // NOTE: To save a transpose here we could store the matrix transposed (i.e. column major) in the constant buffer.
  727. // See _mesa_uniform_matrix in the mesa source for the correct transpose algorithm for a 4x3 matrix.
  728. glUniformMatrix4x3fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
  729. break;
  730. case GFXSCT_Float4x4:
  731. glUniformMatrix4fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
  732. break;
  733. default:
  734. AssertFatal(0,"");
  735. break;
  736. }
  737. }
  738. }
  739. GFXShaderConstBufferRef GFXGLShader::allocConstBuffer()
  740. {
  741. GFXGLShaderConstBuffer* buffer = new GFXGLShaderConstBuffer(this, mConstBufferSize, mConstBuffer);
  742. buffer->registerResourceWithDevice(getOwningDevice());
  743. mActiveBuffers.push_back( buffer );
  744. return buffer;
  745. }
  746. void GFXGLShader::useProgram()
  747. {
  748. glUseProgram(mProgram);
  749. }
  750. void GFXGLShader::zombify()
  751. {
  752. clearShaders();
  753. dMemset(mConstBuffer, 0, mConstBufferSize);
  754. }
  755. char* GFXGLShader::_handleIncludes( const Torque::Path& path, FileStream *s )
  756. {
  757. // TODO: The #line pragma on GLSL takes something called a
  758. // "source-string-number" which it then never explains.
  759. //
  760. // Until i resolve this mystery i disabled this.
  761. //
  762. //String linePragma = String::ToString( "#line 1 \r\n");
  763. //U32 linePragmaLen = linePragma.length();
  764. U32 shaderLen = s->getStreamSize();
  765. char* buffer = (char*)dMalloc(shaderLen + 1);
  766. //dStrncpy( buffer, linePragma.c_str(), linePragmaLen );
  767. s->read(shaderLen, buffer);
  768. buffer[shaderLen] = 0;
  769. char* p = dStrstr(buffer, "#include");
  770. while(p)
  771. {
  772. char* q = p;
  773. p += 8;
  774. if(dIsspace(*p))
  775. {
  776. U32 n = 0;
  777. while(dIsspace(*p)) ++p;
  778. AssertFatal(*p == '"', "Bad #include directive");
  779. ++p;
  780. static char includeFile[256];
  781. while(*p != '"')
  782. {
  783. AssertFatal(*p != 0, "Bad #include directive");
  784. includeFile[n++] = *p++;
  785. AssertFatal(n < sizeof(includeFile), "#include directive too long");
  786. }
  787. ++p;
  788. includeFile[n] = 0;
  789. // First try it as a local file.
  790. Torque::Path includePath = Torque::Path::Join(path.getPath(), '/', includeFile);
  791. includePath = Torque::Path::CompressPath(includePath);
  792. FileStream includeStream;
  793. if ( !includeStream.open( includePath, Torque::FS::File::Read ) )
  794. {
  795. // Try again assuming the path is absolute
  796. // and/or relative.
  797. includePath = String( includeFile );
  798. includePath = Torque::Path::CompressPath(includePath);
  799. if ( !includeStream.open( includePath, Torque::FS::File::Read ) )
  800. {
  801. AssertISV(false, avar("failed to open include '%s'.", includePath.getFullPath().c_str()));
  802. if ( smLogErrors )
  803. Con::errorf( "GFXGLShader::_handleIncludes - Failed to open include '%s'.",
  804. includePath.getFullPath().c_str() );
  805. // Fail... don't return the buffer.
  806. dFree(buffer);
  807. return NULL;
  808. }
  809. }
  810. char* includedText = _handleIncludes(includePath, &includeStream);
  811. // If a sub-include fails... cleanup and return.
  812. if ( !includedText )
  813. {
  814. dFree(buffer);
  815. return NULL;
  816. }
  817. // TODO: Disabled till this is fixed correctly.
  818. //
  819. // Count the number of lines in the file
  820. // before the include.
  821. /*
  822. U32 includeLine = 0;
  823. {
  824. char* nl = dStrstr( buffer, "\n" );
  825. while ( nl )
  826. {
  827. includeLine++;
  828. nl = dStrstr( nl, "\n" );
  829. if(nl) ++nl;
  830. }
  831. }
  832. */
  833. String manip(buffer);
  834. manip.erase(q-buffer, p-q);
  835. String sItx(includedText);
  836. // TODO: Disabled till this is fixed correctly.
  837. //
  838. // Add a new line pragma to restore the proper
  839. // file and line number after the include.
  840. //sItx += String::ToString( "\r\n#line %d \r\n", includeLine );
  841. dFree(includedText);
  842. manip.insert(q-buffer, sItx);
  843. char* manipBuf = dStrdup(manip.c_str());
  844. p = manipBuf + (q - buffer);
  845. dFree(buffer);
  846. buffer = manipBuf;
  847. }
  848. p = dStrstr(p, "#include");
  849. }
  850. return buffer;
  851. }
  852. bool GFXGLShader::_loadShaderFromStream( GLuint shader,
  853. const Torque::Path &path,
  854. FileStream *s,
  855. const Vector<GFXShaderMacro> &macros )
  856. {
  857. Vector<char*> buffers;
  858. Vector<U32> lengths;
  859. // The GLSL version declaration must go first!
  860. const char *versionDecl = "#version 150\r\n";
  861. buffers.push_back( dStrdup( versionDecl ) );
  862. lengths.push_back( dStrlen( versionDecl ) );
  863. if(GFXGL->mCapabilities.shaderModel5)
  864. {
  865. const char *extension = "#extension GL_ARB_gpu_shader5 : enable\r\n";
  866. buffers.push_back( dStrdup( extension ) );
  867. lengths.push_back( dStrlen( extension ) );
  868. }
  869. const char *newLine = "\r\n";
  870. buffers.push_back( dStrdup( newLine ) );
  871. lengths.push_back( dStrlen( newLine ) );
  872. // Now add all the macros.
  873. for( U32 i = 0; i < macros.size(); i++ )
  874. {
  875. if(macros[i].name.isEmpty()) // TODO OPENGL
  876. continue;
  877. String define = String::ToString( "#define %s %s\n", macros[i].name.c_str(), macros[i].value.c_str() );
  878. buffers.push_back( dStrdup( define.c_str() ) );
  879. lengths.push_back( define.length() );
  880. }
  881. // Now finally add the shader source.
  882. U32 shaderLen = s->getStreamSize();
  883. char *buffer = _handleIncludes(path, s);
  884. if ( !buffer )
  885. return false;
  886. buffers.push_back(buffer);
  887. lengths.push_back(shaderLen);
  888. glShaderSource(shader, buffers.size(), (const GLchar**)const_cast<const char**>(buffers.address()), NULL);
  889. #if defined(TORQUE_DEBUG) && defined(TORQUE_DEBUG_GFX)
  890. FileStream stream;
  891. if ( !stream.open( path.getFullPath()+"_DEBUG", Torque::FS::File::Write ) )
  892. {
  893. AssertISV(false, avar("GFXGLShader::initShader - failed to write debug shader '%s'.", path.getFullPath().c_str()));
  894. }
  895. for(int i = 0; i < buffers.size(); ++i)
  896. stream.writeText(buffers[i]);
  897. #endif
  898. // Cleanup the shader source buffer.
  899. for ( U32 i=0; i < buffers.size(); i++ )
  900. dFree( buffers[i] );
  901. glCompileShader(shader);
  902. return true;
  903. }
  904. bool GFXGLShader::initShader( const Torque::Path &file,
  905. bool isVertex,
  906. const Vector<GFXShaderMacro> &macros )
  907. {
  908. PROFILE_SCOPE(GFXGLShader_CompileShader);
  909. GLuint activeShader = glCreateShader(isVertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
  910. if(isVertex)
  911. mVertexShader = activeShader;
  912. else
  913. mPixelShader = activeShader;
  914. glAttachShader(mProgram, activeShader);
  915. // Ok it's not in the shader gen manager, so ask Torque for it
  916. FileStream stream;
  917. if ( !stream.open( file, Torque::FS::File::Read ) )
  918. {
  919. AssertISV(false, avar("GFXGLShader::initShader - failed to open shader '%s'.", file.getFullPath().c_str()));
  920. if ( smLogErrors )
  921. Con::errorf( "GFXGLShader::initShader - Failed to open shader file '%s'.",
  922. file.getFullPath().c_str() );
  923. return false;
  924. }
  925. if ( !_loadShaderFromStream( activeShader, file, &stream, macros ) )
  926. return false;
  927. GLint compile;
  928. glGetShaderiv(activeShader, GL_COMPILE_STATUS, &compile);
  929. // Dump the info log to the console
  930. U32 logLength = 0;
  931. glGetShaderiv(activeShader, GL_INFO_LOG_LENGTH, (GLint*)&logLength);
  932. GLint compileStatus = GL_TRUE;
  933. if ( logLength )
  934. {
  935. FrameAllocatorMarker fam;
  936. char* log = (char*)fam.alloc(logLength);
  937. glGetShaderInfoLog(activeShader, logLength, NULL, log);
  938. // Always print errors
  939. glGetShaderiv( activeShader, GL_COMPILE_STATUS, &compileStatus );
  940. if ( compileStatus == GL_FALSE )
  941. {
  942. if ( smLogErrors )
  943. {
  944. Con::errorf( "GFXGLShader::initShader - Error compiling shader!" );
  945. Con::errorf( "Program %s: %s", file.getFullPath().c_str(), log );
  946. }
  947. }
  948. else if ( smLogWarnings )
  949. Con::warnf( "Program %s: %s", file.getFullPath().c_str(), log );
  950. }
  951. return compileStatus != GL_FALSE;
  952. }
  953. /// Returns our list of shader constants, the material can get this and just set the constants it knows about
  954. const Vector<GFXShaderConstDesc>& GFXGLShader::getShaderConstDesc() const
  955. {
  956. PROFILE_SCOPE(GFXGLShader_GetShaderConstants);
  957. return mConstants;
  958. }
  959. /// Returns the alignment value for constType
  960. U32 GFXGLShader::getAlignmentValue(const GFXShaderConstType constType) const
  961. {
  962. // Alignment is the same thing as size for us.
  963. return shaderConstTypeSize(constType);
  964. }
  965. const String GFXGLShader::describeSelf() const
  966. {
  967. String ret;
  968. ret = String::ToString(" Program: %i", mProgram);
  969. ret += String::ToString(" Vertex Path: %s", mVertexFile.getFullPath().c_str());
  970. ret += String::ToString(" Pixel Path: %s", mPixelFile.getFullPath().c_str());
  971. return ret;
  972. }