DPF OpenGL examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

591 lines
24KB

  1. //
  2. // Copyright (c) 2013 Mikko Mononen memon@inside.org
  3. //
  4. // This software is provided 'as-is', without any express or implied
  5. // warranty. In no event will the authors be held liable for any damages
  6. // arising from the use of this software.
  7. // Permission is granted to anyone to use this software for any purpose,
  8. // including commercial applications, and to alter it and redistribute it
  9. // freely, subject to the following restrictions:
  10. // 1. The origin of this software must not be misrepresented; you must not
  11. // claim that you wrote the original software. If you use this software
  12. // in a product, an acknowledgment in the product documentation would be
  13. // appreciated but is not required.
  14. // 2. Altered source versions must be plainly marked as such, and must not be
  15. // misrepresented as being the original software.
  16. // 3. This notice may not be removed or altered from any source distribution.
  17. //
  18. #ifndef NANOVG_H
  19. #define NANOVG_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #define NVG_PI 3.14159265358979323846264338327f
  24. struct NVGcontext;
  25. struct NVGcolor {
  26. union {
  27. float rgba[4];
  28. struct {
  29. float r,g,b,a;
  30. };
  31. };
  32. };
  33. struct NVGpaint {
  34. float xform[6];
  35. float extent[2];
  36. float radius;
  37. float feather;
  38. struct NVGcolor innerColor;
  39. struct NVGcolor outerColor;
  40. int image;
  41. int repeat;
  42. };
  43. enum NVGwinding {
  44. NVG_CCW = 1, // Winding for solid shapes
  45. NVG_CW = 2, // Winding for holes
  46. };
  47. enum NVGsolidity {
  48. NVG_SOLID = 1, // CCW
  49. NVG_HOLE = 2, // CW
  50. };
  51. enum NVGlineCap {
  52. NVG_BUTT,
  53. NVG_ROUND,
  54. NVG_SQUARE,
  55. NVG_BEVEL,
  56. NVG_MITER,
  57. };
  58. enum NVGpatternRepeat {
  59. NVG_REPEATX = 0x01, // Repeat image pattern in X direction
  60. NVG_REPEATY = 0x02, // Repeat image pattern in Y direction
  61. };
  62. enum NVGalign {
  63. // Horizontal align
  64. NVG_ALIGN_LEFT = 1<<0, // Default, align text horizontally to left.
  65. NVG_ALIGN_CENTER = 1<<1, // Align text horizontally to center.
  66. NVG_ALIGN_RIGHT = 1<<2, // Align text horizontally to right.
  67. // Vertical align
  68. NVG_ALIGN_TOP = 1<<3, // Align text vertically to top.
  69. NVG_ALIGN_MIDDLE = 1<<4, // Align text vertically to middle.
  70. NVG_ALIGN_BOTTOM = 1<<5, // Align text vertically to bottom.
  71. NVG_ALIGN_BASELINE = 1<<6, // Default, align text vertically to baseline.
  72. };
  73. enum NVGalpha {
  74. NVG_STRAIGHT_ALPHA,
  75. NVG_PREMULTIPLIED_ALPHA,
  76. };
  77. struct NVGglyphPosition {
  78. const char* str; // Position of the glyph in the input string.
  79. float x; // The x-coordinate of the logical glyph position.
  80. float minx, maxx; // The bounds of the glyph shape.
  81. };
  82. struct NVGtextRow {
  83. const char* start; // Pointer to the input text where the row starts.
  84. const char* end; // Pointer to the input text where the row ends (one past the last character).
  85. const char* next; // Pointer to the beginning of the next row.
  86. float width; // Logical width of the row.
  87. float minx, maxx; // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
  88. };
  89. // Begin drawing a new frame
  90. // Calls to nanovg drawing API should be wrapped in nvgBeginFrame() & nvgEndFrame()
  91. // nvgBeginFrame() defines the size of the window to render to in relation currently
  92. // set viewport (i.e. glViewport on GL backends). Device pixel ration allows to
  93. // control the rendering on Hi-DPI devices.
  94. // For example, GLFW returns two dimension for an opened window: window size and
  95. // frame buffer size. In that case you would set windowWidth/Height to the window size
  96. // devicePixelRatio to: frameBufferWidth / windowWidth.
  97. // AlphaBlend controls if drawing the shapes to the render target should be done using straight or
  98. // premultiplied alpha. If rendering directly to framebuffer you probably want to use NVG_STRAIGHT_ALPHA,
  99. // if rendering to texture which should contain transparent regions NVG_PREMULTIPLIED_ALPHA is the
  100. // right choice.
  101. void nvgBeginFrame(struct NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio, int alphaBlend);
  102. // Ends drawing flushing remaining render state.
  103. void nvgEndFrame(struct NVGcontext* ctx);
  104. //
  105. // Color utils
  106. //
  107. // Colors in NanoVG are stored as unsigned ints in ABGR format.
  108. // Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).
  109. struct NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b);
  110. // Returns a color value from red, green, blue values. Alpha will be set to 1.0f.
  111. struct NVGcolor nvgRGBf(float r, float g, float b);
  112. // Returns a color value from red, green, blue and alpha values.
  113. struct NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
  114. // Returns a color value from red, green, blue and alpha values.
  115. struct NVGcolor nvgRGBAf(float r, float g, float b, float a);
  116. // Linearly interpoaltes from color c0 to c1, and returns resulting color value.
  117. struct NVGcolor nvgLerpRGBA(struct NVGcolor c0, struct NVGcolor c1, float u);
  118. // Sets transparency of a color value.
  119. struct NVGcolor nvgTransRGBA(struct NVGcolor c0, unsigned char a);
  120. // Sets transparency of a color value.
  121. struct NVGcolor nvgTransRGBAf(struct NVGcolor c0, float a);
  122. // Returns color value specified by hue, saturation and lightness.
  123. // HSL values are all in range [0..1], alpha will be set to 255.
  124. struct NVGcolor nvgHSL(float h, float s, float l);
  125. // Returns color value specified by hue, saturation and lightness and alpha.
  126. // HSL values are all in range [0..1], alpha in range [0..255]
  127. struct NVGcolor nvgHSLA(float h, float s, float l, unsigned char a);
  128. //
  129. // State Handling
  130. //
  131. // NanoVG contains state which represents how paths will be rendered.
  132. // The state contains transform, fill and stroke styles, text and font styles,
  133. // and scissor clipping.
  134. // Pushes and saves the current render state into a state stack.
  135. // A matching nvgRestore() must be used to restore the state.
  136. void nvgSave(struct NVGcontext* ctx);
  137. // Pops and restores current render state.
  138. void nvgRestore(struct NVGcontext* ctx);
  139. // Resets current render state to default values. Does not affect the render state stack.
  140. void nvgReset(struct NVGcontext* ctx);
  141. //
  142. // Render styles
  143. //
  144. // Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern.
  145. // Solid color is simply defined as a color value, different kinds of paints can be created
  146. // using nvgLinearGradient(), nvgBoxGradient(), nvgRadialGradient() and nvgImagePattern().
  147. //
  148. // Current render style can be saved and restored using nvgSave() and nvgRestore().
  149. // Sets current stroke style to a solid color.
  150. void nvgStrokeColor(struct NVGcontext* ctx, struct NVGcolor color);
  151. // Sets current stroke style to a paint, which can be a one of the gradients or a pattern.
  152. void nvgStrokePaint(struct NVGcontext* ctx, struct NVGpaint paint);
  153. // Sets current fill cstyle to a solid color.
  154. void nvgFillColor(struct NVGcontext* ctx, struct NVGcolor color);
  155. // Sets current fill style to a paint, which can be a one of the gradients or a pattern.
  156. void nvgFillPaint(struct NVGcontext* ctx, struct NVGpaint paint);
  157. // Sets the miter limit of the stroke style.
  158. // Miter limit controls when a sharp corner is beveled.
  159. void nvgMiterLimit(struct NVGcontext* ctx, float limit);
  160. // Sets the stroke witdth of the stroke style.
  161. void nvgStrokeWidth(struct NVGcontext* ctx, float size);
  162. // Sets how the end of the line (cap) is drawn,
  163. // Can be one of: NVG_BUTT (default), NVG_ROUND, NVG_SQUARE.
  164. void nvgLineCap(struct NVGcontext* ctx, int cap);
  165. // Sets how sharp path corners are drawn.
  166. // Can be one of NVG_MITER (default), NVG_ROUND, NVG_BEVEL.
  167. void nvgLineJoin(struct NVGcontext* ctx, int join);
  168. //
  169. // Transforms
  170. //
  171. // The paths, gradients, patterns and scissor region are transformed by an transformation
  172. // matrix at the time when they are passed to the API.
  173. // The current transformation matrix is a affine matrix:
  174. // [sx kx tx]
  175. // [ky sy ty]
  176. // [ 0 0 1]
  177. // Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation.
  178. // The last row is assumed to be 0,0,1 and is not stored.
  179. //
  180. // Apart from nvgResetTransform(), each transformation function first creates
  181. // specific transformation matrix and pre-multiplies the current transformation by it.
  182. //
  183. // Current coordinate system (transformation) can be saved and restored using nvgSave() and nvgRestore().
  184. // Resets current transform to a identity matrix.
  185. void nvgResetTransform(struct NVGcontext* ctx);
  186. // Premultiplies current coordinate system by specified matrix.
  187. // The parameters are interpreted as matrix as follows:
  188. // [a c e]
  189. // [b d f]
  190. // [0 0 1]
  191. void nvgTransform(struct NVGcontext* ctx, float a, float b, float c, float d, float e, float f);
  192. // Translates current coordinate system.
  193. void nvgTranslate(struct NVGcontext* ctx, float x, float y);
  194. // Rotates current coordinate system. Angle is specifid in radians.
  195. void nvgRotate(struct NVGcontext* ctx, float angle);
  196. // Skews the current coordinate system along X axis. Angle is specifid in radians.
  197. void nvgSkewX(struct NVGcontext* ctx, float angle);
  198. // Skews the current coordinate system along Y axis. Angle is specifid in radians.
  199. void nvgSkewY(struct NVGcontext* ctx, float angle);
  200. // Scales the current coordinat system.
  201. void nvgScale(struct NVGcontext* ctx, float x, float y);
  202. // Stores the top part (a-f) of the current transformation matrix in to the specified buffer.
  203. // [a c e]
  204. // [b d f]
  205. // [0 0 1]
  206. // There should be space for 6 floats in the return buffer for the values a-f.
  207. void nvgCurrentTransform(struct NVGcontext* ctx, float* xform);
  208. // The following functions can be used to make calculations on 2x3 transformation matrices.
  209. // A 2x3 matrix is representated as float[6].
  210. // Sets the transform to identity matrix.
  211. void nvgTransformIdentity(float* dst);
  212. // Sets the transform to translation matrix matrix.
  213. void nvgTransformTranslate(float* dst, float tx, float ty);
  214. // Sets the transform to scale matrix.
  215. void nvgTransformScale(float* dst, float sx, float sy);
  216. // Sets the transform to rotate matrix. Angle is specifid in radians.
  217. void nvgTransformRotate(float* dst, float a);
  218. // Sets the transform to skew-x matrix. Angle is specifid in radians.
  219. void nvgTransformSkewX(float* dst, float a);
  220. // Sets the transform to skew-y matrix. Angle is specifid in radians.
  221. void nvgTransformSkewY(float* dst, float a);
  222. // Sets the transform to the result of multiplication of two transforms, of A = A*B.
  223. void nvgTransformMultiply(float* dst, const float* src);
  224. // Sets the transform to the result of multiplication of two transforms, of A = B*A.
  225. void nvgTransformPremultiply(float* dst, const float* src);
  226. // Sets the destination to inverse of specified transform.
  227. // Returns 1 if the inverse could be calculated, else 0.
  228. int nvgTransformInverse(float* dst, const float* src);
  229. // Transform a point by given transform.
  230. void nvgTransformPoint(float* dstx, float* dsty, const float* xform, float srcx, float srcy);
  231. // Converts degress to radians and vice versa.
  232. float nvgDegToRad(float deg);
  233. float nvgRadToDeg(float rad);
  234. //
  235. // Images
  236. //
  237. // NanoVG allows you to load jpg, png, psd, tga, pic and gif files to be used for rendering.
  238. // In addition you can upload your own image. The image loading is provided by stb_image.
  239. // Creates image by loading it from the disk from specified file name.
  240. // Returns handle to the image.
  241. int nvgCreateImage(struct NVGcontext* ctx, const char* filename);
  242. // Creates image by loading it from the specified chunk of memory.
  243. // Returns handle to the image.
  244. int nvgCreateImageMem(struct NVGcontext* ctx, unsigned char* data, int ndata);
  245. // Creates image from specified image data.
  246. // Returns handle to the image.
  247. int nvgCreateImageRGBA(struct NVGcontext* ctx, int w, int h, const unsigned char* data);
  248. // Updates image data specified by image handle.
  249. void nvgUpdateImage(struct NVGcontext* ctx, int image, const unsigned char* data);
  250. // Returns the domensions of a created image.
  251. void nvgImageSize(struct NVGcontext* ctx, int image, int* w, int* h);
  252. // Deletes created image.
  253. void nvgDeleteImage(struct NVGcontext* ctx, int image);
  254. //
  255. // Paints
  256. //
  257. // NanoVG supports four types of paints: linear gradient, box gradient, radial gradient and image pattern.
  258. // These can be used as paints for strokes and fills.
  259. // Creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates
  260. // of the linear gradient, icol specifies the start color and ocol the end color.
  261. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
  262. struct NVGpaint nvgLinearGradient(struct NVGcontext* ctx, float sx, float sy, float ex, float ey,
  263. struct NVGcolor icol, struct NVGcolor ocol);
  264. // Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering
  265. // drop shadows or hilights for boxes. Parameters (x,y) define the top-left corner of the rectangle,
  266. // (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry
  267. // the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient.
  268. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
  269. struct NVGpaint nvgBoxGradient(struct NVGcontext* ctx, float x, float y, float w, float h,
  270. float r, float f, struct NVGcolor icol, struct NVGcolor ocol);
  271. // Creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify
  272. // the inner and outer radius of the gradient, icol specifies the start color and ocol the end color.
  273. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
  274. struct NVGpaint nvgRadialGradient(struct NVGcontext* ctx, float cx, float cy, float inr, float outr,
  275. struct NVGcolor icol, struct NVGcolor ocol);
  276. // Creates and returns an image patter. Parameters (ox,oy) specify the left-top location of the image pattern,
  277. // (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render,
  278. // and repeat is combination of NVG_REPEATX and NVG_REPEATY which tells if the image should be repeated across x or y.
  279. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
  280. struct NVGpaint nvgImagePattern(struct NVGcontext* ctx, float ox, float oy, float ex, float ey,
  281. float angle, int image, int repeat);
  282. //
  283. // Scissoring
  284. //
  285. // Scissoring allows you to clip the rendering into a rectangle. This is useful for varius
  286. // user interface cases like rendering a text edit or a timeline.
  287. // Sets the current
  288. // The scissor rectangle is transformed by the current transform.
  289. void nvgScissor(struct NVGcontext* ctx, float x, float y, float w, float h);
  290. // Reset and disables scissoring.
  291. void nvgResetScissor(struct NVGcontext* ctx);
  292. //
  293. // Paths
  294. //
  295. // Drawing a new shape starts with nvgBeginPath(), it clears all the currently defined paths.
  296. // Then you define one or more paths and sub-paths which describe the shape. The are functions
  297. // to draw common shapes like rectangles and circles, and lower level step-by-step functions,
  298. // which allow to define a path curve by curve.
  299. //
  300. // NanoVG uses even-odd fill rule to draw the shapes. Solid shapes should have counter clockwise
  301. // winding and holes should have counter clockwise order. To specify winding of a path you can
  302. // call nvgPathWinding(). This is useful especially for the common shapes, which are drawn CCW.
  303. //
  304. // Finally you can fill the path using current fill style by calling nvgFill(), and stroke it
  305. // with current stroke style by calling nvgStroke().
  306. //
  307. // The curve segments and sub-paths are transformed by the current transform.
  308. // Clears the current path and sub-paths.
  309. void nvgBeginPath(struct NVGcontext* ctx);
  310. // Starts new sub-path with specified point as first point.
  311. void nvgMoveTo(struct NVGcontext* ctx, float x, float y);
  312. // Adds line segment from the last point in the path to the specified point.
  313. void nvgLineTo(struct NVGcontext* ctx, float x, float y);
  314. // Adds bezier segment from last point in the path via two control points to the specified point.
  315. void nvgBezierTo(struct NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y);
  316. // Adds an arc segment at the corner defined by the last path point, and two specified points.
  317. void nvgArcTo(struct NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius);
  318. // Closes current sub-path with a line segment.
  319. void nvgClosePath(struct NVGcontext* ctx);
  320. // Sets the current sub-path winding, see NVGwinding and NVGsolidity.
  321. void nvgPathWinding(struct NVGcontext* ctx, int dir);
  322. // Creates new arc shaped sub-path.
  323. void nvgArc(struct NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir);
  324. // Creates new rectangle shaped sub-path.
  325. void nvgRect(struct NVGcontext* ctx, float x, float y, float w, float h);
  326. // Creates new rounded rectangle shaped sub-path.
  327. void nvgRoundedRect(struct NVGcontext* ctx, float x, float y, float w, float h, float r);
  328. // Creates new ellipse shaped sub-path.
  329. void nvgEllipse(struct NVGcontext* ctx, float cx, float cy, float rx, float ry);
  330. // Creates new circle shaped sub-path.
  331. void nvgCircle(struct NVGcontext* ctx, float cx, float cy, float r);
  332. // Fills the current path with current fill style.
  333. void nvgFill(struct NVGcontext* ctx);
  334. // Fills the current path with current stroke style.
  335. void nvgStroke(struct NVGcontext* ctx);
  336. //
  337. // Text
  338. //
  339. // NanoVG allows you to load .ttf files and use the font to render text.
  340. //
  341. // The appearance of the text can be defined by setting the current text style
  342. // and by specifying the fill color. Common text and font settings such as
  343. // font size, letter spacing and text align are supported. Font blur allows you
  344. // to create simple text effects such as drop shadows.
  345. //
  346. // At render time the font face can be set based on the font handles or name.
  347. //
  348. // Font measure functions return values in local space, the calculations are
  349. // carried in the same resolution as the final rendering. This is done because
  350. // the text glyph positions are snapped to the nearest pixels sharp rendering.
  351. //
  352. // The local space means that values are not rotated or scale as per the current
  353. // transformation. For example if you set font size to 12, which would mean that
  354. // line height is 16, then regardless of the current scaling and rotation, the
  355. // returned line height is always 16. Some measures may vary because of the scaling
  356. // since aforementioned pixel snapping.
  357. //
  358. // While this may sound a little odd, the setup allows you to always render the
  359. // same way regardless of scaling. I.e. following works regardless of scaling:
  360. //
  361. // const char* txt = "Text me up.";
  362. // nvgTextBounds(vg, x,y, txt, NULL, bounds);
  363. // nvgBeginPath(vg);
  364. // nvgRoundedRect(vg, bounds[0],bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]);
  365. // nvgFill(vg);
  366. //
  367. // Note: currently only solid color fill is supported for text.
  368. // Creates font by loading it from the disk from specified file name.
  369. // Returns handle to the font.
  370. int nvgCreateFont(struct NVGcontext* ctx, const char* name, const char* filename);
  371. // Creates image by loading it from the specified memory chunk.
  372. // Returns handle to the font.
  373. int nvgCreateFontMem(struct NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData);
  374. // Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
  375. int nvgFindFont(struct NVGcontext* ctx, const char* name);
  376. // Sets the font size of current text style.
  377. void nvgFontSize(struct NVGcontext* ctx, float size);
  378. // Sets the blur of current text style.
  379. void nvgFontBlur(struct NVGcontext* ctx, float blur);
  380. // Sets the letter spacing of current text style.
  381. void nvgTextLetterSpacing(struct NVGcontext* ctx, float spacing);
  382. // Sets the proportional line height of current text style. The line height is specified as multiple of font size.
  383. void nvgTextLineHeight(struct NVGcontext* ctx, float lineHeight);
  384. // Sets the text align of current text style, see NVGaling for options.
  385. void nvgTextAlign(struct NVGcontext* ctx, int align);
  386. // Sets the font face based on specified id of current text style.
  387. void nvgFontFaceId(struct NVGcontext* ctx, int font);
  388. // Sets the font face based on specified name of current text style.
  389. void nvgFontFace(struct NVGcontext* ctx, const char* font);
  390. // Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.
  391. float nvgText(struct NVGcontext* ctx, float x, float y, const char* string, const char* end);
  392. // Draws multi-line text string at specified location wrapped at the specified width. If end is specified only the sub-string up to the end is drawn.
  393. // White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
  394. // Words longer than the max width are slit at nearest character (i.e. no hyphenation).
  395. void nvgTextBox(struct NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end);
  396. // Measures the specified text string. Parameter bounds should be a pointer to float[4],
  397. // if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
  398. // Returns the horizontal advance of the measured text (i.e. where the next character should drawn).
  399. // Measured values are returned in local coordinate space.
  400. float nvgTextBounds(struct NVGcontext* ctx, float x, float y, const char* string, const char* end, float* bounds);
  401. // Measures the specified multi-text string. Parameter bounds should be a pointer to float[4],
  402. // if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
  403. // Measured values are returned in local coordinate space.
  404. void nvgTextBoxBounds(struct NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds);
  405. // Calculates the glyph x positions of the specified text. If end is specified only the sub-string will be used.
  406. // Measured values are returned in local coordinate space.
  407. int nvgTextGlyphPositions(struct NVGcontext* ctx, float x, float y, const char* string, const char* end, struct NVGglyphPosition* positions, int maxPositions);
  408. // Returns the vertical metrics based on the current text style.
  409. // Measured values are returned in local coordinate space.
  410. void nvgTextMetrics(struct NVGcontext* ctx, float* ascender, float* descender, float* lineh);
  411. // Breaks the specified text into lines. If end is specified only the sub-string will be used.
  412. // White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
  413. // Words longer than the max width are slit at nearest character (i.e. no hyphenation).
  414. int nvgTextBreakLines(struct NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, struct NVGtextRow* rows, int maxRows);
  415. //
  416. // Internal Render API
  417. //
  418. enum NVGtexture {
  419. NVG_TEXTURE_ALPHA = 0x01,
  420. NVG_TEXTURE_RGBA = 0x02,
  421. };
  422. struct NVGscissor
  423. {
  424. float xform[6];
  425. float extent[2];
  426. };
  427. struct NVGvertex {
  428. float x,y,u,v;
  429. };
  430. struct NVGpath {
  431. int first;
  432. int count;
  433. unsigned char closed;
  434. int nbevel;
  435. struct NVGvertex* fill;
  436. int nfill;
  437. struct NVGvertex* stroke;
  438. int nstroke;
  439. int winding;
  440. int convex;
  441. };
  442. struct NVGparams {
  443. void* userPtr;
  444. int atlasWidth, atlasHeight;
  445. int edgeAntiAlias;
  446. int (*renderCreate)(void* uptr);
  447. int (*renderCreateTexture)(void* uptr, int type, int w, int h, const unsigned char* data);
  448. int (*renderDeleteTexture)(void* uptr, int image);
  449. int (*renderUpdateTexture)(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data);
  450. int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h);
  451. void (*renderViewport)(void* uptr, int width, int height, int alphaBlend);
  452. void (*renderFlush)(void* uptr, int alphaBlend);
  453. void (*renderFill)(void* uptr, struct NVGpaint* paint, struct NVGscissor* scissor, float fringe, const float* bounds, const struct NVGpath* paths, int npaths);
  454. void (*renderStroke)(void* uptr, struct NVGpaint* paint, struct NVGscissor* scissor, float fringe, float strokeWidth, const struct NVGpath* paths, int npaths);
  455. void (*renderTriangles)(void* uptr, struct NVGpaint* paint, struct NVGscissor* scissor, const struct NVGvertex* verts, int nverts);
  456. void (*renderDelete)(void* uptr);
  457. };
  458. // Contructor and destructor, called by the render back-end.
  459. struct NVGcontext* nvgCreateInternal(struct NVGparams* params);
  460. void nvgDeleteInternal(struct NVGcontext* ctx);
  461. // Debug function to dump cached path data.
  462. void nvgDebugDumpPathCache(struct NVGcontext* ctx);
  463. #define NVG_NOTUSED(v) do { (void)(1 ? (void)0 : ( (void)(v) ) ); } while(0)
  464. #ifdef __cplusplus
  465. }
  466. #endif
  467. #endif // NANOVG_H