Material.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. //========================================================================
  3. // File: Material.h - stores texture and material information for D3D9 and D3D11
  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 Material - Chapter 14, page 485
  43. #include "Geometry.h"
  44. #include "../ResourceCache/ResCache.h"
  45. #include <GL/glew.h>
  46. class Material
  47. {
  48. private:
  49. Color m_Ambient;
  50. Color m_Diffuse;
  51. Color m_Specular;
  52. Color m_Emissive;
  53. float m_Power;
  54. public:
  55. Material();
  56. void SetAmbient(const Color &color);
  57. const Color GetAmbient() { return m_Ambient; }
  58. void SetDiffuse(const Color &color);
  59. const Color GetDiffuse() { return m_Diffuse; }
  60. void SetSpecular(const Color &color, const float power);
  61. void GetSpecular(Color &_color, float &_power)
  62. { _color = m_Specular; _power = m_Power; }
  63. void SetEmissive(const Color &color);
  64. const Color GetEmissive() { return m_Emissive; }
  65. void SetAlpha(const float alpha);
  66. bool HasAlpha() const { return GetAlpha() != fOPAQUE; }
  67. float GetAlpha() const { return m_Diffuse.a; }
  68. void D3Use9();
  69. };
  70. class OpenGLTextureResourceExtraData : public IResourceExtraData
  71. {
  72. friend class TextureResourceLoader;
  73. public:
  74. OpenGLTextureResourceExtraData();
  75. virtual ~OpenGLTextureResourceExtraData();
  76. virtual std::string VToString() { return "OpenGLTextureResourceExtraData"; }
  77. GLuint GetTextureId() { return m_texture_id; }
  78. protected:
  79. GLuint m_texture_id;
  80. };
  81. //
  82. // class TextureResourceLoader - Chapter 14, page 492
  83. //
  84. class TextureResourceLoader : public IResourceLoader
  85. {
  86. virtual bool VUseRawFile() { return false; }
  87. virtual bool VDiscardRawBufferAfterLoad() { return true; }
  88. virtual unsigned int VGetLoadedResourceSize(char *rawBuffer, unsigned int rawSize);
  89. virtual bool VLoadResource(char *rawBuffer, unsigned int rawSize, std::shared_ptr<ResHandle> handle);
  90. };