-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FFMpeg rendering, Initial Pattern Creation & tests
FFMpeg rendering will now be done by piping every frame into a subprocess. There seems, however, to be some error with the subprocess stdin buffer being filled and it hanging resulting in me having to flush it, close the process and start a new one. A bunch of movies are created and then concatenated at the end. This is still better than a data.txt which easily goes above 100s if gigabytes in size, but not still not nice. Bug in osproc? Inside drawing.nim there has been some initial work on pattern creation. Patterns ends the current frame and saves the pixels written by nanovg. It then clears a portion of the screen, draws a pattern, creates an Image and a Pain from those pixels, resets the screen to its original state and returns the Paint/Pattern. Simple patterns are cached. Initial unittests have been setup. Workflows works out fo the box? Probs not...
- Loading branch information
Showing
13 changed files
with
513 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Run nimble test | ||
|
||
on: push | ||
|
||
jobs: | ||
nimble-test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
nim: [ '1.4.0', 'stable', 'devel' ] | ||
name: Nimble test with nim version ${{ matrix.nim }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup nim | ||
uses: jiro4989/setup-nim-action@v1 | ||
with: | ||
nim-version: ${{ matrix.nim }} | ||
|
||
- run: nimble test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
file 'D:\Documents\Coding\GitHub\nanim\examples\renders\parts\scene_0.mp4' | ||
file 'D:\Documents\Coding\GitHub\nanim\examples\renders\parts\scene_242.mp4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
|
||
import | ||
nanovg, | ||
opengl, | ||
glm | ||
|
||
|
||
proc clearWithColor*(color: Color = rgba(0, 0, 0, 0)) = | ||
glClearColor(color.r, color.g, color.b, color.a) | ||
glClear(GL_COLOR_BUFFER_BIT or | ||
GL_DEPTH_BUFFER_BIT or | ||
GL_STENCIL_BUFFER_BIT) | ||
|
||
|
||
proc drawPointsWithTension*(context: NVGContext, points: seq[Vec], tension: float = 0.5) = | ||
if len(points) < 2: return | ||
|
||
context.moveTo(points[0].x, points[0].y) | ||
|
||
let controlScale = tension / 0.5 * 0.175 | ||
let numberOfPoints = len(points) | ||
|
||
for i in 0..high(points): | ||
let points_before = points[(i - 1 + numberOfPoints) mod numberOfPoints] | ||
let point = points[i] | ||
|
||
let pointAfter = points[(i + 1) mod numberOfPoints] | ||
let pointAfter2 = points[(i + 2) mod numberOfPoints] | ||
|
||
let p4 = pointAfter | ||
|
||
let di = vec2(pointAfter.x - points_before.x, pointAfter.y - points_before.y) | ||
let p2 = vec2(point.x + controlScale * di.x, point.y + controlScale * di.y) | ||
|
||
let diPlus1 = vec2(pointAfter2.x - points[i].x, pointAfter2.y - points[i].y) | ||
|
||
let p3 = vec2(pointAfter.x - controlScale * diPlus1.x, pointAfter.y - controlScale * diPlus1.y) | ||
|
||
context.bezierTo(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y) | ||
|
||
|
||
proc drawPointsWithRoundedCornerRadius*(context: NVGContext, points: seq[Vec], cornerRadius: float = 20) = | ||
if len(points) < 2: return | ||
|
||
var p1 = points[0] | ||
|
||
let lastPoint = points[high(points)] | ||
let midPoint = vec2((p1.x + lastPoint.x) / 2.0, (p1.y + lastPoint.y) / 2.0) | ||
|
||
context.moveTo(midPoint.x, midPoint.y) | ||
for i in 1..high(points): | ||
let p2 = points[i] | ||
|
||
context.arcTo(p1.x, p1.y, p2.x, p2.y, cornerRadius) | ||
p1 = p2 | ||
|
||
context.arcTo(p1.x, p1.y, midPoint.x, midPoint.y, cornerRadius) | ||
|
||
|
||
proc defaultPattern(context: NVGContext) = | ||
context.beginPath() | ||
context.circle(5, 1440-5, 3) | ||
context.closePath() | ||
|
||
context.fillColor(rgb(20, 20, 20)) | ||
context.fill() | ||
|
||
|
||
var | ||
patternPaint: Paint | ||
hasGatheredPattern = false | ||
|
||
proc gridPattern*(context: NVGContext, patternDrawer: proc(context: NVGContext) = defaultPattern, width: cint = 10, height: cint = 10): Paint = | ||
# Impure, but worth it for the performance benefit... | ||
if hasGatheredPattern: | ||
return patternPaint | ||
|
||
let | ||
bufferSize = width*height*4 | ||
oldTransformMatrix = context.currentTransform() | ||
|
||
var | ||
oldData = alloc0(bufferSize) | ||
imageData = alloc0(bufferSize) | ||
|
||
context.endFrame() | ||
|
||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, oldData) | ||
glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, imageData) | ||
|
||
context.beginFrame(2880.cfloat, 1440.cfloat, 1) | ||
patternDrawer(context) | ||
context.endFrame() | ||
|
||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, imageData) | ||
var pixels: seq[uint8] = newSeq[uint8](bufferSize) | ||
copyMem(pixels[0].unsafeAddr, imageData, bufferSize) | ||
let image = context.createImageRGBA(width, height, {ifRepeatX, ifRepeatY, ifFlipY}, pixels) | ||
|
||
patternPaint = context.imagePattern(0, 0, width.cfloat, height.cfloat, 0, image, 1.0) | ||
hasGatheredPattern = true | ||
result = patternPaint | ||
|
||
context.beginFrame(2880.cfloat, 1440.cfloat, 1) | ||
glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, oldData) | ||
|
||
dealloc(oldData) | ||
dealloc(imageData) | ||
|
||
context.transform(oldTransformMatrix.m[0], oldTransformMatrix.m[1], oldTransformMatrix.m[2], | ||
oldTransformMatrix.m[3], oldTransformMatrix.m[4], oldTransformMatrix.m[5]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.