我试图(徒劳地)使用OpenGL和NVIDIA的Cg着色器系统设置MRT,最终目的是推迟渲染。我已经成功为单个目标同时使用了着色器和“渲染到纹理”,但是当我尝试将一个对象渲染到多个渲染目标时,它在任何一个中都无法显示。
我以以下方式设置帧缓冲区对象:
// Initialize textures
// (I'll spare you the code since I've done that without issues)
// Initialize the FBO
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glGenRenderbuffers(1, &depthBuff);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuff);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, depthBuff);
// -snip-
// Bind each texture we want to use to the FBO at rtNum
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + rtNum,
GL_TEXTURE_2D, tex->getID(), 0);
// Check to make sure we're good to go
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
throw Exceptions::GLException("Frame buffer object is not complete.", …Run Code Online (Sandbox Code Playgroud) 我正在为一个宠物项目编写解析器,出于教育目的,我想手工而不是使用解析器生成器。不幸的是,许多在线资源(以及我在大学上的编译器课程)都采用某种 LL(k) 语法。我不想保留语法因素,因为左递归非终结符,例如
E ::= E * E
| E / E
| E + E
| E - E
| ...
Run Code Online (Sandbox Code Playgroud)
这在类似野牛的解析器生成器中是可能的,这似乎大大简化了语法。
手动解析这种语法的最简单方法是什么?到目前为止,我的研究告诉我,由于这里解释的原因,递归下降不是一种选择,并且使用递归上升的 LR 解析可能是一个不错的选择,尽管有几个站点停下来提到它不直观。
在D中,可以使用scope,即,在堆栈上分配类
void foo()
{
scope example = new Bar();
}
Run Code Online (Sandbox Code Playgroud)
现在,如果类Foo具有类Bar作为成员,是否有任何方法可以Bar在内部存储Foo并使用Foola C++进行拆分?
我曾希望如此
import std.stdio;
class Foo {
this() { writeln("Foo"); }
~this() { writeln("~Foo"); }
scope Bar inside;
}
class Bar {
this() { writeln("Bar"); }
~this() { writeln("~Bar"); }
};
void main()
{
scope f = new Foo();
writeln("I'm a main!");
}
Run Code Online (Sandbox Code Playgroud)
会产生类似的东西
Bar
Foo
我是主角!
~Bar
~Foo
相反,我只能得到
Foo
我是主力!
〜富
看起来将类成员存储为垃圾收集引用而不是就地存储只是不必要地使堆布局复杂化而没有什么好处.什么是scope做在这种情况下,如果不指定举行Bar …
为什么下面NullReferenceException的声明崩溃a.b.c = LazyInitBAndReturnValue(a);?
class A {
public B b;
}
class B {
public int c;
public int other, various, fields;
}
class Program {
private static int LazyInitBAndReturnValue(A a)
{
if (a.b == null)
a.b = new B();
return 42;
}
static void Main(string[] args)
{
A a = new A();
a.b.c = LazyInitBAndReturnValue(a);
a.b.other = LazyInitBAndReturnValue(a);
a.b.various = LazyInitBAndReturnValue(a);
a.b.fields = LazyInitBAndReturnValue(a);
}
}
Run Code Online (Sandbox Code Playgroud)
赋值表达式从右到左进行计算,因此在我们分配时a.b.c,a.b不应为null.奇怪的是,当调试器中断异常时,它也显示a.b为初始化为非空值.

我正在使用GCC arm-gnueabi交叉编译器将V8项目交叉编译为嵌入式ARM目标.我成功地对V8库进行了交叉编译,作为一个冒烟测试,我想将它链接到Google的hello world示例并在ARM板上运行它.
这些库本身的时钟超过1.2 MB:
v8 % find out/arm.release/obj.target/ -name '*.a' -exec du -h {} +
1.2M out/arm.release/obj.target/tools/gyp/libv8_base.a
12K out/arm.release/obj.target/tools/gyp/libv8_libbase.a
4.0K out/arm.release/obj.target/tools/gyp/libv8_libplatform.a
4.0K out/arm.release/obj.target/tools/gyp/libv8_snapshot.a
4.0K out/arm.release/obj.target/tools/gyp/libv8_nosnapshot.a
4.0K out/arm.release/obj.target/third_party/icu/libicudata.a
164K out/arm.release/obj.target/third_party/icu/libicuuc.a
336K out/arm.release/obj.target/third_party/icu/libicui18n.
Run Code Online (Sandbox Code Playgroud)
然而,当我建立和链接
arm-linux-gnueabi-g++ -pthread -Iv8/include hi.cpp -Os -o hi_v8 -Wl,--start-group v8/out/arm.release/obj.target/{tools/gyp/libv8_{base,libbase,snapshot},third_party/icu/libicu{uc,i18n,data}}.a -Wl,--end-group
Run Code Online (Sandbox Code Playgroud)
我得到一个20 MB的可执行文件.剥离它只能让我降到17 MB
那个气球链接的文件大小如此之多?我怎么能避免呢?我可以使用哪些工具来诊断问题?在我定位的平台上,此大小可能会出现问题.
我已经看了一下readelf --sections,但它只是告诉我整个.text部分的大小,这不是特别有用.我也看了一下这里的建议并尝试使用nm,但它太具体了 - 我只是一堆名称错误的符号_ZN2v88internal11FLAG_log_gcE.
我在Windows上使用预构建的Qt 5.0.2和MinGW,并为我的项目安装了一个安装程序.我发现我的编译的二进制依赖于ICU库(icudt49.dll,icuin49.dll,和icuuc49.dll),即使我没有使用任何本地化或Unicode.
有没有简单的方法可以阻止Qt将ICU用于项目,还是我必须从源代码重新编译Qt?
如何创建堆栈中的结构的垃圾收集副本?
来自C++背景,我的第一个猜测将是一个像下面那样的复制构造函数,但对于D来说它似乎不是很惯用,而且我没有在任何D项目中看到过我看过的.
struct Foo {
immutable int bar;
this(int b) { bar = b; }
// A C++-style copy constructor works but doesn't seem idiomatic.
this(ref const Foo f) { bar = f.bar; }
}
void main()
{
// We initialize a Foo on the stack
auto f = Foo(42);
// Now I want to get a heap copy of its member. How?
// A C++-style copy constructor works but doesn't seem idiomatic.
Foo* f1 = new Foo(f);
}
Run Code Online (Sandbox Code Playgroud) 我之前的问题讨论过如下制作复制构造函数:
struct Foo {
int i;
this(int j) { i = j; }
this(Foo rhs) { this = rhs; }
}
void main()
{
auto f = Foo(5);
auto g = new Foo(f);
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用i不可变,则构造函数无法编译
错误:无法使用不可变成员修改struct this Foo
为什么会这样?我的印象是,在到达构造函数的末尾之前,类或结构的不可变成员不会变为不可变.
我正在使用C11*atomics来管理几个线程之间的状态枚举.代码类似于以下内容:
static _Atomic State state;
void setToFoo(void)
{
atomic_store_explicit(&state, STATE_FOO, memory_order_release);
}
bool stateIsBar(void)
{
return atomic_load_explicit(&state, memory_order_acquire) == STATE_BAR;
}
Run Code Online (Sandbox Code Playgroud)
这组装(对于ARM Cortex-M4):
<setToFoo>:
ldr r3, [pc, #8]
dmb sy ; Memory barrier
movs r2, #0
strb r2, [r3, #0] ; store STATE_FOO
bx lr
.word 0x00000000
<stateIsBar>:
ldr r3, [pc, #16]
ldrb r0, [r3, #0] ; load state
dmb sy ; Memory barrier
sub.w r0, r0, #2 ; Comparison and return follows
clz r0, r0
lsrs r0, r0, #5 …Run Code Online (Sandbox Code Playgroud) 我正在尝试围绕libavformat构建一些视频阅读代码.获得编译的DLL和之后.lib的文件在这里,我去打造我的代码,并链接器无法找到任何即使我在所提供的已关联了libavformat符号的 .lib文件.
检查libavformat.lib以dumpbin -headers显示它导出所需功能以下划线前缀.例如,当我想调用时avformat_open_input,.lib文件给出_avformat_open_input.
为什么会这样,为什么我不能链接预编译的dll?
我喜欢我的c ++成员变量和方法声明都缩进相同的数量,所以它们排列如下:
class SnipformationScheduler : public ParagraphformationFinishedResponder
{
int mCurrentSnipIndex;
vector<ParagraphFormationAnimation> mParagraphAnimations;
public:
vector<string> mSnippetIDs;
MovementController* mMovementController;
SnipformationScheduler();
virtual ~SnipformationScheduler(void);
void tick();
void paragraphAnimationFinished();
};
Run Code Online (Sandbox Code Playgroud)
目前,我这样做是通过按Tab键直到我得到正确数量的缩进.当然有一种更简单的方法.有谁知道它是什么?
我已将文本文件加载到缓冲区中,并且想要使用良好的C ++样式,请使用vector<char>。然后,我想将一个迭代器从所述向量传递给char*函数参数-我假设在幕后,向量迭代器仅解析为指向成员类型的指针。但是,出现以下错误:
no known conversion for argument 2 from ‘const __gnu_cxx::__normal_iterator<char*, std::vector<char> >’ to ‘char*’
Run Code Online (Sandbox Code Playgroud)
向量迭代器不仅仅是指针吗?在这种情况下,仅使用指针会更有效吗?
c++ ×4
d ×3
immutability ×2
arm ×1
assembly ×1
atomic ×1
c# ×1
c++11 ×1
c11 ×1
cg ×1
constructor ×1
deployment ×1
elf ×1
evaluation ×1
ffmpeg ×1
framebuffer ×1
gcc ×1
grammar ×1
icu ×1
indentation ×1
iterator ×1
libavformat ×1
linker ×1
opengl ×1
parsing ×1
qt ×1
reference ×1
shader ×1
stack ×1
unicode ×1
v8 ×1
vector ×1
visual-c++ ×1