I have a question about UV

Hi, I’m leaving a topic because I have a question.

After creating the vertices and uv directly, I want to use the
Example) var vertices: [Float] = [-1, 0, 1,…]
var uv: [Float] = [0, 1, …1, 1]

Paste in the texture.

Here we want to adjust the uv from a large texture in the form of an atlas to get only a portion of it.

I want to put a [Float] value from swift in the bridge header (c++) and get it from the protocol, but what is the [Float] data type in c++?

I solved it over the weekend,

I just need to declare vector_float2 as an array in the structure of the bridge header and then initialize the value for each element of vector_float2 in swift.

I solved it, but is there a more fancy way?

Well done for solving it yourself :clap: !

I guess the “fancy” way would be to use a vertex descriptor with vertex attributes rather than a bridging header.

Chapter 4 - The Vertex Function final code has an example of passing generated vertices and vertex colors (but UV coordinates would be the same except for being a simd_float2). It renders four points of a quad in different colors.

There’s one more thing I want.
When I call Ui(texture2d) one after another inside draw, it comes out jumbled instead of top to bottom.

Should I be suspicious of what is wrong in this case?

Also, is the reason for using the bridgeheader to synchronize the CPU and GPU correct?

Have you checked the GPU frame debugger to see that the values you expect are actually on the GPU?

I would suspect the initial UV array creation.

The bridging header is not for synchronization, and you don’t absolutely need one.

For example, you use the uniform values structure called Uniforms in both Swift for the CPU and C++ for the GPU. You could create the structure in both places, but when you add a property to the structure, you’d have to remember to do it in both places.

By creating a bridging header, you can make definitions that are readable by both Swift and C++.

1 Like

I really appreciate the advice :smiley:

I took your advice and tried really hard for a day or so to figure it out (I would suspect the initial UV array creation).

In debug mode, I found a phrase that is printed in purple.
I suspected this statement.

vertexbuffer, uvbuffer, texture, etc. in one class,
The problem seems to be that it is structured to change the values within one memory address.

Declaring one class for each object to create multiple memories solved the problem.

1 Like