gfxGLShader.cpp 37 KB

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