The term "scissor" does not appear in the docs, so I assume a direct equivalent does not exist.
What you could do instead is use a shader that discards fragments outside of the scissor rectangle. The rectangle boundaries would be passed with a uniform.
Here's the second example from the gpu
module docs modified to do this. Added lines have been marked with a #
.
import bpy
import gpu
from gpu_extras.batch import batch_for_shader
vert_out = gpu.types.GPUStageInterfaceInfo("my_interface")
vert_out.smooth('VEC3', "pos")
shader_info = gpu.types.GPUShaderCreateInfo()
shader_info.push_constant('MAT4', "viewProjectionMatrix")
shader_info.push_constant('FLOAT', "brightness")
shader_info.push_constant('VEC4', "scissorRect") #
shader_info.vertex_in(0, 'VEC3', "position")
shader_info.vertex_out(vert_out)
shader_info.fragment_out(0, 'VEC4', "FragColor")
shader_info.vertex_source(
"void main()"
"{"
" pos = position;"
" gl_Position = viewProjectionMatrix * vec4(position, 1.0f);"
"}"
)
shader_info.fragment_source(
"void main()"
"{"
" if (" #
" gl_FragCoord.x < scissorRect.x || " #
" gl_FragCoord.x > scissorRect.z || " #
" gl_FragCoord.y < scissorRect.y || " #
" gl_FragCoord.y > scissorRect.w " #
" ) discard;" #
" FragColor = vec4(pos * brightness, 1.0);"
"}"
)
shader = gpu.shader.create_from_info(shader_info)
del vert_out
del shader_info
coords = [(1, 1, 1), (2, 0, 0), (-2, -1, 3)]
batch = batch_for_shader(shader, 'TRIS', {"position": coords})
def draw():
matrix = bpy.context.region_data.perspective_matrix
shader.uniform_float("viewProjectionMatrix", matrix)
shader.uniform_float("brightness", 0.5)
shader.uniform_float("scissorRect", [100, 100, 300, 300]) #
batch.draw(shader)
bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')
![Triangle being clipped to the scissor rectangle as the viewport is moved](https://cdn.statically.io/img/i.sstatic.net/w7ZMJ.gif)