Shaders.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. //========================================================================
  3. // Shaders.h - helper classes to call GameCode4_VS.hlsl and GameCode4_PS.hlsl
  4. //
  5. // Part of the GameCode4 Application
  6. //
  7. // GameCode4 is the sample application that encapsulates much of the source code
  8. // discussed in "Game Coding Complete - 4th Edition" by Mike McShaffry and David
  9. // "Rez" Graham, published by Charles River Media.
  10. // ISBN-10: 1133776574 | ISBN-13: 978-1133776574
  11. //
  12. // If this source code has found it's way to you, and you think it has helped you
  13. // in any way, do the authors a favor and buy a new copy of the book - there are
  14. // detailed explanations in it that compliment this code well. Buy a copy at Amazon.com
  15. // by clicking here:
  16. // http://www.amazon.com/gp/product/1133776574/ref=olp_product_details?ie=UTF8&me=&seller=
  17. //
  18. // There's a companion web site at http://www.mcshaffry.com/GameCode/
  19. //
  20. // The source code is managed and maintained through Google Code:
  21. // http://code.google.com/p/gamecode4/
  22. //
  23. // (c) Copyright 2012 Michael L. McShaffry and David Graham
  24. //
  25. // This program is free software; you can redistribute it and/or
  26. // modify it under the terms of the GNU Lesser GPL v3
  27. // as published by the Free Software Foundation.
  28. //
  29. // This program is distributed in the hope that it will be useful,
  30. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  32. // http://www.gnu.org/licenses/lgpl-3.0.txt for more details.
  33. //
  34. // You should have received a copy of the GNU Lesser GPL v3
  35. // along with this program; if not, write to the Free Software
  36. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  37. //
  38. //========================================================================
  39. //========================================================================
  40. // Content References in Game Coding Complete 4th Edition
  41. //
  42. // class GameCode4_Hlsl_VertexShader - Chapter 15, page 508
  43. // class GameCode4_Hlsl_PixelShader - Chapter 15, page 515
  44. //
  45. // #include <xnamath.h>
  46. // #include "Geometry.h"
  47. #include "Material.h"
  48. #include <GL/glew.h>
  49. // Forward declarations
  50. class SceneNode;
  51. class Scene;
  52. class OpenGLShader
  53. {
  54. public:
  55. OpenGLShader();
  56. ~OpenGLShader();
  57. protected:
  58. GLuint m_shaderId;
  59. };
  60. class OpenGLShaderProgram
  61. {
  62. public:
  63. OpenGLShaderProgram();
  64. ~OpenGLShaderProgram();
  65. int OnRestore(Scene *pScene);
  66. int SetupRender(Scene *pScene, SceneNode *pNode);
  67. void EnableLights(bool enableLights) { m_enableLights = enableLights; }
  68. int SetTexture(const std::string& textureName);
  69. protected:
  70. bool m_enableLights;
  71. GLuint m_programId;
  72. GLuint m_matrixUbo;
  73. GLuint m_lightsUbo;
  74. GLuint m_materialsUbo;
  75. std::string m_textureResource;
  76. };