render.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include "atto/math.h"
  3. #if !defined(ATTO_PLATFORM)
  4. #include "atto/platform.h"
  5. #endif
  6. #if !defined(ATTO_GL_HEADERS_INCLUDED)
  7. #ifdef ATTO_PLATFORM_X11
  8. #define GL_GLEXT_PROTOTYPES 1
  9. #include <GL/glx.h>
  10. #include <GL/gl.h>
  11. #include <GL/glext.h>
  12. #define ATTO_GL_DESKTOP
  13. #endif /* ifdef ATTO_PLATFORM_X11 */
  14. #ifdef ATTO_PLATFORM_RPI
  15. #include <GLES2/gl2.h>
  16. #include <GLES2/gl2ext.h>
  17. #define ATTO_GL_ES
  18. #endif /* ifdef ATTO_PLATFORM_RPI */
  19. #ifdef ATTO_PLATFORM_WINDOWS
  20. #include "libc.h"
  21. #include <GL/gl.h>
  22. #include <glext.h>
  23. #define ATTO_GL_DESKTOP
  24. #endif /* ifdef ATTO_PLATFORM_WINDOWS */
  25. #ifdef ATTO_PLATFORM_OSX
  26. #include <OpenGL/gl3.h>
  27. #define ATTO_GL_DESKTOP
  28. #endif
  29. #endif /* if !defined(ATTO_GL_HEADERS_INCLUDED) */
  30. int renderInit();
  31. void renderClear();
  32. typedef enum {
  33. RTexFormat_RGB565
  34. } RTexFormat;
  35. typedef enum {
  36. RTexType_2D = (1 << 0),
  37. RTexType_CubePX = (1 << 1),
  38. RTexType_CubeNX = (1 << 2),
  39. RTexType_CubePY = (1 << 3),
  40. RTexType_CubeNY = (1 << 4),
  41. RTexType_CubePZ = (1 << 5),
  42. RTexType_CubeNZ = (1 << 6),
  43. } RTexType;
  44. typedef struct RTexture {
  45. int width, height;
  46. RTexFormat format;
  47. GLuint gl_name;
  48. int type_flags;
  49. } RTexture;
  50. typedef struct {
  51. RTexType type;
  52. int width, height;
  53. RTexFormat format;
  54. const void *pixels;
  55. int generate_mipmaps;
  56. } RTextureUploadParams;
  57. #define renderTextureInit(texture_ptr) do { (texture_ptr)->gl_name = (GLuint)-1; } while (0)
  58. void renderTextureUpload(RTexture *texture, RTextureUploadParams params);
  59. typedef struct {
  60. GLuint gl_name;
  61. } RBuffer;
  62. typedef enum {
  63. RBufferType_Vertex = GL_ARRAY_BUFFER,
  64. RBufferType_Index = GL_ELEMENT_ARRAY_BUFFER
  65. } RBufferType;
  66. void renderBufferCreate(RBuffer *buffer, RBufferType type, int size, const void *data);
  67. //void renderBufferUpload(RBuffer *buffer, RBufferUpload upload);
  68. struct BSPModel;
  69. void renderModelDraw(const struct AMat4f *mvp, struct AVec3f camera_position, float lmn, const struct BSPModel *model);