我有一个抽象类:
和扩展类:
Vec2t有以下配套对象:
companion object {
@JvmField val length = 2
}
Run Code Online (Sandbox Code Playgroud)
但是当我输入时Vec2.length,它被标记为未解决的参考...
为什么?我错过了什么?
我使用VBO渲染基于milions(最多十个)三角形的模型,我需要检测用户可以点击哪些三角形.
我尝试阅读并理解"名称堆栈"和"独特颜色"的工作原理.我发现名称堆栈最多只能包含128个名称,而唯一颜色最多可包含2 ^(8 + 8 + 8)= 16777216种不同的颜色,但有时可能会有一些近似值,因此它可以得到改性..
对我来说哪个是最好的策略?
纯粹的超级采样抗锯齿 (SSAA) 和通过每样本着色进行多重采样之间有什么区别
gl4.glMinSampleShading(1.0f);
Run Code Online (Sandbox Code Playgroud)
我更喜欢后者,因为与 SSAA 相比,它不需要更大的纹理,并且提供了很大的灵活性。即:您甚至可以在运行时在 SS 和纯多重采样之间切换。
有什么我不知道的缺点吗?
在这些日子里,我正在阅读Jason L. McKesson撰写的" 学习现代3D图形编程"一书.基本上它是一本关于OpenGL 3.3的书,我现在在第4章,这是关于正交和透视的.
在本章的最后,在"进一步研究"部分,他建议尝试一些事情,比如实现可变眼点(他在相机空间的开头(0,0,0)用于简洁)和任意透视平面地点.他说我需要分别用E_x和E_y来偏移顶点的X,Y相机空间位置.
我无法理解这段话,我应该如何使用可变眼点仅修改X,Y偏移?
编辑:这可能是这样的吗?
#version 330
layout(location = 0) in vec4 position;
layout(location = 1) in vec4 color;
smooth out vec4 theColor;
uniform vec2 offset;
uniform vec2 E;
uniform float zNear;
uniform float zFar;
uniform float frustumScale;
void main()
{
vec4 cameraPos = position + vec4(offset.x, offset.y, 0.0, 0.0);
vec4 clipPos;
clipPos.xy = cameraPos.xy * frustumScale + vec4(E.x, E.y, 0.0, 0.0);
clipPos.z = cameraPos.z * (zNear + zFar) / (zNear - …Run Code Online (Sandbox Code Playgroud) 我有一个空的 byteBuffer 分配为
data = ByteBuffer.allocateDirect(layerSize(0, faces - 1, 0, levels - 1) * layers);
按照这个答案,我尝试使用以下array()方法
public void setData(ByteBuffer data, int layer, int face, int level) {
int offset = offset(layer, face, level);
int levelSize = levelSize(level);
this.data.put(data.array(), offset, levelSize);
}
Run Code Online (Sandbox Code Playgroud)
但我得到:
Caused by: java.lang.UnsupportedOperationException
at java.nio.ByteBuffer.array(ByteBuffer.java:994)
Run Code Online (Sandbox Code Playgroud)
我尝试使用的源字节缓冲区以这种方式读取:
File file = new File(Load.class.getResource(fileName).getFile());
FileInputStream fileInputStream = new FileInputStream(file);
FileChannel fileChannel = fileInputStream.getChannel();
return loadKtx(fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int) file.length()));
public static Texture loadKtx(ByteBuffer byteBuffer) throws IOException {
... …Run Code Online (Sandbox Code Playgroud) 我现在卡住尝试将以下布局[10,10,10,2]中的四个整数打包成一个整数,这是第一个int占据前10位,类似于第二个和第三个,而最后一个只是最后两位.
在C++示例中,这是打包它们的代码:
GLM_FUNC_QUALIFIER uint32 packSnorm3x10_1x2(vec4 const & v)
{
detail::i10i10i10i2 Result;
Result.data.x = int(round(clamp(v.x,-1.0f, 1.0f) * 511.f));
Result.data.y = int(round(clamp(v.y,-1.0f, 1.0f) * 511.f));
Result.data.z = int(round(clamp(v.z,-1.0f, 1.0f) * 511.f));
Result.data.w = int(round(clamp(v.w,-1.0f, 1.0f) * 1.f));
return Result.pack;
}
Run Code Online (Sandbox Code Playgroud)
Result.data如下struct:
union i10i10i10i2
{
struct
{
int x : 10;
int y : 10;
int z : 10;
int w : 2;
} data;
uint32 pack;
};
Run Code Online (Sandbox Code Playgroud)
输入等于[-1f,-1f,0f,1f]我们得到Result.data等于[-511,-511,0,1]和返回值1074267649,二进制是:
0 -511 …Run Code Online (Sandbox Code Playgroud) 我想得到与cpp相同的行为:
enum dxgi_format_gli
{
DXGI_FORMAT_R64_UINT_GLI = 1,
DXGI_FORMAT_R64_SINT_GLI
}
Run Code Online (Sandbox Code Playgroud)
其中DXGI_FORMAT_R64_UINT_GLI获取1和下得到2
我得到的最接近的是:
private var counter: Int = 2;
enum class dxgi_format_gli(i: Int = counter++) {
DXGI_FORMAT_R64_UINT_GLI(1),
DXGI_FORMAT_R64_SINT_GLI()
}
Run Code Online (Sandbox Code Playgroud)
但是我当然希望它是动态的,就是每当我用一个参数调用构造函数时,保存一个counter并且所有以下构造函数都递增并得到它.
我已经在java中创建了它:
public enum Dxgi_format_gli {
DXGI_FORMAT_R64_UINT_GLI(1),
DXGI_FORMAT_R64_SINT_GLI;
public final int value;
private static class Counter {
private static short value = 0;
}
private Dxgi_format_gli() {
value = Counter.value;
Counter.value++;
}
private Dxgi_format_gli(int value) {
this.value = value;
Counter.value++;
}
}
Run Code Online (Sandbox Code Playgroud)
但我没有使用Kotlin.
我想.MAX在通用枚举上表示值计数.
我试着玩一点,但我想不出来.
当我写作时,例如,这个:
val Enum.Companion.MAX get() = enumValues().size
它抱怨enumValues()说
类型推断失败:没有足够的信息来推断参数T in
inline fun> enumValues():Array请明确指定它.
这很有道理,然后我也试过了:
val <E> Enum<E>.Companion.MAX get() = enumValues().size
它抱怨第二个 E
引用嵌套类时,外部类的类型参数是多余的
有办法吗?
我想输入:
project.tasks<JmhTask> {
...
}
Run Code Online (Sandbox Code Playgroud)
反而
project.tasks.withType(JmhTask::class.java) {
...
}
Run Code Online (Sandbox Code Playgroud)
tasks是TaskContainer类型,它扩展interface DomainObjectCollection<T> extends Collection<T>
DomainObjectCollection还定义::withType如下:
<S extends T> DomainObjectCollection<S> withType(Class<S> type, Action<? super S> configureAction);
我尝试执行以下操作(TaskContainer为简单起见,首先针对接收器):
inline operator fun <reified S> TaskContainer.invoke(configureAction: Action<in S>?) =
withType(S::class.java, configureAction)
Run Code Online (Sandbox Code Playgroud)
不幸的withType是被标记为红色:
None of the following functions can be called with the arguments supplied.
withType(Class<TypeVariable(S)!>, (Closure<Any!>..Closure<*>)) where S = TypeVariable(S) for fun <S : Task!> withType(type: Class<S!>, configureClosure: (Closure<Any!>..Closure<*>)): DomainObjectCollection<S!> defined in org.gradle.api.tasks.TaskContainer …Run Code Online (Sandbox Code Playgroud) Java(FontMetrics)中是否有任何字体指标?
例如:
FontMetrics fm = g2.getFontMetrics();
Rectangle2D rect = fm.getStringBounds(node.getText(), g2);
Run Code Online (Sandbox Code Playgroud) 在jvm imgui中,我正在使用
System.identityHashCode(i++)
哪里
var i = 0
为每个帧始终为给定对象生成一个常数id(因此
可以对其进行跟踪)
但是,一个用户案例只是告诉我,这仅对中的值有效[0, 125]
尝试调试并查找错误,我结束了这段简短的代码测试:
var i = 0
val A = Array(256, { System.identityHashCode(i++) })
i = 0
val B = Array(256, { System.identityHashCode(i++) })
repeat(256) {
if (A[it] != B[it])
println("[$it] different, A ${A[it]}, B ${B[it]}")
}
Run Code Online (Sandbox Code Playgroud)
还有:
这是为什么?
我是否可以安全地假设这种行为在其他平台上也能保持一致?
我正在考虑初始化一些值,而不是在init函数中复杂化,我重构为函数,例如callSomeFunctionThatWillOnlyBeCalledByInit(),并在finalValue那里进行初始化.
val finalValue: String
init {
callSomeFunctionThatWillOnlyBeCalledByInit()
}
fun callSomeFunctionThatWillOnlyBeCalledByInit() {
finalValue = "Something"
}
Run Code Online (Sandbox Code Playgroud)
显然它会投诉val cannot be reassigned.我清楚地知道callSomeFunctionThatWillOnlyBeCalledByInit()只会被召唤出来init.但有没有办法让编译器知道这一点,所以它不抱怨?
注意:
我知道我可以做如下的事情
val finalValue: String
init {
finalValue = callSomeFunctionThatWillOnlyBeCalledByInit()
}
fun callSomeFunctionThatWillOnlyBeCalledByInit() : String {
return "Something"
}
Run Code Online (Sandbox Code Playgroud)
但我只是想探索是否有init更好的重构方法,并且可以将初始化放在某个函数中而不是必须进行init.
我正在将项目移至Java11
我已经改变了sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl与java.lang.reflect.ParameterizedType(作为指定在这里),现在之交MalformedByteSequenceException:
警告:MalformedByteSequenceException是内部专有API,可以在以后的版本导入com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException中删除。
它被用于从XML文件创建对象的一小段代码中。更确切地说是try-catch。
try {
...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(stream);
NodeList list = document.getChildNodes();
fillProcessStack(document);
...
list = list.item(0).getChildNodes();
createItems(list, parent);
} catch (MalformedByteSequenceException e) {
//"Any char in your xml file has a wrong format: " + e.getLocalizedMessage()
} catch (SAXParseException sax) {
...
} catch (Exception e) {
...
}
Run Code Online (Sandbox Code Playgroud)
无论如何,我在网上找不到任何关于此的信息。
我能想到的最接近的是UnsupportedEncodingException,但我不确定。
另外,这可能是从网络复制的一些旧代码的遗留物,并且显然,如果我删除它,则对于编译器来说一切看起来仍然很好。
那么,关于Java11是否有任何一般/好的建议?
编辑:对于寻求关闭此问题的人,因为
寻求调试帮助的问题(“此代码为什么不起作用?”)必须包括所需的行为,特定的问题或错误以及在问题本身中再现该错误所需的最短代码。没有明确问题陈述的问题对其他读者没有用。请参阅:如何创建最小的,可复制的示例。
我会尝试更清楚地解释。 …