- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我只想对默认的 OpenGL 行为进行一些说明。据我了解,默认事件纹理单元为 0 (GL_TEXTURE0
),除非通过 glActiveTexture
明确更改,否则将保持不变。
我问这个是因为我遇到了无法解释且有问题的行为。加载纹理并将其绑定(bind)到 GL_TEXTURE_2D
(假设 GL_TEXTURE0
处于事件状态)后,我无法显示它,直到我将事件纹理设置为 GL_TEXTURE1
。甚至在加载后第一次绑定(bind)之前显式调用 glActiveTexture(GL_TEXTUREX)
,然后在绘制期间使用它时重复此调用也没有任何作用。仅当我在绑定(bind)和分配给着色器之前调用 glActiveTexture(GL_TEXTURE1)
时才会显示纹理。
当我尝试使用更多纹理时会重复此过程,而我必须显式设置每个 glActiveTexture(GL_TEXTURE...)
取决于我之前加载和首次绑定(bind)纹理的顺序我绑定(bind)它们并将它们分配给着色器。即使我没有使用我加载的第一个纹理进行绘制,我仍然必须调用 glActiveTexture(GL_TEXTURE2)
...而不是 GL_TEXTURE1
,或者更好的 GL_TEXTURE0
因为到那时我什至还没有调用 glActiveTexture(...)
。我认为后者是根据 GL 规范应该发生的情况。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glActiveTexture.xhtml
这是司机主义吗?
Dell Precision M6800、nV K2200M、GL 4.1 和 3.3。
更新:孤立的例子。
#include <Windows.h>
#include <gl\GL.h>
#include "glext.h"
#include "wglext.h"
#include <vector>
#include <memory>
#include <atlimage.h>
namespace
{
class GLFunc
{
public:
GLFunc()
{
glCreateProgram = (PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram");
glCreateShader = (PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader");
glShaderSource = (PFNGLSHADERSOURCEPROC)wglGetProcAddress("glShaderSource");
glCompileShader = (PFNGLCOMPILESHADERPROC)wglGetProcAddress("glCompileShader");
glAttachShader = (PFNGLATTACHSHADERPROC)wglGetProcAddress("glAttachShader");
glDetachShader = (PFNGLDETACHSHADERPROC)wglGetProcAddress("glDetachShader");
glLinkProgram = (PFNGLLINKPROGRAMPROC)wglGetProcAddress("glLinkProgram");
glUseProgram = (PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram");
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)wglGetProcAddress("glGenFramebuffers");
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)wglGetProcAddress("glBindFramebuffer");
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)wglGetProcAddress("glGenRenderbuffers");
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)wglGetProcAddress("glBindRenderbuffer");
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)wglGetProcAddress("glRenderbufferStorage");
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)wglGetProcAddress("glFramebufferRenderbuffer");
glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)wglGetProcAddress("glFramebufferTexture");
glDrawBuffers = (PFNGLDRAWBUFFERSPROC)wglGetProcAddress("glDrawBuffers");
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)wglGetProcAddress("glCheckFramebufferStatus");
glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)wglGetProcAddress("glGenVertexArrays");
glBindBuffer = (PFNGLBINDBUFFERPROC)wglGetProcAddress("glBindBuffer");
glBufferData = (PFNGLBUFFERDATAPROC)wglGetProcAddress("glBufferData");
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)wglGetProcAddress("glDeleteFramebuffers");
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)wglGetProcAddress("glDeleteRenderbuffers");
glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC)wglGetProcAddress("glDeleteVertexArrays");
glGetShaderiv = (PFNGLGETSHADERIVPROC)wglGetProcAddress("glGetShaderiv");
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)wglGetProcAddress("glGetShaderInfoLog");
glGetProgramiv = (PFNGLGETPROGRAMIVPROC)wglGetProcAddress("glGetProgramiv");
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)wglGetProcAddress("glGetProgramInfoLog");
glGenBuffers = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffers");
glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)wglGetProcAddress("glEnableVertexAttribArray");
glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)wglGetProcAddress("glVertexAttribPointer");
glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)wglGetProcAddress("glBindVertexArray");
glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation");
glUniformMatrix2fv = (PFNGLUNIFORMMATRIX2FVPROC)wglGetProcAddress("glUniformMatrix2fv");
glUniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC)wglGetProcAddress("glUniformMatrix3fv");
glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)wglGetProcAddress("glUniformMatrix4fv");
glUniform1f = (PFNGLUNIFORM1FPROC)wglGetProcAddress("glUniform1f");
glUniform2f = (PFNGLUNIFORM2FPROC)wglGetProcAddress("glUniform2f");
glUniform3f = (PFNGLUNIFORM3FPROC)wglGetProcAddress("glUniform3f");
glUniform4f = (PFNGLUNIFORM4FPROC)wglGetProcAddress("glUniform4f");
glUniform1i = (PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i");
glUniform2i = (PFNGLUNIFORM2IPROC)wglGetProcAddress("glUniform2i");
glUniform3i = (PFNGLUNIFORM3IPROC)wglGetProcAddress("glUniform3i");
glUniform4i = (PFNGLUNIFORM4IPROC)wglGetProcAddress("glUniform4i");
glActiveTexture = (PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture");
glDeleteShader = (PFNGLDELETESHADERPROC)wglGetProcAddress("glDeleteShader");
}
PFNGLCREATEPROGRAMPROC glCreateProgram;
PFNGLCREATESHADERPROC glCreateShader;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLCOMPILESHADERPROC glCompileShader;
PFNGLATTACHSHADERPROC glAttachShader;
PFNGLDETACHSHADERPROC glDetachShader;
PFNGLLINKPROGRAMPROC glLinkProgram;
PFNGLUSEPROGRAMPROC glUseProgram;
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture;
PFNGLDRAWBUFFERSPROC glDrawBuffers;
PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
PFNGLBINDBUFFERPROC glBindBuffer;
PFNGLBUFFERDATAPROC glBufferData;
PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays;
PFNGLGETSHADERIVPROC glGetShaderiv;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
PFNGLGETPROGRAMIVPROC glGetProgramiv;
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
PFNGLGENBUFFERSPROC glGenBuffers;
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
PFNGLUNIFORMMATRIX2FVPROC glUniformMatrix2fv;
PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fv;
PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv;
PFNGLUNIFORM1FPROC glUniform1f;
PFNGLUNIFORM2FPROC glUniform2f;
PFNGLUNIFORM3FPROC glUniform3f;
PFNGLUNIFORM4FPROC glUniform4f;
PFNGLUNIFORM1IPROC glUniform1i;
PFNGLUNIFORM2IPROC glUniform2i;
PFNGLUNIFORM3IPROC glUniform3i;
PFNGLUNIFORM4IPROC glUniform4i;
PFNGLACTIVETEXTUREPROC glActiveTexture;
PFNGLDELETESHADERPROC glDeleteShader;
};
static HGLRC hglrc_;
static GLFunc* gl_;
unsigned int points_;
unsigned int uvs_;
unsigned int indexes_;
unsigned int vao_;
unsigned int calibrationTexture_;
unsigned int vertexShader_;
unsigned int fragmentShader_;
unsigned int programID_;
struct Vector3
{
Vector3(float x, float y, float z)
: x_(x), y_(y), z_(z)
{
}
float x_;
float y_;
float z_;
};
struct Vector2
{
Vector2(float x, float y)
: x_(x), y_(y)
{
}
float x_;
float y_;
};
struct Texture
{
Texture(unsigned int width, unsigned int height)
: width_(width), height_(height)
{
bits_.insert(bits_.end(), width*height * 3, 0);
}
unsigned char* GetTexel(unsigned int x, unsigned int y)
{
return &bits_[((x * height_) + y)*3];
}
unsigned int width_;
unsigned int height_;
std::vector<unsigned char> bits_;
};
unsigned int CompileVertexShader(const std::string& sourceCode)
{
GLint result = GL_FALSE;
GLuint vertexShaderID = gl_->glCreateShader(GL_VERTEX_SHADER);
const char* src = sourceCode.c_str();
gl_->glShaderSource(vertexShaderID, 1, &src, NULL);
gl_->glCompileShader(vertexShaderID);
gl_->glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &result);
if (result == GL_FALSE)
{
int infoLogLength;
gl_->glGetShaderiv(vertexShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<GLchar> error(infoLogLength);
gl_->glGetShaderInfoLog(vertexShaderID, infoLogLength, &infoLogLength, &error[0]);
std::string errStr(&error[0], error.size());
OutputDebugString(errStr.c_str());
return 0;
}
return vertexShaderID;
}
unsigned int CompileFragmentShader(const std::string& sourceCode)
{
GLint result = GL_FALSE;
GLuint fragmentShaderID = gl_->glCreateShader(GL_FRAGMENT_SHADER);
const char* src = sourceCode.c_str();
gl_->glShaderSource(fragmentShaderID, 1, &src, NULL);
gl_->glCompileShader(fragmentShaderID);
gl_->glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &result);
if (result == GL_FALSE)
{
int infoLogLength;
gl_->glGetShaderiv(fragmentShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<GLchar> error(infoLogLength);
gl_->glGetShaderInfoLog(fragmentShaderID, infoLogLength, &infoLogLength, &error[0]);
std::string errStr(&error[0], error.size());
OutputDebugString(errStr.c_str());
return 0;
}
return fragmentShaderID;
}
unsigned int LinkShaderProgram(unsigned int vertexShader, unsigned int fragmentShader)
{
// attempt to link the program...
GLint result = GL_FALSE;
unsigned int programID = gl_->glCreateProgram();
gl_->glAttachShader(programID, vertexShader);
gl_->glAttachShader(programID, fragmentShader);
gl_->glLinkProgram(programID);
gl_->glGetProgramiv(programID, GL_LINK_STATUS, &result);
if (result == GL_FALSE)
{
int InfoLogLength;
gl_->glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<GLchar> error(InfoLogLength);
gl_->glGetProgramInfoLog(programID, InfoLogLength, &InfoLogLength, &error[0]);
std::string errStr(&error[0], error.size());
OutputDebugString(errStr.c_str());
return 0;
}
gl_->glDetachShader(programID, vertexShader);
gl_->glDetachShader(programID, fragmentShader);
return programID;
}
void SetUniform(const std::string& name, unsigned int ID)
{
int location = gl_->glGetUniformLocation(programID_, name.c_str());
if (location < 0)
OutputDebugString("Unable to find uniform location :(");
else
gl_->glUniform1i(location, ID);
}
std::shared_ptr<Texture> LoadTexture(const std::string& filename)
{
CImage image;
image.Load(filename.c_str());
std::shared_ptr<Texture> texture(new Texture(image.GetWidth(), image.GetHeight()));
for (int y = image.GetHeight() - 1; y >= 0; --y)
{
for (int x = 0; x < image.GetWidth(); ++x)
{
unsigned char* target = texture->GetTexel(x, y);
unsigned char* source = reinterpret_cast<unsigned char*>(image.GetPixelAddress(x, y));
for ( unsigned int c = 0; c < 3; ++c )
*(target+c) = *(source+c);
}
}
return texture;
}
}
extern "C" __declspec(dllexport) int OpenGLInit(void* hdc)
{
// We need to create a context or get an existing one that fits the supplied context.
// first check we have a valid device context
if (!hdc)
return 1;
HDC hDC = static_cast<HDC>(hdc);
if (!hDC)
return 2;
// we then need to get a valid DC...
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 32;
pfd.cStencilBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;
int nPixelFormat = ChoosePixelFormat(hDC, &pfd);
if (nPixelFormat == 0)
return 3;
if (!SetPixelFormat(hDC, nPixelFormat, &pfd))
return 4;
HGLRC tempContext = wglCreateContext(hDC);
wglMakeCurrent(hDC, tempContext);
int attribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
WGL_CONTEXT_FLAGS_ARB, 0,
0
};
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
if (wglCreateContextAttribsARB)
{
hglrc_ = wglCreateContextAttribsARB(hDC, 0, attribs);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(tempContext);
if (!wglMakeCurrent(hDC, hglrc_))
return 5;
}
// Initialise the functions..
gl_ = new GLFunc();
// Cache the geometry for a quad
float v = 1.0f;
std::vector<Vector3> quadPoints = std::initializer_list<Vector3>({
Vector3(-v, -v, 0),
Vector3(v, -v, 0),
Vector3(v, v, 0),
Vector3(-v, v, 0)
});
std::vector<Vector2> quadUVs = std::initializer_list<Vector2>({
Vector2(0, 0),
Vector2(1.0f, 0),
Vector2(1.0f, 1.0f),
Vector2(0, 1.0f)
});
std::vector<unsigned int> quadIndexes = std::initializer_list<unsigned int>({
0, 1, 2, 2, 3, 0
});
gl_->glGenVertexArrays(1, &vao_);
gl_->glBindVertexArray(vao_);
// Cache the points...
gl_->glGenBuffers(1, &points_);
gl_->glBindBuffer(GL_ARRAY_BUFFER, points_);
gl_->glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * quadPoints.size(), &quadPoints[0].x_, GL_STATIC_DRAW);
gl_->glEnableVertexAttribArray(0);
gl_->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
// Cache the UVs...
gl_->glGenBuffers(1, &uvs_);
gl_->glBindBuffer(GL_ARRAY_BUFFER, uvs_);
gl_->glBufferData(GL_ARRAY_BUFFER, sizeof(float) * quadUVs.size() * 2, &quadUVs[0].x_, GL_STATIC_DRAW);
gl_->glEnableVertexAttribArray(1);
gl_->glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
// Cache the indexes...
gl_->glGenBuffers(1, &indexes_);
gl_->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexes_);
gl_->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * quadIndexes.size(), &quadIndexes[0], GL_STATIC_DRAW);
gl_->glBindBuffer(GL_ARRAY_BUFFER, NULL);
gl_->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
gl_->glBindVertexArray(NULL);
// Load the texture...
std::shared_ptr<Texture> calibrationImage = LoadTexture("uvgrid.jpg");
glGenTextures(1, &calibrationTexture_);
glBindTexture(GL_TEXTURE_2D, calibrationTexture_);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, calibrationImage->width_, calibrationImage->height_, 0, GL_RGB, GL_UNSIGNED_BYTE, &calibrationImage->bits_[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, NULL);
// Compile the shaders
const char* fragmentSource = R"(
#version 410 core
uniform sampler2D quadTexture;
in vec2 UV;
out vec3 COLOUR;
void main()
{
//COLOUR = vec3(UV.st, 0);
COLOUR = texture(quadTexture, UV).bgr;
}
)";
const char* vertexSource = R"(
#version 410 core
in vec3 inP;
in vec2 inUV;
out vec2 UV;
void main()
{
gl_Position = vec4(inP, 1.0);
UV = inUV;
}
)";
vertexShader_ = CompileVertexShader(vertexSource);
fragmentShader_ = CompileFragmentShader(fragmentSource);
programID_ = LinkShaderProgram(vertexShader_, fragmentShader_);
return 0;
}
extern "C" __declspec(dllexport) void OpenGLKill()
{
wglDeleteContext(hglrc_);
}
extern "C" __declspec(dllexport) void OpenGLDraw(void* hdc, float rotation)
{
HDC validHDC = static_cast<HDC>(hdc);
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl_->glUseProgram(programID_);
gl_->glBindVertexArray(vao_);
gl_->glBindBuffer(GL_ARRAY_BUFFER, uvs_);
gl_->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexes_);
// Assign the texture...
gl_->glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, calibrationTexture_);
SetUniform("quadTexture", calibrationTexture_);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
gl_->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
gl_->glBindVertexArray(NULL);
gl_->glUseProgram(NULL);
SwapBuffers(validHDC);
}
extern "C" __declspec(dllexport) void OpenGLResize(int width, int height)
{
glViewport(0, 0, width, height);
//glMatrixMode(GL_PROJECTION);
//glLoadIdentity();
//glOrtho(width / static_cast<float>(height), -width / static_cast<float>(height), -1.0f, 1.0f, 0.1f, 100.0f);
}
包含 wpf 客户端的完整代码:https://github.com/spiroyster/wpfogl(分支“GL4”)。
如前所述,在绘制例程绑定(bind)纹理之前,我必须显式调用 gl_->glActiveTexture(GL_TEXTURE1)
,即使在此之前我从未设置过事件纹理单元(而且只有一个)在上下文中加载的纹理)。如果我删除该行,即事件纹理单元保留为 GL_TEXTURE0
,它不会显示纹理。
接下来是我加载的所有后续纹理...也就是说,如果它是我在此实例/上下文中加载的第二个纹理,则必须将事件纹理单元设置为说 GL_TEXTURE2
...即使我只使用所述纹理,也会发生这种情况。即,即使我只使用第二个纹理进行绘制(而不是第一个加载的纹理),我仍然必须明确地将事件纹理单元设置为 GL_TEXTURE2
。
最佳答案
必须为纹理采样器统一设置的值是纹理单元的索引,而不是纹理对象。
像这样更改您的代码:
gl_->glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, calibrationTexture_);
// this is wrong
//SetUniform("quadTexture", calibrationTexture_);
SetUniform( "quadTexture", 1 ); // 1 because of GL_TEXTURE1
参见 OpenGL 4.6 API Compatibility Profile Specification; 7.10 Samplers; page 154 :
Samplers are special uniforms used in the OpenGL Shading Language to identify the texture object used for each texture lookup. The value of a sampler indicates the texture image unit being accessed. Setting a sampler’s value to
i
selects texture image unit numberi
.
注意,纹理对象的“名称”由
glGenTextures(1, &calibrationTexture_);
此“名称”(整数)取决于硬件和驱动程序。
但是由于您的代码中只生成了 1 个纹理对象,因此名称的值很有可能是 1。
这意味着,当你设置
gl_->glActiveTexture(GL_TEXTURE1);
您的代码有效,因为 calibrationTexture_
的值为 1。
关于c++ - glActiveTexture 默认行为不符合预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49542557/
我们如何让 SwiftUI 对象,尤其是 Image,符合 Hashable 协议(protocol)? 我知道它们符合 Equatable 协议(protocol),所以主要问题是如何获取哈希值,或
我遇到了一些符合 AVAudioPlayerDelegate 的奇怪问题。以下正是我在一个全新的 Xcode 项目中所拥有的: import UIKit import AVFoundation cla
我一辈子都弄不明白为什么我会收到此类不符合 NSCoding 协议(protocol)的错误。也许另一双眼睛会有所帮助。我试图添加注释以明确每个函数在做什么。 import Foundation im
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
所有现代浏览器都理解 HTML,所以除了在键盘最右侧编写更多字符之外,兼容 XHTML 的意义何在。 最佳答案 没有一点我能想到的。 W3C 已经取消了 XHTML 2.0,尽管应该有一个 XHTML
我正在设计一个订单系统,状态设计模式似乎很合适,因为订单可以更改其状态,从而更改订单允许的功能。下面是我的基本类图: 我不喜欢这种方法,因为客户端无法查看某个方法是否受支持并且违反了里氏原则。我在下面
我正在考虑使用图形数据库来存储 IFC数据。理想情况下,数据库应该提供一种方法来定义 IFC 架构中定义的所有规则类型。但是,我不认为有任何这样的数据库,因为 IFC 中的某些规则类型非常复杂并且需要
我所在的组织必须满足 FISMA 对启用 FIPS 的系统的要求。我正在尝试做的一件事是为我们的密码实现哈希算法。我对此有很多选择:SHA-2、MD5、bcrypt(使用 Blowfish)、RIPE
我正在尝试实现我的自定义 CoreData Carpark 实体以符合 MKAnnotation,就像我们如何使 class 对象符合 >MKAnnotation. 我根据以下帖子调整了我的实现:th
我在 project-Swift.h 文件中收到名为“CBCentralManagerDelegate”的 No 类型或协议(protocol)。不知道我在这里哪里出错了。我认为这与 swift.h
我正在尝试读取之前写入 NVM 闪存的变量的值。 我的代码是: uintptr_t address = getAddress(); //[MISRA C++ Rule 5-2-8] cast from
所以我有这个练习要解决。我必须创建第一个。一个名为 Printable 的接口(interface),它有一个 put() 方法,该方法将接受实现 Comparable 的对象。 完成 interfa
我的问题涉及 IEEE 754 单精度数字。假设我有一个结构: typedef struct __ieee754 { int sign; int exponent; int mant
我需要使用 map,键为 uint32_t,值为 Meshes。我希望将网格布局在连续的内存中以 boost 性能,因为它们将经常被连续访问。 我想知道有哪些内存分配器库可以提供以下内容; 分配给连续
在处理小对象时,有哪些分配器可用于 STL。我已经尝试过使用 Boost 的池分配器,但没有得到任何性能提升(实际上,在某些情况下性能下降相当大)。 最佳答案 你没有说你使用的是什么编译器,但它可能带
我想做什么 我有一种划分事物的方法。此方法不会对数组进行完全排序;它只是简单地对数组进行分区,以便一侧的所有元素(某些预先确定的“中心”或“中点值”——但它不必导致均匀拆分)小于“中心”和另一侧的所有
假设我需要开发一个 REST 银行应用程序允许创建/销毁银行账户以及对帐户进行以下操作:withdraw/credit/getBalance。 创建帐户 PUT/银行/约翰 这里我使用 PUT 而不是
假设我有一个 struct 符合我的模型的 Equatable,如下所示: struct Model: Equatable { var a: Int = 0 var b: String
我目前正在研究 Decodable、Encodable 和 friend ,试图理解它背后的“魔法”。 以下是我发现不寻常的一件事: class Person: Decodable { var n
在 Swift 书中,枚举的例子很好用 enum CompassPoint: String { case north, south, east, west } var northCom = C
我是一名优秀的程序员,十分优秀!