Exercise 10 Kore::Image, Kore::Texture, threads

PicoJr
Nichts ist wie es scheint
Beiträge: 23
Registriert: 28. Okt 2017 20:25

Exercise 10 Kore::Image, Kore::Texture, threads

Beitrag von PicoJr » 11. Jan 2018 00:01

Hallo/Hello,

I have several questions regarding Exercise 10 instructions:
reload darmstadt.jpg for every box,...
What does reload mean here? I guess it does not mean reload image from disk...
...pretend that every box has a different texture
Does it mean each image should be loaded once for each cube? or rather that each image could be loaded only once while textures are instantiated/updated for each cube?
Beware, neither OpenGL nor Direct3D is thread safe - you can't just create a Texture in a second thread. But you can create a Kore::Image in another thread, access it's pixels in the main thread and put them in a Kore::Texture using lock/unlock.
I'm a bit lost here =/ https://www.reddit.com/r/ProgrammerHumo ... e_threads/

using lock/unlock: use the lock/unlock methods of the Kore::Texture class? or declare our own mutex instead?

What does access it's pixels mean here? is it image.data? Ideally I would like to write something similar to:

Code: Alles auswählen

cubeNear.getTexture().setImage(highResImage);
But sadly I could not find such method... what method should we use in order to put them (pixels) in a Kore::Texture?

So far I have managed to make textures disappear (they appear black) when close enough ^^'

Thanks for your help,

Best Regards,

PicoJr.

RobDangerous
Computerversteher
Computerversteher
Beiträge: 363
Registriert: 14. Okt 2014 17:05

Re: Exercise 10 Kore::Image, Kore::Texture, threads

Beitrag von RobDangerous » 11. Jan 2018 00:17

It does mean "reload from disk" and each image should be loaded once for each cube. lock/unlock refers to the Texture, that's what you use to put pixels in there (setImage basically becomes pointer = tex.lock(); memcpy(pointer, highResImage); tex.unlock();).

PicoJr
Nichts ist wie es scheint
Beiträge: 23
Registriert: 28. Okt 2017 20:25

Re: Exercise 10 Kore::Image, Kore::Texture, threads

Beitrag von PicoJr » 11. Jan 2018 14:49

Hello/Hallo,

Thank you for your reply =)

I now understand why .lock() returns u8*.

However I don't understand how memcpy can be used to supply a bigger image:

Code: Alles auswählen

memcpy(pointer_to_16x16_image, pointer_to_64x64_image, size_of_64x64_image)
will segfault isn't it?

The following code snippet segfaults.

Code: Alles auswählen

// cubeTex contains the lower res texture
Graphics1::Image darmstadt64 = Graphics1::Image("darmstadt64.png", true);
u8* pointer = cubeTex->lock();
memcpy(pointer, darmstadt64.data, (size_t) (darmstadt64.width * darmstadt64.height * darmstadt64.sizeOf(darmstadt64.format))); // use high res texture
cubeTex->unlock();
Even when I supply the lower res texture (that way it does not segfault), it is not displayed:

Code: Alles auswählen

// cubeTex contains the higher res texture
Graphics1::Image darmstadt16 = Graphics1::Image("darmstadt16.png", true);
u8* pointer = cubeTex->lock();
memcpy(pointer, darmstadt16.data, (size_t) (darmstadt16.width * darmstadt16.height * darmstadt16.sizeOf(darmstadt16.format))); // use low res texture
cubeTex->unlock();
Thanks for your help,

Best regards,

PicoJr.

RobDangerous
Computerversteher
Computerversteher
Beiträge: 363
Registriert: 14. Okt 2014 17:05

Re: Exercise 10 Kore::Image, Kore::Texture, threads

Beitrag von RobDangerous » 11. Jan 2018 14:59

Create more images in the correct sizes beforehand. But the last one should work, what systems was that?

PicoJr
Nichts ist wie es scheint
Beiträge: 23
Registriert: 28. Okt 2017 20:25

Re: Exercise 10 Kore::Image, Kore::Texture, threads

Beitrag von PicoJr » 11. Jan 2018 15:07

Hallo/Hello

System:

Code: Alles auswählen

            .-/+oossssoo+/-.
        `:+ssssssssssssssssss+:`           ----------
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 16.04.3 LTS x86_64
    .ossssssssssssssssssdMMMNysssso.       Host: Compaq 15 Notebook PC 096C110000405F00050660180
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Kernel: 4.4.0-104-generic
  +ssssssssshmydMMMMMMMNddddyssssssss+     Packages: 2579
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Shell: zsh 5.1.1
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Resolution: 1366x768
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   WM: i3
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   Theme: Ambiance [GTK3]
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   Icons: Ubuntu-mono-dark [GTK3]
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Terminal: x-term
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   CPU: Intel Celeron N2840 (2) @ 2.582GHz
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/    GPU: Intel Integrated Graphics
  +sssssssssdmydMMMMMMMMddddyssssssss+     Memory: 1917MiB / 7875MiB
   /ssssssssssshdmNNNNmyNMMMMhssssss/      GPU Driver: i915, i915
    .ossssssssssssssssssdMMMNysssso. 
      -+sssssssssssssssssyyyssss+-                                 
        `:+ssssssssssssssssss+:` 
            .-/+oossssoo+/-. 
OpenGL Config

Code: Alles auswählen

» glxinfo -B
name of display: :0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Intel Open Source Technology Center (0x8086)
    Device: Mesa DRI Intel(R) Bay Trail  (0xf31)
    Version: 17.0.7
    Accelerated: yes
    Video memory: 1536MB
    Unified memory: yes
    Preferred profile: core (0x1)
    Max core profile version: 3.3
    Max compat profile version: 3.0
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.0
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Bay Trail 
OpenGL core profile version string: 3.3 (Core Profile) Mesa 17.0.7
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 3.0 Mesa 17.0.7
OpenGL shading language version string: 1.30
OpenGL context flags: (none)

OpenGL ES profile version string: OpenGL ES 3.0 Mesa 17.0.7
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
Best regards,

PicoJr.

RobDangerous
Computerversteher
Computerversteher
Beiträge: 363
Registriert: 14. Okt 2014 17:05

Re: Exercise 10 Kore::Image, Kore::Texture, threads

Beitrag von RobDangerous » 11. Jan 2018 17:32

It works fine for me in a Ubuntu VM. Do you do the lock/unlock in the render thread?

PicoJr
Nichts ist wie es scheint
Beiträge: 23
Registriert: 28. Okt 2017 20:25

Re: Exercise 10 Kore::Image, Kore::Texture, threads

Beitrag von PicoJr » 11. Jan 2018 21:33

Hallo/Hello,

Thanks for your reply =)

I was doing the lock/unlock inside the stream thread.

I tried doing the lock/unlock in the update method (main thread).
It works better:

Code: Alles auswählen

std::memcpy(pointer, darmstadt16.data, (size_t) (darmstadt16.width * darmstadt16.height * darmstadt16.sizeOf(darmstadt16.format)));
does make visible changes: the top part of the high res texture is replaced by the lower res texture when displayed (see below).
memcpy_darmstadt_small.png
memcpy_darmstadt_small.png (21.26 KiB) 506 mal betrachtet
(update 0) when updating the texture width and height:
memcpy_darmstadt_small_2.png
memcpy_darmstadt_small_2.png (24.13 KiB) 505 mal betrachtet
(update 1) this is how it currently looks like:
textures_16_32_64.png
textures_16_32_64.png (20.46 KiB) 471 mal betrachtet
I still cannot figure out how to display lower res textures correctly =/

Best regards,

PicoJr.

RobDangerous
Computerversteher
Computerversteher
Beiträge: 363
Registriert: 14. Okt 2014 17:05

Re: Exercise 10 Kore::Image, Kore::Texture, threads

Beitrag von RobDangerous » 12. Jan 2018 13:33

You will have to figure that out yourself. But it's not hard, you just need to think about how the image data is represented in memory and do a bit more than just a memcpy. But you are also free to create multiple image objects instead and use the one which fits.

PicoJr
Nichts ist wie es scheint
Beiträge: 23
Registriert: 28. Okt 2017 20:25

Re: Exercise 10 Kore::Image, Kore::Texture, threads

Beitrag von PicoJr » 12. Jan 2018 13:45

Hallo/Hello,

Thanks for your reply =)

Understood, I'll give it more thoughts.

(Update 0)
memcpy.png
memcpy and textures
memcpy.png (10.77 KiB) 446 mal betrachtet
(Update 1)
texture-streaming-4.gif
texture streaming almost
texture-streaming-4.gif (296.59 KiB) 437 mal betrachtet
Best regards,

PicoJr.

Antworten

Zurück zu „Archiv“