# OpenGLCommandList - OpenGL 特有方法 以下是 `OpenGLCommandList` 中 OpenGL 特有的底层逃逸方法。这些方法不存在于 RHI 抽象接口中,用于需要直接操作 OpenGL 状态的高级场景。 ## 顶点缓冲区(OpenGL 逃逸) ### SetVertexBuffer (GL uint) ```cpp void SetVertexBuffer(unsigned int buffer, size_t offset, size_t stride) ``` 直接使用 OpenGL buffer ID 设置顶点缓冲区。 ### SetVertexBuffers (GL uint) ```cpp void SetVertexBuffers(unsigned int startSlot, unsigned int count, const unsigned int* buffers, const size_t* offsets, const size_t* strides) ``` 批量设置顶点缓冲区。 ### SetIndexBuffer (GL uint) ```cpp void SetIndexBuffer(unsigned int buffer, unsigned int type) void SetIndexBuffer(unsigned int buffer, unsigned int type, size_t offset) ``` 直接设置索引缓冲区。 ## 顶点数组 ### BindVertexArray ```cpp void BindVertexArray(unsigned int vao) void BindVertexArray(unsigned int vao, unsigned int indexBuffer, unsigned int indexType) ``` 绑定 VAO,可同时设置索引缓冲区。 ### UseShader ```cpp void UseShader(unsigned int program) ``` 使用 shader program。 ## 视口与裁剪 ### SetViewport (int) ```cpp void SetViewport(int x, int y, int width, int height) ``` 使用整数参数设置视口。 ### SetViewport (float) ```cpp void SetViewport(float x, float y, float width, float height, float minDepth, float maxDepth) ``` 使用浮点参数设置视口。 ### SetViewports ```cpp void SetViewports(unsigned int count, const float* viewports) ``` 批量设置视口(6 个浮点值 per viewport: x, y, width, height, minDepth, maxDepth)。 ### SetScissor ```cpp void SetScissor(int x, int y, int width, int height) ``` 设置裁剪矩形。 ### SetScissorRects ```cpp void SetScissorRects(unsigned int count, const int* rects) ``` 批量设置裁剪矩形(4 个整数值 per rect: x, y, width, height)。 ### EnableScissorTest ```cpp void EnableScissorTest(bool enable) ``` 启用/禁用裁剪测试。 ## 深度测试 ### EnableDepthTest ```cpp void EnableDepthTest(bool enable) ``` 启用/禁用深度测试。 ### EnableDepthWrite ```cpp void EnableDepthWrite(bool enable) ``` 启用/禁用深度写入。 ### SetDepthFunc ```cpp void SetDepthFunc(unsigned int func) ``` 设置深度比较函数(GL_NEVER, GL_LESS, GL_EQUAL, etc.)。 ## 模板测试 ### EnableStencilTest ```cpp void EnableStencilTest(bool enable) ``` 启用/禁用模板测试。 ### SetStencilFunc ```cpp void SetStencilFunc(unsigned int func, int ref, unsigned int mask) ``` 设置模板测试函数。 ### SetStencilOp ```cpp void SetStencilOp(unsigned int fail, unsigned int zfail, unsigned int zpass) ``` 设置模板操作。 ## 混合 ### EnableBlending ```cpp void EnableBlending(bool enable) ``` 启用/禁用混合。 ### SetBlendFunc ```cpp void SetBlendFunc(unsigned int src, unsigned int dst) ``` 设置混合函数。 ### SetBlendFuncSeparate ```cpp void SetBlendFuncSeparate(unsigned int srcRGB, unsigned int dstRGB, unsigned int srcAlpha, unsigned int dstAlpha) ``` 分别设置 RGB 和 Alpha 的混合函数。 ### SetBlendEquation ```cpp void SetBlendEquation(unsigned int mode) ``` 设置混合方程。 ### SetBlendColor ```cpp void SetBlendColor(float r, float g, float b, float a) ``` 设置混合因子颜色。 ## 光栅化 ### EnableCulling ```cpp void EnableCulling(bool enable) ``` 启用/禁用面剔除。 ### SetCullFace ```cpp void SetCullFace(unsigned int face) ``` 设置剔除面(GL_FRONT, GL_BACK, GL_FRONT_AND_BACK)。 ### SetFrontFace ```cpp void SetFrontFace(unsigned int face) ``` 设置正面方向(GL_CW, GL_CCW)。 ### SetPolygonMode ```cpp void SetPolygonMode(unsigned int mode) ``` 设置多边形模式(GL_POINT, GL_LINE, GL_FILL)。 ### SetPolygonOffset ```cpp void SetPolygonOffset(float factor, float units) ``` 设置多边形偏移。 ### SetPrimitiveType ```cpp void SetPrimitiveType(PrimitiveType type) ``` 设置图元类型。 ## 绘制(OpenGL 类型) ### Draw (PrimitiveType) ```cpp void Draw(PrimitiveType type, unsigned int vertexCount, unsigned int startVertex) ``` 绘制非索引图元。 ### DrawInstanced ```cpp void DrawInstanced(PrimitiveType type, unsigned int vertexCount, unsigned int instanceCount, unsigned int startVertex, unsigned int startInstance) ``` 实例化绘制。 ### DrawIndexed (PrimitiveType) ```cpp void DrawIndexed(PrimitiveType type, unsigned int indexCount, unsigned int startIndex, int baseVertex) ``` 绘制索引图元。 ### DrawIndexedInstanced ```cpp void DrawIndexedInstanced(PrimitiveType type, unsigned int indexCount, unsigned int instanceCount, unsigned int startIndex, int baseVertex, unsigned int startInstance) ``` 实例化索引绘制。 ### DrawIndirect ```cpp void DrawIndirect(PrimitiveType type, unsigned int buffer, size_t offset, unsigned int drawCount, unsigned int stride) ``` 间接绘制。 ### DrawIndexedIndirect ```cpp void DrawIndexedIndirect(PrimitiveType type, unsigned int buffer, size_t offset, unsigned int drawCount, unsigned int stride) ``` 间接索引绘制。 ### MultiDrawArrays ```cpp void MultiDrawArrays(PrimitiveType type, const int* first, const int* count, unsigned int drawCount) ``` 多重绘制。 ### MultiDrawElements ```cpp void MultiDrawElements(PrimitiveType type, const int* count, unsigned int type_, const void* const* indices, unsigned int drawCount) ``` 多重索引绘制。 ## 计算着色器 ### DispatchIndirect ```cpp void DispatchIndirect(unsigned int buffer, size_t offset) ``` 间接分发计算着色器。 ### DispatchCompute ```cpp void DispatchCompute(unsigned int x, unsigned int y, unsigned int z, unsigned int groupX, unsigned int groupY, unsigned int groupZ) ``` 分发计算着色器(带参数)。 ## 内存屏障 ### MemoryBarrier ```cpp void MemoryBarrier(unsigned int barriers) ``` 设置内存屏障。 ### TextureBarrier ```cpp void TextureBarrier() ``` 纹理屏障。 ## 纹理绑定 ### BindTexture ```cpp void BindTexture(unsigned int target, unsigned int unit, unsigned int texture) ``` 绑定纹理到纹理单元。 ### BindTextures ```cpp void BindTextures(unsigned int first, unsigned int count, const unsigned int* textures) ``` 批量绑定纹理。 ### BindSampler ```cpp void BindSampler(unsigned int unit, unsigned int sampler) ``` 绑定采样器。 ### BindSamplers ```cpp void BindSamplers(unsigned int first, unsigned int count, const unsigned int* samplers) ``` 批量绑定采样器。 ### BindImageTexture ```cpp void BindImageTexture(unsigned int unit, unsigned int texture, int level, bool layered, int layer, unsigned int access, unsigned int format) ``` 绑定为 image texture。 ## 缓冲区绑定 ### BindBufferBase ```cpp void BindBufferBase(unsigned int target, unsigned int index, unsigned int buffer) ``` 绑定到固定 binding point。 ### BindBufferRange ```cpp void BindBufferRange(unsigned int target, unsigned int index, unsigned int buffer, size_t offset, size_t size) ``` 绑定到范围 binding point。 ## OpenGL 状态 ### Enable / Disable ```cpp void Enable(unsigned int cap) void Disable(unsigned int cap) void Enablei(unsigned int cap, unsigned int index) void Disablei(unsigned int cap, unsigned int index) ``` 启用/禁用 GL capability。 ## Uniform 设置 ### SetUniform1i / SetUniform1f ```cpp void SetUniform1i(int location, int v) void SetUniform1f(int location, float v) ``` ### SetUniform2f ```cpp void SetUniform2f(int location, float x, float y) ``` ### SetUniform3f ```cpp void SetUniform3f(int location, float x, float y, float z) ``` ### SetUniform4f ```cpp void SetUniform4f(int location, float x, float y, float z, float w) ``` ### SetUniform1fv / SetUniform2fv / SetUniform3fv / SetUniform4fv ```cpp void SetUniform1fv(int location, int count, const float* v) void SetUniform2fv(int location, int count, const float* v) void SetUniform3fv(int location, int count, const float* v) void SetUniform4fv(int location, int count, const float* v) ``` ### SetUniformMatrix4fv ```cpp void SetUniformMatrix4fv(int location, int count, bool transpose, const float* v) ``` ## Shader 程序 ### UseProgram ```cpp void UseProgram(unsigned int program) ``` 使用 program。 ### BindFragDataLocation ```cpp void BindFragDataLocation(unsigned int program, unsigned int colorNumber, const char* name) void BindFragDataLocationIndexed(unsigned int program, unsigned int colorNumber, unsigned int index, const char* name) ``` 设置颜色输出绑定。 ## 查询 ### BeginQuery / EndQuery ```cpp void BeginQuery(unsigned int target, unsigned int id) void EndQuery(unsigned int target) ``` 开始/结束查询。 ### GetQueryObjectiv / GetQueryObjectuiv ```cpp void GetQueryObjectiv(unsigned int id, unsigned int pname, int* params) void GetQueryObjectuiv(unsigned int id, unsigned int pname, unsigned int* params) ``` 获取查询结果。 ## Framebuffer 操作 ### ReadPixels ```cpp void ReadPixels(int x, int y, int width, int height, unsigned int format, unsigned int type, void* data) ``` 读取像素。 ### BlitFramebuffer ```cpp void BlitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, unsigned int mask, unsigned int filter) ``` Blit 帧缓冲区。 ### CopyImageSubData ```cpp void CopyImageSubData(unsigned int srcName, unsigned int srcTarget, int srcLevel, int srcX, int srcY, int srcZ, unsigned int dstName, unsigned int dstTarget, int dstLevel, int dstX, int dstY, int dstZ, int width, int height, int depth) ``` 复制图像子数据。 ### InvalidateFramebuffer ```cpp void InvalidateFramebuffer(unsigned int target, unsigned int count, const unsigned int* attachments) void InvalidateSubFramebuffer(unsigned int target, unsigned int count, const unsigned int* attachments, int x, int y, int width, int height) ``` 使帧缓冲区失效。 ## 调试 ### PushDebugGroup / PopDebugGroup ```cpp void PushDebugGroup(unsigned int source, unsigned int id, int length, const char* message) void PopDebugGroup() ``` 推送/弹出调试组。