Renderer.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright (c) 2009-2010 jMonkeyEngine
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are
  7. * met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. package com.jme3.renderer;
  33. import com.jme3.light.LightList;
  34. import com.jme3.material.RenderState;
  35. import com.jme3.math.ColorRGBA;
  36. import com.jme3.math.Matrix4f;
  37. import com.jme3.scene.Mesh;
  38. import com.jme3.scene.VertexBuffer;
  39. import com.jme3.shader.Shader;
  40. import com.jme3.shader.Shader.ShaderSource;
  41. import com.jme3.texture.FrameBuffer;
  42. import com.jme3.texture.Image;
  43. import com.jme3.texture.Texture;
  44. import java.nio.ByteBuffer;
  45. import java.util.EnumSet;
  46. public interface Renderer {
  47. /**
  48. * @return The capabilities of the renderer.
  49. */
  50. public EnumSet<Caps> getCaps();
  51. /**
  52. * @return The statistics allow tracking of how data
  53. * per frame, such as number of objects rendered, number of triangles, etc.
  54. */
  55. public Statistics getStatistics();
  56. /**
  57. * Invalidates the current rendering state. Should be called after
  58. * the GL state was changed manually or through an external library.
  59. */
  60. public void invalidateState();
  61. /**
  62. * Clears certain channels of the current bound framebuffer.
  63. *
  64. * @param color True if to clear colors (RGBA)
  65. * @param depth True if to clear depth/z
  66. * @param stencil True if to clear stencil buffer (if available, otherwise
  67. * ignored)
  68. */
  69. public void clearBuffers(boolean color, boolean depth, boolean stencil);
  70. /**
  71. * Sets the background (aka clear) color.
  72. * @param color
  73. */
  74. public void setBackgroundColor(ColorRGBA color);
  75. /**
  76. * Applies the given renderstate, making the neccessary
  77. * GL calls so that the state is applied.
  78. */
  79. public void applyRenderState(RenderState state);
  80. /**
  81. * Set the range of the depth values for objects.
  82. * @param start
  83. * @param end
  84. */
  85. public void setDepthRange(float start, float end);
  86. /**
  87. * Called when a new frame has been rendered.
  88. */
  89. public void onFrame();
  90. /**
  91. * @param transform The world transform to use. This changes
  92. * the world matrix given in the shader.
  93. */
  94. public void setWorldMatrix(Matrix4f worldMatrix);
  95. public void setViewProjectionMatrices(Matrix4f viewMatrix, Matrix4f projMatrix);
  96. public void setViewPort(int x, int y, int width, int height);
  97. public void setClipRect(int x, int y, int width, int height);
  98. public void clearClipRect();
  99. public void setLighting(LightList lights);
  100. /**
  101. * @param shader Sets the shader to use for rendering, uploading it
  102. * if neccessary.
  103. */
  104. public void setShader(Shader shader);
  105. /**
  106. * @param shader The shader to delete. This method also deletes
  107. * the attached shader sources.
  108. */
  109. public void deleteShader(Shader shader);
  110. /**
  111. * Deletes the provided shader source.
  112. * @param source
  113. */
  114. public void deleteShaderSource(ShaderSource source);
  115. /**
  116. * Copies contents from src to dst, scaling if neccessary.
  117. */
  118. public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst);
  119. /**
  120. * Copies contents from src to dst, scaling if neccessary.
  121. * set copyDepth to false ton ly copy the color
  122. */
  123. public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth);
  124. /**
  125. * Sets the framebuffer that will be drawn to.
  126. */
  127. public void setFrameBuffer(FrameBuffer fb);
  128. /**
  129. * Reads the pixels currently stored in the specified framebuffer
  130. * into the given ByteBuffer object.
  131. * Only color pixels are transferred, the format is BGRA with 8 bits
  132. * per component. The given byte buffer should have at least
  133. * fb.getWidth() * fb.getHeight() * 4 bytes remaining.
  134. * @param fb
  135. * @param byteBuf
  136. */
  137. public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf);
  138. /**
  139. * Deletes a framebuffer and all attached renderbuffers
  140. */
  141. public void deleteFrameBuffer(FrameBuffer fb);
  142. /**
  143. * Sets the texture to use for the given texture unit.
  144. */
  145. public void setTexture(int unit, Texture tex);
  146. /**
  147. * Deletes a texture from the GPU.
  148. * @param tex
  149. */
  150. public void deleteImage(Image image);
  151. /**
  152. * Uploads a vertex buffer to the GPU.
  153. *
  154. * @param vb The vertex buffer to upload
  155. */
  156. public void updateBufferData(VertexBuffer vb);
  157. /**
  158. * Deletes a vertex buffer from the GPU.
  159. * @param vb The vertex buffer to delete
  160. */
  161. public void deleteBuffer(VertexBuffer vb);
  162. /**
  163. * Renders <code>count</code> meshes, with the geometry data supplied.
  164. * The shader which is currently set with <code>setShader</code> is
  165. * responsible for transforming the input verticies into clip space
  166. * and shading it based on the given vertex attributes.
  167. * The int variable gl_InstanceID can be used to access the current
  168. * instance of the mesh being rendered inside the vertex shader.
  169. *
  170. * @param mesh
  171. * @param count
  172. */
  173. public void renderMesh(Mesh mesh, int lod, int count);
  174. /**
  175. * Called on restart() to reset all GL objects
  176. */
  177. public void resetGLObjects();
  178. /**
  179. * Called when the display is restarted to delete
  180. * all created GL objects.
  181. */
  182. public void cleanup();
  183. /**
  184. * sets alpha to coverage
  185. * @param value
  186. */
  187. public void setAlphaToCoverage(boolean value);
  188. }