mirror of https://github.com/auygun/kaliber.git
Add support for scissor
This commit is contained in:
parent
14b2d22fbd
commit
2bafd5dbd7
|
@ -58,6 +58,17 @@ int RendererOpenGL::GetScreenHeight() const {
|
|||
return screen_height_;
|
||||
}
|
||||
|
||||
void RendererOpenGL::SetScissor(int x, int y, int width, int height) {
|
||||
DCHECK(x >= 0 && y >= 0 && width >= 0 && height >= 0);
|
||||
DCHECK(x + width <= GetScreenWidth() && y + height <= GetScreenHeight());
|
||||
glScissor(x, screen_height_ - y - height, width, height);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
void RendererOpenGL::ResetScissor() {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
uint64_t RendererOpenGL::CreateGeometry(std::unique_ptr<Mesh> mesh) {
|
||||
// Verify that we have a valid layout and get the total byte size per vertex.
|
||||
GLuint vertex_size = mesh->GetVertexSize();
|
||||
|
@ -417,6 +428,10 @@ void RendererOpenGL::SetUniform(uint64_t resource_id,
|
|||
glUniform1i(index, val);
|
||||
}
|
||||
|
||||
void RendererOpenGL::PrepareForDrawing() {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
void RendererOpenGL::ContextLost() {
|
||||
LOG(0) << "Context lost.";
|
||||
|
||||
|
|
|
@ -31,6 +31,9 @@ class RendererOpenGL final : public Renderer {
|
|||
int GetScreenWidth() const final;
|
||||
int GetScreenHeight() const final;
|
||||
|
||||
void SetScissor(int x, int y, int width, int height) final;
|
||||
void ResetScissor() final;
|
||||
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
|
||||
void DestroyGeometry(uint64_t resource_id) final;
|
||||
void Draw(uint64_t resource_id,
|
||||
|
@ -67,7 +70,7 @@ class RendererOpenGL final : public Renderer {
|
|||
void SetUniform(uint64_t resource_id, const std::string& name, int val) final;
|
||||
void UploadUniforms(uint64_t resource_id) final {}
|
||||
|
||||
void PrepareForDrawing() final {}
|
||||
void PrepareForDrawing() final;
|
||||
void Present() final;
|
||||
|
||||
size_t GetAndResetFPS() final;
|
||||
|
|
|
@ -38,6 +38,9 @@ class Renderer {
|
|||
virtual int GetScreenWidth() const = 0;
|
||||
virtual int GetScreenHeight() const = 0;
|
||||
|
||||
virtual void SetScissor(int x, int y, int width, int height) = 0;
|
||||
virtual void ResetScissor() = 0;
|
||||
|
||||
virtual uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) = 0;
|
||||
virtual void DestroyGeometry(uint64_t resource_id) = 0;
|
||||
virtual void Draw(uint64_t resource_id,
|
||||
|
|
|
@ -390,6 +390,27 @@ int RendererVulkan::GetScreenHeight() const {
|
|||
return context_.GetWindowHeight();
|
||||
}
|
||||
|
||||
void RendererVulkan::SetScissor(int x, int y, int width, int height) {
|
||||
DCHECK(x >= 0 && y >= 0 && width >= 0 && height >= 0);
|
||||
DCHECK(x + width <= GetScreenWidth() && y + height <= GetScreenHeight());
|
||||
|
||||
VkRect2D scissor;
|
||||
scissor.offset.x = x;
|
||||
scissor.offset.y = y;
|
||||
scissor.extent.width = width;
|
||||
scissor.extent.height = height;
|
||||
vkCmdSetScissor(frames_[current_frame_].draw_command_buffer, 0, 1, &scissor);
|
||||
}
|
||||
|
||||
void RendererVulkan::ResetScissor() {
|
||||
VkRect2D scissor;
|
||||
scissor.offset.x = 0;
|
||||
scissor.offset.y = 0;
|
||||
scissor.extent.width = context_.GetWindowWidth();
|
||||
scissor.extent.height = context_.GetWindowHeight();
|
||||
vkCmdSetScissor(frames_[current_frame_].draw_command_buffer, 0, 1, &scissor);
|
||||
}
|
||||
|
||||
uint64_t RendererVulkan::CreateGeometry(std::unique_ptr<Mesh> mesh) {
|
||||
auto& geometry = geometries_[++last_resource_id_] = {};
|
||||
|
||||
|
|
|
@ -33,6 +33,9 @@ class RendererVulkan final : public Renderer {
|
|||
int GetScreenWidth() const final;
|
||||
int GetScreenHeight() const final;
|
||||
|
||||
void SetScissor(int x, int y, int width, int height) final;
|
||||
void ResetScissor() final;
|
||||
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
|
||||
void DestroyGeometry(uint64_t resource_id) final;
|
||||
void Draw(uint64_t resource_id,
|
||||
|
|
Loading…
Reference in New Issue