Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411283 Posts in 69325 Topics- by 58380 Members - Latest Member: bob1029

March 29, 2024, 05:36:32 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)The happy programmer room
Pages: 1 ... 245 246 [247] 248 249 ... 279
Print
Author Topic: The happy programmer room  (Read 673162 times)
JWki
Level 4
****


View Profile
« Reply #4920 on: July 31, 2017, 01:31:18 PM »

Yeah then here's one of the not so nice parts of programming: Messing with the win32 API.
Anyways, halfway happy to have gotten to this after a few hours:




Looks like nothing but alas this shows UI being rendered in process A, with process B housing the window for process A using SetParent() after sending the window handle via TCP. Sounds hilarious but actually KINDA works except for when trying to actually resize the swap chain or, you know, render something else than the UI.

EDIT: Yeah resizing the window seems to make things go really bad.
« Last Edit: July 31, 2017, 01:49:53 PM by JWki » Logged
JWki
Level 4
****


View Profile
« Reply #4921 on: July 31, 2017, 02:39:38 PM »

Sorry for the spam but fuck yeah



D3D11 application embedded into Win32 application with TCP based window handle exchange.
OF COURSE the resizing misbehaviour had NOTHING to do with the window management stuff but everything with COMPLETELY unrelated rendering code - turns out I didn't handle resize correctly before trying this out either.
Logged
ferreiradaselva
Level 3
***



View Profile
« Reply #4922 on: August 01, 2017, 04:08:56 PM »

Why the heck I never thought this:

Code:
typedef union {
float m[4][4];
struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
float m30, m31, m32, m33;
};
} cmatrix;

My corrent code:
Code:
struct cmatrix {
/* Row x Column */
float m11;
float m21;
float m31;
float m41;
float m12;
float m22;
float m32;
float m42;
float m13;
float m23;
float m33;
float m43;
float m14;
float m24;
float m34;
float m44;
};

I found on the lib github.com/arkanis/single-header-file-c-libs, that I saw (BlinkBlink) Randy starring on github

... To be fair, even a simple struct is working nicely and fast on my framework, but it's always good to make it faster.
Logged

qMopey
Level 6
*


View Profile WWW
« Reply #4923 on: August 01, 2017, 04:56:45 PM »

Yep! Union is great for math stuff. Triangle I wrote for work just now:

Code:
union Triangle
{
struct
{
Vector3 a;
Vector3 b;
Vector3 c;
};

Vector3 v[3];
};

Math stuff is an exercise in API design. Good API design caters to common user style preferences. Sometimes people want an array, sometimes they want named members. Sometimes they want style A, or style B, or style C, etc... It's the API's job to let the user quickly "plug in" the API and get going. Nobody wants to write wrappers or boiler plate for this kind of stuff.
Logged
JWki
Level 4
****


View Profile
« Reply #4924 on: August 01, 2017, 10:33:42 PM »

Did someone say unions and maths stuff

Code:
template <class TElement>
        struct Vector<TElement, 4>
        {
            union {
                TElement elements[4];
                struct { TElement x, y, z, w; };
                struct { TElement r, g, b, a; };
                Vector<TElement, 3> xyz;
                Vector<TElement, 2> xy;
                Vector<TElement, 3> rgb;
                Vector<TElement, 2> rg;
            };
            GT_COMMON_VECTOR_OP(TElement, 4)

            Vector(Vector<TElement, 3> abc, TElement d) : xyz(abc), w(d) {}
            Vector(TElement a, TElement b, TElement c, TElement d) : x(a), y(b), z(c), w(d) {}
        };

Yeahhhhhh I know, templates...
Logged
Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #4925 on: August 02, 2017, 12:32:26 AM »

What's the matter with templates? Just last month I had to template my math classes after ~15 years of use and maintenance, because I required fixpoint vector math. Save yourself the hassle, template at least the scalar type right from the start.

Then there are people who also template the element count, which I think is a case of over-generalization. It has its advantages, like sharing a lot of code between differently sized vectors, but it prevents you from using speaking names. After so many years as a coder I realized that there's a whole lot of language features which solely aids you, the human, and has no meaning to the compiler. public, private, protected, const, or variable names - it's for humans.

Note: I heard a lot of complaints about unions and the optimizer behavior of Visual Studio. Apparently when using unions, the compiler does not do a lot of obvious optimizations. That's why I implemented element-wise access in a hacky way:

Code:
Scalar operator [] (size_t idx) const { return (&x)[idx]; }

Maybe that's undefined behavior, maybe it breaks aliasing analysis... I don't know. I don't even know if this observation still holds true in recent versions. Haven't verified this for years.
« Last Edit: August 02, 2017, 12:40:27 AM by Schrompf » Logged

Snake World, multiplayer worm eats stuff and grows DevLog
qMopey
Level 6
*


View Profile WWW
« Reply #4926 on: August 02, 2017, 01:39:57 AM »

Personally if I had to do some fixed-point stuff, I would want a custom little lib to do that. The point of fixed-point math is to have full explicit control over everything; a lot of code that will work with floating point stuff won't make much sense for fixed-point, and vice versa.

The role of the template can be fulfilled with a typedef. Typically it's something like: typedef float real. That way float/double can be swapped around for debugging purposes. This is pretty helpful in numerically sensitive algorithms.

But the biggest reason to not template math is that math goes everywhere in the codebase. Spreading templates around like that incurs a lot of compile time overhead.
Logged
JWki
Level 4
****


View Profile
« Reply #4927 on: August 02, 2017, 01:56:21 AM »

Yeah that's essentially the issue with templates - it can blow compile times up extremely.
My maths stuff is templated by element type as well as element count simply because you can write most operations in a generic fashion that way. The snippet above is the specialization for vectors with 4 components.
I then have some typedefs for stuff like float2, float3, float4, int2, int3, int4, etc (or vec3f or what have you).

I might try out a simple code generator tho to replace this.
Logged
Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #4928 on: August 02, 2017, 02:14:49 AM »

But the biggest reason to not template math is that math goes everywhere in the codebase. Spreading templates around like that incurs a lot of compile time overhead.

That's another thing in need of verification. People keep bringing it up, but I'm pretty sure it's not true anymore... at least not for straight forward templates with a single parameter, like this one. If you're going for boost meta programming, though, that's an all different topic.

But well... each to their own.
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
qMopey
Level 6
*


View Profile WWW
« Reply #4929 on: August 02, 2017, 12:43:47 PM »

In my experience, people haven't noticed much because A) they work on tiny projects at home, and B) at work they use some kind of distributed build system that solves compilation time with lots of hardware.
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #4930 on: August 02, 2017, 05:34:06 PM »

But the biggest reason to not template math is that math goes everywhere in the codebase. Spreading templates around like that incurs a lot of compile time overhead.

That's another thing in need of verification. People keep bringing it up, but I'm pretty sure it's not true anymore... at least not for straight forward templates with a single parameter, like this one. If you're going for boost meta programming, though, that's an all different topic.

But well... each to their own.

I can tell you anecdotally from working on a handful of very large game engines that templates are a brutal thorn in my side. That and whole program optimization link stages. Those are essentially the 2 worst offenders for compile time.

But yes, for simpler templates where the overall developer gains are big. It's kind of hard to argue against them.
Logged

JWki
Level 4
****


View Profile
« Reply #4931 on: August 04, 2017, 03:10:56 AM »

Templates asides, the best part about API design is that you get to use the APIs you always wanted.
Like this one to enumerate graphics devices in the system and then use the default one to create a vertex and an index buffer:

Code:
gfx::Interface* gfxInterface = nullptr;
gfx::Device* gfxDevice = nullptr;

gfx::InterfaceDesc interfaceDesc;
if (!gfx::CreateInterface(&gfxInterface, &interfaceDesc, &applicationArena)) {
    GT_LOG_ERROR("Renderer", "Failed to initialize graphics interface\n");
}

gfx::DeviceInfo deviceInfo[GFX_DEFAULT_MAX_NUM_DEVICES];
uint32_t numDevices = 0;
gfx::EnumerateDevices(gfxInterface, deviceInfo, &numDevices);
for (uint32_t i = 0; i < numDevices; ++i) {
    GT_LOG_INFO("Renderer", "Detected graphics device: %s", deviceInfo[i].friendlyName);
}
if (numDevices == 0) {
    GT_LOG_ERROR("Renderer", "No graphics device detected!");
}
else {
    gfxDevice = gfx::GetDevice(gfxInterface, deviceInfo[0].index);
    if (gfxDevice != nullptr) {
        GT_LOG_INFO("Renderer", "Selected graphics device: %s", deviceInfo[0].friendlyName);
    }
    else {
        GT_LOG_ERROR("Renderer", "Failed to get default graphics device");
    }
}

gfx::BufferDesc vBufferDesc;
vBufferDesc.type = gfx::BufferType::BUFFER_TYPE_VERTEX;
vBufferDesc.initialData = triangleVertices;
vBufferDesc.initialDataSize = sizeof(triangleVertices);
gfx::Buffer vBuffer = gfx::CreateBuffer(gfxDevice, &vBufferDesc);

gfx::BufferDesc iBufferDesc;
iBufferDesc.type = gfx::BufferType::BUFFER_TYPE_VERTEX;
iBufferDesc.initialData = triangleIndices;
iBufferDesc.initialDataSize = sizeof(triangleIndices);
gfx::Buffer iBuffer = gfx::CreateBuffer(gfxDevice, &iBufferDesc);
Logged
JWki
Level 4
****


View Profile
« Reply #4932 on: August 04, 2017, 12:37:45 PM »

So



Impressive, I know.

Seriously though, that triangle there is being rendered without the use code caring what the underlying graphics API is.
ATM it's d3d11 but tomorrow it may be OpenGL - or Vulkan - or Metal - or whatever I can get my hands on.
Well after I make the API more complete to support more blend states, rasterizer states, etc etc. Also constant/uniform buffers I guess.

I realize it looks pretty much like nothing but I've tried my hands at this so many times now and it's the first time that I think I'm on the right track.
Logged
oahda
Level 10
*****



View Profile
« Reply #4933 on: August 04, 2017, 01:04:28 PM »

Don't worry, I completely get the joy of a triangle (don't let me remind you of this ridiculous photo)! Coffee

I'll be getting back to that sometime soon too hopefully. I'll code it to work with any graphics backend as well, altho I won't be implementing anything besides OpenGL for now (and I'll try to compromise as well as I can whenever GLES/WebGL won't allow me to do something I can do in regular GL in order to have a single implementation for both mobile and PC/console, because it seems like less work if the simpler one can work everywhere and I have to write it anyway, and I'm not looking to make Crysis, plus I'm using GLES3 which is quite decent in my limited experience, and WebGL seems to mirror it quite well).
Logged

JWki
Level 4
****


View Profile
« Reply #4934 on: August 04, 2017, 01:07:28 PM »

Don't worry, I completely get the joy of a triangle (don't let me remind you of this ridiculous photo)! Coffee

I'll be getting back to that sometime soon too hopefully. I'll code it to work with any graphics backend as well, altho I won't be implementing anything besides OpenGL for now (and I'll try to compromise as well as I can whenever GLES/WebGL won't allow me to do something I can do in regular GL in order to have a single implementation for both mobile and PC/console, because it seems like less work if the simpler one can work everywhere and I have to write it anyway, and I'm not looking to make Crysis, plus I'm using GLES3 which is quite decent in my limited experience, and WebGL seems to mirror it quite well).

WebGL 1 is pretty much GLES2, but WebGL 2 is based on ES3 yeah.
I'm pretty hungry to do more serious gfx programming because I haven't done any in like more than a year now. Probably won't even bother implementing OpenGL tho - it's my least favorite graphics API by now and all platforms of interest are covered by other APIs anyways.
Logged
JWki
Level 4
****


View Profile
« Reply #4935 on: August 08, 2017, 05:44:02 AM »

Here's something cooler than a triangle.



A bit hard to see, but it's rendering the UI onto the cube face as well as blitting it to the screen in the other window.
This was to test my API for offscreen rendering and also lead down the rabbit hole of configuring the blend states for the to-screen blit and the UI rendering pass such that the result is equivalent both when rendering to the screen and when rendering to the offscreen buffer and then blitting.
Logged
oahda
Level 10
*****



View Profile
« Reply #4936 on: August 08, 2017, 09:44:39 AM »

Nice!

Probably won't even bother implementing OpenGL tho - it's my least favorite graphics API by now and all platforms of interest are covered by other APIs anyways.
I'd be really keen on trying stuff like Vulkan and Metal but I'm sticking with OpenGL thanks to its unrivalled compatibility across the board for now—even less keen on writing multiple complex backends. Might try those for fun in throwaway projects tho. e:
Logged

JWki
Level 4
****


View Profile
« Reply #4937 on: August 08, 2017, 11:27:50 AM »

Nice!

Probably won't even bother implementing OpenGL tho - it's my least favorite graphics API by now and all platforms of interest are covered by other APIs anyways.
I'd be really keen on trying stuff like Vulkan and Metal but I'm sticking with OpenGL thanks to its unrivalled compatibility across the board for now—even less keen on writing multiple complex backends. Might try those for fun in throwaway projects tho. e:

Fair enough, I'm pretty happy with how my API is shaping tho. Pretty happy that I started it going for simplicity and non-verbosity this time, it's way easier to add complexity to something simple than designing something complex up front. Everytime I do something that'd take me dozens of lines of code in OpenGL or D3D11, it just takes like a few lines in the current form of my API and it feels great.
Logged
JWki
Level 4
****


View Profile
« Reply #4938 on: August 10, 2017, 02:13:01 AM »

Sometimes I feel like I'm the only happy programmer.

Messed around with realtime mesh painting:



As in, you can paint the thing with your mouse. Great stuff.
Logged
oahda
Level 10
*****



View Profile
« Reply #4939 on: August 10, 2017, 02:31:45 AM »

I'll get back to it soon enough! c: Did a jam recently and exhausted myself. Considering doing some prototyping in Unity for the game I'll be making with my own engine in the end.

Looks good! Is that the brand new colour picker that Omar tweeted about, or one of the third-party ones?
Logged

Pages: 1 ... 245 246 [247] 248 249 ... 279
Print
Jump to:  

Theme orange-lt created by panic