TracyFrameCapture.java
com.mojang.blaze3d.TracyFrameCapture
信息
- 全限定名:com.mojang.blaze3d.TracyFrameCapture
- 类型:public class
- 包:com.mojang.blaze3d
- 源码路径:src/main/java/com/mojang/blaze3d/TracyFrameCapture.java
- 起始行号:L20
- 实现:AutoCloseable
- 职责:
TODO
字段/常量
-
MAX_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
MAX_HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
BYTES_PER_PIXEL- 类型:
long - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
targetWidth- 类型:
int - 修饰符:
private - 源码定位:
L24 - 说明:
TODO
- 类型:
-
targetHeight- 类型:
int - 修饰符:
private - 源码定位:
L25 - 说明:
TODO
- 类型:
-
width- 类型:
int - 修饰符:
private - 源码定位:
L26 - 说明:
TODO
- 类型:
-
height- 类型:
int - 修饰符:
private - 源码定位:
L27 - 说明:
TODO
- 类型:
-
frameBuffer- 类型:
GpuTexture - 修饰符:
private - 源码定位:
L28 - 说明:
TODO
- 类型:
-
frameBufferView- 类型:
GpuTextureView - 修饰符:
private - 源码定位:
L29 - 说明:
TODO
- 类型:
-
pixelbuffer- 类型:
GpuBuffer - 修饰符:
private - 源码定位:
L30 - 说明:
TODO
- 类型:
-
lastCaptureDelay- 类型:
int - 修饰符:
private - 源码定位:
L31 - 说明:
TODO
- 类型:
-
capturedThisFrame- 类型:
boolean - 修饰符:
private - 源码定位:
L32 - 说明:
TODO
- 类型:
-
status- 类型:
TracyFrameCapture.Status - 修饰符:
private - 源码定位:
L33 - 说明:
TODO
- 类型:
内部类/嵌套类型
com.mojang.blaze3d.TracyFrameCapture.Status- 类型:
enum - 修饰符:
static - 源码定位:
L120 - 说明:
TODO
- 类型:
构造器
public TracyFrameCapture() @ L35
- 构造器名:TracyFrameCapture
- 源码定位:L35
- 修饰符:public
参数:
- 无
说明:
TODO
方法
下面的方法块按源码顺序生成。
private void resize(int width, int height) @ L44
- 方法名:resize
- 源码定位:L44
- 返回类型:void
- 修饰符:private
参数:
- width: int
- height: int
说明:
TODO
public void capture(RenderTarget captureTarget) @ L71
- 方法名:capture
- 源码定位:L71
- 返回类型:void
- 修饰符:public
参数:
- captureTarget: RenderTarget
说明:
TODO
public void upload() @ L96
- 方法名:upload
- 源码定位:L96
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void endFrame() @ L106
- 方法名:endFrame
- 源码定位:L106
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void close() @ L112
- 方法名:close
- 源码定位:L112
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class TracyFrameCapture implements AutoCloseable {
private static final int MAX_WIDTH = 320;
private static final int MAX_HEIGHT = 180;
private static final long BYTES_PER_PIXEL = 4L;
private int targetWidth;
private int targetHeight;
private int width;
private int height;
private GpuTexture frameBuffer;
private GpuTextureView frameBufferView;
private GpuBuffer pixelbuffer;
private int lastCaptureDelay;
private boolean capturedThisFrame;
private TracyFrameCapture.Status status = TracyFrameCapture.Status.WAITING_FOR_CAPTURE;
public TracyFrameCapture() {
this.width = 320;
this.height = 180;
GpuDevice device = RenderSystem.getDevice();
this.frameBuffer = device.createTexture("Tracy Frame Capture", 10, TextureFormat.RGBA8, this.width, this.height, 1, 1);
this.frameBufferView = device.createTextureView(this.frameBuffer);
this.pixelbuffer = device.createBuffer(() -> "Tracy Frame Capture buffer", 9, this.width * this.height * 4L);
}
private void resize(int width, int height) {
float aspectRatio = (float)width / height;
if (width > 320) {
width = 320;
height = (int)(320.0F / aspectRatio);
}
if (height > 180) {
width = (int)(180.0F * aspectRatio);
height = 180;
}
width = width / 4 * 4;
height = height / 4 * 4;
if (this.width != width || this.height != height) {
this.width = width;
this.height = height;
GpuDevice device = RenderSystem.getDevice();
this.frameBuffer.close();
this.frameBuffer = device.createTexture("Tracy Frame Capture", 10, TextureFormat.RGBA8, width, height, 1, 1);
this.frameBufferView.close();
this.frameBufferView = device.createTextureView(this.frameBuffer);
this.pixelbuffer.close();
this.pixelbuffer = device.createBuffer(() -> "Tracy Frame Capture buffer", 9, width * height * 4L);
}
}
public void capture(RenderTarget captureTarget) {
if (this.status == TracyFrameCapture.Status.WAITING_FOR_CAPTURE && !this.capturedThisFrame && captureTarget.getColorTexture() != null) {
this.capturedThisFrame = true;
if (captureTarget.width != this.targetWidth || captureTarget.height != this.targetHeight) {
this.targetWidth = captureTarget.width;
this.targetHeight = captureTarget.height;
this.resize(this.targetWidth, this.targetHeight);
}
this.status = TracyFrameCapture.Status.WAITING_FOR_COPY;
CommandEncoder commandEncoder = RenderSystem.getDevice().createCommandEncoder();
try (RenderPass renderPass = RenderSystem.getDevice()
.createCommandEncoder()
.createRenderPass(() -> "Tracy blit", this.frameBufferView, OptionalInt.empty())) {
renderPass.setPipeline(RenderPipelines.TRACY_BLIT);
renderPass.bindTexture("InSampler", captureTarget.getColorTextureView(), RenderSystem.getSamplerCache().getClampToEdge(FilterMode.LINEAR));
renderPass.draw(0, 3);
}
commandEncoder.copyTextureToBuffer(this.frameBuffer, this.pixelbuffer, 0L, () -> this.status = TracyFrameCapture.Status.WAITING_FOR_UPLOAD, 0);
this.lastCaptureDelay = 0;
}
}
public void upload() {
if (this.status == TracyFrameCapture.Status.WAITING_FOR_UPLOAD) {
this.status = TracyFrameCapture.Status.WAITING_FOR_CAPTURE;
try (GpuBuffer.MappedView view = RenderSystem.getDevice().createCommandEncoder().mapBuffer(this.pixelbuffer, true, false)) {
TracyClient.frameImage(view.data(), this.width, this.height, this.lastCaptureDelay, true);
}
}
}
public void endFrame() {
this.lastCaptureDelay++;
this.capturedThisFrame = false;
TracyClient.markFrame();
}
@Override
public void close() {
this.frameBuffer.close();
this.frameBufferView.close();
this.pixelbuffer.close();
}
@OnlyIn(Dist.CLIENT)
static enum Status {
WAITING_FOR_CAPTURE,
WAITING_FOR_COPY,
WAITING_FOR_UPLOAD;
}
}引用的其他类
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RenderSystem.getDevice(), RenderSystem.getSamplerCache()
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
字段
- 引用位置: