Skip to content

Commit c1e8884

Browse files
authored
Port Renderer to C code (#3327)
1 parent 9ebab96 commit c1e8884

File tree

9 files changed

+980
-7
lines changed

9 files changed

+980
-7
lines changed

buildconfig/stubs/pygame/__init__.pyi

+15
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,26 @@ from .constants import (
109109
AUDIO_U16SYS as AUDIO_U16SYS,
110110
AUDIO_U8 as AUDIO_U8,
111111
BIG_ENDIAN as BIG_ENDIAN,
112+
BLENDFACTOR_DST_ALPHA as BLENDFACTOR_DST_ALPHA,
113+
BLENDFACTOR_DST_COLOR as BLENDFACTOR_DST_COLOR,
114+
BLENDFACTOR_ONE as BLENDFACTOR_ONE,
115+
BLENDFACTOR_ONE_MINUS_DST_ALPHA as BLENDFACTOR_ONE_MINUS_DST_ALPHA,
116+
BLENDFACTOR_ONE_MINUS_DST_COLOR as BLENDFACTOR_ONE_MINUS_DST_COLOR,
117+
BLENDFACTOR_ONE_MINUS_SRC_ALPHA as BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
118+
BLENDFACTOR_ONE_MINUS_SRC_COLOR as BLENDFACTOR_ONE_MINUS_SRC_COLOR,
119+
BLENDFACTOR_SRC_ALPHA as BLENDFACTOR_SRC_ALPHA,
120+
BLENDFACTOR_SRC_COLOR as BLENDFACTOR_SRC_COLOR,
121+
BLENDFACTOR_ZERO as BLENDFACTOR_ZERO,
112122
BLENDMODE_ADD as BLENDMODE_ADD,
113123
BLENDMODE_BLEND as BLENDMODE_BLEND,
114124
BLENDMODE_MOD as BLENDMODE_MOD,
115125
BLENDMODE_MUL as BLENDMODE_MUL,
116126
BLENDMODE_NONE as BLENDMODE_NONE,
127+
BLENDOPERATION_ADD as BLENDOPERATION_ADD,
128+
BLENDOPERATION_MAXIMUM as BLENDOPERATION_MAXIMUM,
129+
BLENDOPERATION_MINIMUM as BLENDOPERATION_MINIMUM,
130+
BLENDOPERATION_REV_SUBTRACT as BLENDOPERATION_REV_SUBTRACT,
131+
BLENDOPERATION_SUBTRACT as BLENDOPERATION_SUBTRACT,
117132
BLEND_ADD as BLEND_ADD,
118133
BLEND_ALPHA_SDL2 as BLEND_ALPHA_SDL2,
119134
BLEND_MAX as BLEND_MAX,

buildconfig/stubs/pygame/_render.pyi

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from typing import Optional, Protocol, Union, final
2+
3+
from pygame.color import Color
4+
from pygame.rect import Rect
5+
from pygame.surface import Surface
6+
from pygame.typing import ColorLike, IntPoint, Point, RectLike, SequenceLike
7+
from pygame.window import Window
8+
from typing_extensions import deprecated # added in 3.13
9+
10+
class _DrawableClass(Protocol):
11+
# Object that has the draw method that accepts area and dest arguments
12+
def draw(
13+
self, area: Optional[RectLike] = None, dest: Optional[RectLike] = None
14+
): ...
15+
16+
@final
17+
class Renderer:
18+
def __init__(
19+
self,
20+
window: Window,
21+
index: int = -1,
22+
accelerated: int = -1,
23+
vsync: bool = False,
24+
target_texture: bool = False,
25+
) -> None: ...
26+
def blit(
27+
self,
28+
source: Union["Texture", "Image", _DrawableClass],
29+
dest: Optional[RectLike] = None,
30+
area: Optional[RectLike] = None,
31+
special_flags: int = 0,
32+
) -> Rect: ...
33+
def clear(self) -> None: ...
34+
def draw_line(self, p1: Point, p2: Point) -> None: ...
35+
def draw_point(self, point: Point) -> None: ...
36+
def draw_quad(self, p1: Point, p2: Point, p3: Point, p4: Point) -> None: ...
37+
def draw_rect(self, rect: RectLike) -> None: ...
38+
def draw_triangle(self, p1: Point, p2: Point, p3: Point) -> None: ...
39+
def fill_quad(self, p1: Point, p2: Point, p3: Point, p4: Point) -> None: ...
40+
def fill_rect(self, rect: RectLike) -> None: ...
41+
def fill_triangle(self, p1: Point, p2: Point, p3: Point) -> None: ...
42+
def get_viewport(self) -> Rect: ...
43+
def present(self) -> None: ...
44+
def set_viewport(self, area: Optional[RectLike]) -> None: ...
45+
def to_surface(
46+
self, surface: Optional[Surface] = None, area: Optional[RectLike] = None
47+
) -> Surface: ...
48+
@property
49+
def draw_blend_mode(self) -> int: ...
50+
@draw_blend_mode.setter
51+
def draw_blend_mode(self, value: int) -> None: ...
52+
@property
53+
def draw_color(self) -> Color: ...
54+
@draw_color.setter
55+
def draw_color(self, value: ColorLike) -> None: ...
56+
@property
57+
def logical_size(self) -> tuple[int, int]: ...
58+
@logical_size.setter
59+
def logical_size(self, value: IntPoint) -> None: ...
60+
@property
61+
def scale(self) -> tuple[float, float]: ...
62+
@scale.setter
63+
def scale(self, value: Point) -> None: ...
64+
@property
65+
def target(self) -> "Texture": ...
66+
@target.setter
67+
def target(self, value: "Texture") -> None: ...
68+
@classmethod
69+
def compose_custom_blend_mode(
70+
cls, color_mode: SequenceLike[int], alpha_mode: SequenceLike[int]
71+
) -> int: ...
72+
@classmethod
73+
def from_window(cls, window: Window) -> Renderer: ...
74+
75+
@final
76+
class Texture:
77+
pass
78+
79+
@final
80+
class Image:
81+
pass

buildconfig/stubs/pygame/constants.pyi

+15
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,26 @@ AUDIO_U16MSB: int
3131
AUDIO_U16SYS: int
3232
AUDIO_U8: int
3333
BIG_ENDIAN: int
34+
BLENDFACTOR_DST_ALPHA: int
35+
BLENDFACTOR_DST_COLOR: int
36+
BLENDFACTOR_ONE: int
37+
BLENDFACTOR_ONE_MINUS_DST_ALPHA: int
38+
BLENDFACTOR_ONE_MINUS_DST_COLOR: int
39+
BLENDFACTOR_ONE_MINUS_SRC_ALPHA: int
40+
BLENDFACTOR_ONE_MINUS_SRC_COLOR: int
41+
BLENDFACTOR_SRC_ALPHA: int
42+
BLENDFACTOR_SRC_COLOR: int
43+
BLENDFACTOR_ZERO: int
3444
BLENDMODE_ADD: int
3545
BLENDMODE_BLEND: int
3646
BLENDMODE_MOD: int
3747
BLENDMODE_MUL: int
3848
BLENDMODE_NONE: int
49+
BLENDOPERATION_ADD: int
50+
BLENDOPERATION_MAXIMUM: int
51+
BLENDOPERATION_MINIMUM: int
52+
BLENDOPERATION_REV_SUBTRACT: int
53+
BLENDOPERATION_SUBTRACT: int
3954
BLEND_ADD: int
4055
BLEND_ALPHA_SDL2: int
4156
BLEND_MAX: int

buildconfig/stubs/pygame/locals.pyi

+15
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,26 @@ AUDIO_U16MSB: int
3131
AUDIO_U16SYS: int
3232
AUDIO_U8: int
3333
BIG_ENDIAN: int
34+
BLENDFACTOR_DST_ALPHA: int
35+
BLENDFACTOR_DST_COLOR: int
36+
BLENDFACTOR_ONE: int
37+
BLENDFACTOR_ONE_MINUS_DST_ALPHA: int
38+
BLENDFACTOR_ONE_MINUS_DST_COLOR: int
39+
BLENDFACTOR_ONE_MINUS_SRC_ALPHA: int
40+
BLENDFACTOR_ONE_MINUS_SRC_COLOR: int
41+
BLENDFACTOR_SRC_ALPHA: int
42+
BLENDFACTOR_SRC_COLOR: int
43+
BLENDFACTOR_ZERO: int
3444
BLENDMODE_ADD: int
3545
BLENDMODE_BLEND: int
3646
BLENDMODE_MOD: int
3747
BLENDMODE_MUL: int
3848
BLENDMODE_NONE: int
49+
BLENDOPERATION_ADD: int
50+
BLENDOPERATION_MAXIMUM: int
51+
BLENDOPERATION_MINIMUM: int
52+
BLENDOPERATION_REV_SUBTRACT: int
53+
BLENDOPERATION_SUBTRACT: int
3954
BLEND_ADD: int
4055
BLEND_ALPHA_SDL2: int
4156
BLEND_MAX: int

src_c/constants.c

+16
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,22 @@ MODINIT_DEFINE(constants)
161161
DEC_CONST(BLENDMODE_ADD);
162162
DEC_CONST(BLENDMODE_MOD);
163163
DEC_CONST(BLENDMODE_MUL);
164+
DEC_CONST(BLENDFACTOR_ZERO);
165+
DEC_CONST(BLENDFACTOR_ONE);
166+
DEC_CONST(BLENDFACTOR_SRC_COLOR);
167+
DEC_CONST(BLENDFACTOR_ONE_MINUS_SRC_COLOR);
168+
DEC_CONST(BLENDFACTOR_SRC_ALPHA);
169+
DEC_CONST(BLENDFACTOR_ONE_MINUS_SRC_ALPHA);
170+
DEC_CONST(BLENDFACTOR_DST_COLOR);
171+
DEC_CONST(BLENDFACTOR_ONE_MINUS_DST_COLOR);
172+
DEC_CONST(BLENDFACTOR_DST_ALPHA);
173+
DEC_CONST(BLENDFACTOR_ONE_MINUS_DST_ALPHA);
174+
DEC_CONST(BLENDOPERATION_ADD);
175+
DEC_CONST(BLENDOPERATION_SUBTRACT);
176+
DEC_CONST(BLENDOPERATION_REV_SUBTRACT);
177+
DEC_CONST(BLENDOPERATION_MINIMUM);
178+
DEC_CONST(BLENDOPERATION_MAXIMUM);
179+
164180
DEC_CONST(GL_STEREO);
165181
DEC_CONST(GL_MULTISAMPLEBUFFERS);
166182
DEC_CONST(GL_MULTISAMPLESAMPLES);

0 commit comments

Comments
 (0)