haxiomic / vector-math

Shader-math in haxe: library for GLSL vector operations, complete with swizzles and all
MIT License
39 stars 7 forks source link

[C++]In C++, the problem of repeated attribute definitions occurs. #16

Closed rainyt closed 1 year ago

rainyt commented 3 years ago
Error: ./src/zygame/shader/StrokeShader.cpp: In member function 'bool zygame::shader::StrokeShader_obj::inAlpha(Vec2Data, Float, Float)':
./src/zygame/shader/StrokeShader.cpp:142:36: error: conversion from 'Float {aka double}' to non-scalar type 'Vec2Data {aka hx::ObjectPtr<Vec2Data_obj>}' requested
 HXDLIN(  22)   ::Vec2Data this11 = b_y;
                                    ^
./src/zygame/shader/StrokeShader.cpp:148:27: error: redeclaration of 'Vec2Data this11'
 HXDLIN(  22)   ::Vec2Data this11 =  ::Vec2Data_obj::__alloc( HX_CTX ,offestX,offestY);
                           ^
./src/zygame/shader/StrokeShader.cpp:142:27: note: 'Vec2Data this11' previously declared here
 HXDLIN(  22)   ::Vec2Data this11 = b_y;
                           ^
./src/zygame/shader/StrokeShader.cpp:149:21: error: redeclaration of 'Float x1'
 HXDLIN(  22)  Float x1 = (v2->x + b_x);
                     ^
./src/zygame/shader/StrokeShader.cpp:143:21: note: 'Float x1' previously declared here
 HXDLIN(  22)  Float x1 = (v2->x + b_x);
                     ^
./src/zygame/shader/StrokeShader.cpp:150:21: error: redeclaration of 'Float y1'
 HXDLIN(  22)  Float y1 = (v2->y + b_y);
                     ^
./src/zygame/shader/StrokeShader.cpp:144:21: note: 'Float y1' previously declared here
 HXDLIN(  22)  Float y1 = (v2->y + b_y);
                     ^
./src/zygame/shader/StrokeShader.cpp:151:27: error: redeclaration of 'Vec2Data this21'
 HXDLIN(  22)   ::Vec2Data this21 =  ::Vec2Data_obj::__alloc( HX_CTX ,x1,y1);
                           ^
./src/zygame/shader/StrokeShader.cpp:145:27: note: 'Vec2Data this21' previously declared here
 HXDLIN(  22)   ::Vec2Data this21 =  ::Vec2Data_obj::__alloc( HX_CTX ,x1,y1);
                           ^

In C++, the problem of repeated attribute definitions occurs. I noticed that it was caused by accessing .a, rbg and other methods:

if (alphaBlendMode.y == 1) {
    gl_FragColor.a *= 0;
}
if (mulcolor.a == 1) {
    gl_FragColor.rgb *= mulcolor.rgb;
}
rainyt commented 3 years ago
override function fragment() {
    super.fragment();
        color.r += 0.3;
        color.b += sin(time / 60);        
    gl_FragColor = color;
}
/Users/grtf/haxelib/vector-math/VectorMath.macro.hx:50: characters 12-13 : Float has no field x
Source/glsl/BitmapGLSL2.hx:10: characters 9-23 : ... Called from macro here
/Users/grtf/haxelib/vector-math/VectorMath.macro.hx:50: characters 12-13 : Float has no field z
Source/glsl/BitmapGLSL2.hx:11: characters 9-34 : ... Called from macro here
/Users/grtf/haxelib/vector-math/VectorMath.macro.hx:50: characters 12-13 : Float has no field x
Source/glsl/BitmapGLSL3.hx:10: characters 9-55 : ... Called from macro here
/Users/grtf/haxelib/vector-math/VectorMath.macro.hx:50: characters 12-13 : Float has no field x
Source/glsl/BitmapGLSL3.hx:11: characters 9-55 : ... Called from macro here
macro {
    var self = $self;
    self.$f0 = $value;
}

It seems that definitions such as rgba, xyzw, etc. cannot be accessed here. of +=.

shakesoda commented 3 years ago

this seems like an hxcpp bug more than a library bug, since it has valid output everywhere else. can it be worked around by adding an extra block/{} in the macro?

rainyt commented 3 years ago

Create a pull requestts:https://github.com/haxiomic/vector-math/pull/17

But the problem of += still exists.

// Error: Float has no field w
color.r += 0.3;
haxiomic commented 3 years ago

Create a pull requestts:#17

But the problem of += still exists.

// Error: Float has no field w
color.r += 0.3;

Thanks for reporting, it's helpful to have these examples!

This issue appears to be another form of a haxe compiler bug https://github.com/HaxeFoundation/haxe/issues/10150

The issue seems to occur when using the a.b overload with operators like +=. This should be fixed in the compiler, if we're lucky it may be fixed for haxe 4.3

haxiomic commented 1 year ago

This should be fixed since 4.3! c81180f4d0ce6a97f10cdca90d5a323dd7543e4f