Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mandelbrot-explorer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ильин Владимир Александрович
mandelbrot-explorer
Commits
e00e1adf
Commit
e00e1adf
authored
Jun 25, 2025
by
Ильин Владимир Александрович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Smarter headless mode
parent
90009436
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
54 deletions
+79
-54
Makefile
Makefile
+1
-1
mandelbrot.c
src/mandelbrot.c
+78
-53
No files found.
Makefile
View file @
e00e1adf
...
...
@@ -31,7 +31,7 @@ $(BIULDDIR)/ui.o: $(SRCDIR)/ui.c
$(CC)
-c
$(CFLAGS)
$(DEBUG_FLAGS)
$<
-o
$@
clean
:
rm
mandelbrot
$(OBJS)
rm
fast
mandelbrot
$(OBJS)
fast
:
$(SRCDIR)/mandelbrot.c $(OBJS)
$(CC)
$(CFLAGS)
$(LDLIBS)
$^
-o
$@
src/mandelbrot.c
View file @
e00e1adf
...
...
@@ -13,6 +13,7 @@
#include <SDL2/SDL.h>
#include <complex.h>
#include <omp.h>
#include <stdlib.h>
#include <x86intrin.h>
#include <argp.h>
...
...
@@ -173,63 +174,21 @@ calculate_set_omp(Array *arr, int height, int width, ViewInfo view, short unsign
}
void
update_texture
(
App
*
app
,
Array
*
arr
)
{
update_texture
(
int
width
,
int
height
,
SDL_Texture
*
texture
,
Array
*
arr
)
{
void
*
pixels
;
int
pitch
;
if
(
SDL_LockTexture
(
app
->
texture
,
NULL
,
&
pixels
,
&
pitch
)
!=
0
)
{
if
(
SDL_LockTexture
(
texture
,
NULL
,
&
pixels
,
&
pitch
)
!=
0
)
{
fprintf
(
stderr
,
"Failed to lock texture: %s
\n
"
,
SDL_GetError
());
return
;
}
memcpy
(
pixels
,
arr
->
pointer
,
app
->
win_width
*
app
->
win_
height
*
sizeof
(
Color
));
memcpy
(
pixels
,
arr
->
pointer
,
width
*
height
*
sizeof
(
Color
));
SDL_UnlockTexture
(
app
->
texture
);
}
void
save_texture
(
const
char
*
file_name
,
SDL_Renderer
*
renderer
,
SDL_Texture
*
texture
)
{
SDL_Texture
*
target
=
SDL_GetRenderTarget
(
renderer
);
SDL_SetRenderTarget
(
renderer
,
texture
);
int
width
,
height
;
SDL_QueryTexture
(
texture
,
NULL
,
NULL
,
&
width
,
&
height
);
SDL_Surface
*
surface
=
SDL_CreateRGBSurface
(
0
,
width
,
height
,
32
,
0
,
0
,
0
,
0
);
SDL_RenderReadPixels
(
renderer
,
NULL
,
surface
->
format
->
format
,
surface
->
pixels
,
surface
->
pitch
);
IMG_SavePNG
(
surface
,
file_name
);
SDL_FreeSurface
(
surface
);
SDL_SetRenderTarget
(
renderer
,
target
);
SDL_UnlockTexture
(
texture
);
}
void
render_cl
(
Array
*
arr
,
App
*
app
,
ViewInfo
view
,
short
unsigned
use_avx
,
short
unsigned
use_omp
)
{
void
(
*
calculate_set_func
)(
Array
*
arr
,
int
height
,
int
width
,
ViewInfo
view
,
short
unsigned
use_avx
);
if
(
use_omp
==
0
)
calculate_set_func
=
calculate_set
;
else
calculate_set_func
=
calculate_set_omp
;
SDL_SetRenderDrawColor
(
app
->
renderer
,
0
,
0
,
50
,
255
);
SDL_RenderClear
(
app
->
renderer
);
if
(
arr
->
size
<
app
->
win_height
*
app
->
win_width
*
(
int
)
sizeof
(
Color
)){
arr
->
pointer
=
realloc
(
arr
->
pointer
,
app
->
win_height
*
app
->
win_width
*
sizeof
(
Color
));
arr
->
size
=
app
->
win_height
*
app
->
win_width
*
sizeof
(
Color
);
}
if
(
app
->
needs_recalc
){
calculate_set_func
(
arr
,
app
->
win_height
,
app
->
win_width
,
view
,
use_avx
);
app
->
needs_recalc
=
0
;
}
update_texture
(
app
,
arr
);
SDL_RenderCopy
(
app
->
renderer
,
app
->
texture
,
NULL
,
NULL
);
}
struct
arguments
{
char
*
output_file
;
...
...
@@ -320,6 +279,69 @@ parse_opt (int key, char *arg, struct argp_state *state)
static
struct
argp
argp
=
{
options
,
parse_opt
,
NULL
,
NULL
};
void
render_cl
(
Array
*
arr
,
SDL_Texture
*
texture
,
SDL_Renderer
*
renderer
,
int
width
,
int
height
,
ViewInfo
*
view
,
short
unsigned
use_avx
,
short
unsigned
use_omp
,
short
unsigned
*
needs_recalc
)
{
void
(
*
calculate_set_func
)(
Array
*
arr
,
int
height
,
int
width
,
ViewInfo
view
,
short
unsigned
use_avx
);
calculate_set_func
=
use_omp
?
calculate_set_omp
:
calculate_set
;
SDL_SetRenderDrawColor
(
renderer
,
0
,
0
,
50
,
255
);
SDL_RenderClear
(
renderer
);
if
(
arr
->
size
<
height
*
width
*
(
int
)
sizeof
(
Color
)){
arr
->
pointer
=
realloc
(
arr
->
pointer
,
height
*
width
*
sizeof
(
Color
));
arr
->
size
=
height
*
width
*
sizeof
(
Color
);
}
if
(
needs_recalc
){
calculate_set_func
(
arr
,
height
,
width
,
*
view
,
use_avx
);
*
needs_recalc
=
0
;
}
update_texture
(
width
,
height
,
texture
,
arr
);
SDL_RenderCopy
(
renderer
,
texture
,
NULL
,
NULL
);
}
short
unsigned
render_headless
(
ViewInfo
view
,
const
char
*
filename
,
int
width
,
int
height
,
short
unsigned
use_avx
,
short
unsigned
use_omp
)
{
SDL_Surface
*
surface
=
SDL_CreateRGBSurface
(
0
,
width
,
height
,
32
,
0
,
0
,
0
,
0
);
SDL_Renderer
*
renderer
=
SDL_CreateSoftwareRenderer
(
surface
);
SDL_Texture
*
texture
=
SDL_CreateTexture
(
renderer
,
SDL_PIXELFORMAT_RGBA8888
,
SDL_TEXTUREACCESS_STREAMING
,
width
,
height
);
if
(
!
surface
)
{
fprintf
(
stderr
,
"Failed to create surface: %s
\n
"
,
SDL_GetError
());
return
1
;
}
Array
arr
=
{
malloc
(
width
*
height
*
sizeof
(
Color
)),
width
*
height
*
sizeof
(
Color
)
};
void
(
*
calculate_set_func
)(
Array
*
,
int
,
int
,
ViewInfo
,
short
unsigned
);
calculate_set_func
=
use_omp
?
calculate_set_omp
:
calculate_set
;
short
unsigned
int
plug
;
render_cl
(
&
arr
,
texture
,
renderer
,
width
,
height
,
&
view
,
use_avx
,
use_omp
,
&
plug
);
IMG_SavePNG
(
surface
,
filename
);
free
(
arr
.
pointer
);
SDL_FreeSurface
(
surface
);
return
0
;
}
int
main
(
int
argc
,
char
**
argv
)
...
...
@@ -345,6 +367,14 @@ main(int argc, char **argv)
.
zoom
=
args
.
zoom
};
if
(
args
.
output_file
)
{
render_headless
(
view
,
args
.
output_file
,
args
.
width
,
args
.
height
,
args
.
use_avx
,
args
.
use_omp
);
SDL_Quit
();
return
0
;
}
App
app
=
{
SDL_CreateWindow
(
"Mandelbrot set exploer"
,
0
,
0
,
...
...
@@ -458,14 +488,9 @@ main(int argc, char **argv)
//drawing happens here
SDL_SetRenderDrawColor
(
app
.
renderer
,
0xff
,
0xff
,
0xff
,
0xff
);
SDL_RenderClear
(
app
.
renderer
);
render_cl
(
&
screen
,
&
app
,
view
,
args
.
use_avx
,
args
.
use_omp
);
// if outputfile arg given bail after 1 frame rendered and dumb to png
if
(
args
.
output_file
!=
NULL
){
save_texture
(
args
.
output_file
,
app
.
renderer
,
app
.
texture
);
running
=
0
;
}
render_cl
(
&
screen
,
app
.
texture
,
app
.
renderer
,
app
.
win_width
,
app
.
win_height
,
&
view
,
args
.
use_avx
,
args
.
use_omp
,
&
app
.
needs_recalc
);
int
msec
=
SDL_GetTicks
()
-
frame_start
;
float
fps
=
0
;
if
(
msec
>
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment