void Plane::Define(const Vector3& v0, const Vector3& v1, const Vector3& v2) { CHECK_ASSERT(NSG::Distance(v0, v1) > 0.0001f); CHECK_ASSERT(NSG::Distance(v0, v2) > 0.0001f); Vector3 dist1 = v1 - v0; Vector3 dist2 = v2 - v0; Define(Normalize(Cross(dist1, dist2)), v1); }
int main(void) { unsigned long value = 0xffffffffffffffff; char *ptr = console_buffer; debug_descriptor.console_log_levels = 0x75; /* Test for huge TB value. */ huge_tb = 1; prlog(PR_EMERG, "Hello World"); CHECK_ASSERT("[1223372515963611388,0] Hello World"); memset(console_buffer, 0, sizeof(console_buffer)); /* Test for normal TB with huge unsigned long value */ huge_tb = 0; prlog(PR_EMERG, "Hello World %lu", value); CHECK_ASSERT("[42,0] Hello World 18446744073709551615"); printf("Hello World %lu", value); CHECK_ASSERT("[42,5] Hello World 18446744073709551615"); /* * Test string of size > 320 * * core/console-log.c:vprlog() uses buffer[320] to print message * Try printing more than 320 bytes to test stack corruption. * You would see Segmentation fault on stack corruption. */ prlog(PR_EMERG, "%330s", "Hello World"); memset(console_buffer, 0, sizeof(console_buffer)); /* * Test boundary condition. * * Print string of exact size 320. We should see string truncated * with console_buffer[319] == '\0'. */ memset(console_buffer, 0, sizeof(console_buffer)); prlog(PR_EMERG, "%313s", "Hello World"); assert(console_buffer[319] == 0); /* compare truncated string */ ptr += 320 - strlen("Hello World"); CHECK_BUF_ASSERT(ptr, "Hello Worl"); return 0; }
void ResourceFile::AllocateResources() { if (!get_) { #if defined(EMSCRIPTEN) { auto filename = path_.GetFilePath(); std::ifstream file(filename.c_str(), std::ios::binary); if (file.is_open()) { file.seekg(0, std::ios::end); std::streampos filelength = file.tellg(); file.seekg(0, std::ios::beg); buffer_.resize((int)filelength); file.read(&buffer_[0], filelength); CHECK_ASSERT(file.gcount() == filelength); file.close(); LOGI("%s has been loaded with size=%d", filename.c_str(), buffer_.size()); } else { LOGE("Cannot load %s", filename.c_str()); } } #else { CHECK_ASSERT(isLocal_); auto filename = path_.GetFilePath(); SDL_RWops* context = SDL_RWFromFile(filename.c_str(), "rb"); if (context) { SDL_RWseek(context, 0, RW_SEEK_END); Sint64 filelength = SDL_RWtell(context); SDL_RWseek(context, 0, RW_SEEK_SET); buffer_.resize((int)filelength); SDL_RWread(context, &buffer_[0], buffer_.size(), 1); SDL_RWclose(context); LOGI("%s has been loaded with size=%u", filename.c_str(), (unsigned)buffer_.size()); } else { LOGE("Cannot load %s with error %s", filename.c_str(), SDL_GetError()); } } #endif } if (path_.GetExtension() == "lz4") buffer_ = DecompressBuffer(buffer_); }
void Graphics::SetInstanceAttrPointers(Program* program) { if (!HasInstancedArrays()) return; CHECK_ASSERT(program->GetMaterial()->IsBatched()); CHECK_GL_STATUS(); SetVertexBuffer(program->GetMaterial()->GetInstanceBuffer().get()); GLuint modelMatrixLoc = program->GetAttModelMatrixLoc(); if (modelMatrixLoc != -1) { for (int i = 0; i < 3; i++) { glEnableVertexAttribArray(modelMatrixLoc + i); glVertexAttribPointer(modelMatrixLoc + i, 4, GL_FLOAT, GL_FALSE, sizeof(InstanceData), reinterpret_cast<void*>(offsetof(InstanceData, modelMatrixRow0_) + sizeof(float) * 4 * i)); glVertexAttribDivisor(modelMatrixLoc + i, 1); } } else { glDisableVertexAttribArray((int)AttributesLoc::MODEL_MATRIX_ROW0); glDisableVertexAttribArray((int)AttributesLoc::MODEL_MATRIX_ROW1); glDisableVertexAttribArray((int)AttributesLoc::MODEL_MATRIX_ROW2); } GLuint normalMatrixLoc = program->GetAttNormalMatrixLoc(); if (normalMatrixLoc != -1) { for (int i = 0; i < 3; i++) { glEnableVertexAttribArray(normalMatrixLoc + i); glVertexAttribPointer(normalMatrixLoc + i, 3, GL_FLOAT, GL_FALSE, sizeof(InstanceData), reinterpret_cast<void*>(offsetof(InstanceData, normalMatrixCol0_) + sizeof(float) * 3 * i)); glVertexAttribDivisor(normalMatrixLoc + i, 1); } } else { glDisableVertexAttribArray((int)AttributesLoc::NORMAL_MATRIX_COL0); glDisableVertexAttribArray((int)AttributesLoc::NORMAL_MATRIX_COL1); glDisableVertexAttribArray((int)AttributesLoc::NORMAL_MATRIX_COL2); } CHECK_GL_STATUS(); }
void Node::AddChild(PNode node) { CHECK_ASSERT(node && node.get() != this); children_.push_back(node); childrenHash_.insert(std::make_pair(node->name_, node)); PNode thisNode = SharedFromPointerNode(this); node->parent_ = thisNode; PScene scene = scene_.lock(); if (!scene) scene = std::dynamic_pointer_cast<Scene>(thisNode); node->scene_ = scene; if (scene) { PLight light = std::dynamic_pointer_cast<Light>(node); if (light) scene->AddLight(light.get()); else { PCamera camera = std::dynamic_pointer_cast<Camera>(node); if (camera) scene->AddCamera(camera.get()); else { auto ps = std::dynamic_pointer_cast<ParticleSystem>(node); if (ps) scene->AddParticleSystem(ps.get()); } } } node->MarkAsDirty(); }
void Graphics::SetBlendModeTest(BLEND_MODE blendMode) { static BLEND_MODE blendMode_ = DEFAULT_BLEND_MODE; static GLenum blendSFactor_ = DEFAULT_BLEND_SFACTOR; static GLenum blendDFactor_ = DEFAULT_BLEND_DFACTOR; if (blendMode != blendMode_) { switch (blendMode) { case BLEND_MODE::NONE: glDisable(GL_BLEND); if (blendSFactor_ != GL_ONE || blendDFactor_ != GL_ZERO) { glBlendFunc(GL_ONE, GL_ZERO); blendSFactor_ = GL_ONE; blendDFactor_ = GL_ZERO; } break; case BLEND_MODE::MULTIPLICATIVE: glEnable(GL_BLEND); if (blendSFactor_ != GL_ZERO || blendDFactor_ != GL_SRC_COLOR) { glBlendFunc(GL_ZERO, GL_SRC_COLOR); blendSFactor_ = GL_ZERO; blendDFactor_ = GL_SRC_COLOR; } break; case BLEND_MODE::ADDITIVE: glEnable(GL_BLEND); if (blendSFactor_ != GL_ONE || blendDFactor_ != GL_ONE) { glBlendFunc(GL_ONE, GL_ONE); blendSFactor_ = GL_ONE; blendDFactor_ = GL_ONE; } break; case BLEND_MODE::ALPHA: glEnable(GL_BLEND); if (blendSFactor_ != GL_SRC_ALPHA || blendDFactor_ != GL_ONE_MINUS_SRC_ALPHA) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); blendSFactor_ = GL_SRC_ALPHA; blendDFactor_ = GL_ONE_MINUS_SRC_ALPHA; } break; default: CHECK_ASSERT(false && "Undefined blend mode"); break; } blendMode_ = blendMode; } }
void Camera::SetAspectRatio(float aspect) { CHECK_ASSERT(aspect != 0); if (aspectRatio_ != aspect) { aspectRatio_ = aspect; isDirty_ = true; SetUniformsNeedUpdate(); } }
void Camera::SetHalfHorizontalFov(float hhfov) { CHECK_ASSERT(hhfov != 0); float fovy = hhfov / aspectRatio_; if (fovy_ != fovy) { fovy_ = fovy; isDirty_ = true; SetUniformsNeedUpdate(); } }
void PointOnSphere::CalculateUpVector() { // Apply spherical coordinates Vertex3 currentPoint(cos(theta_) * sin(phi_), cos(phi_), sin(theta_) * sin(phi_)); CHECK_ASSERT(Distance(center_ + radius_ * currentPoint, point_) < 9*PRECISION); // Reduce phi slightly to obtain another point on the same longitude line on the sphere. const float dt = 1; Vertex3 newUpPoint(cos(theta_) * sin(phi_ - dt), cos(phi_ - dt), sin(theta_) * sin(phi_ - dt)); up_ = Normalize(newUpPoint - currentPoint); }
// // Copyright (c) 2008-2014 the Urho3D project. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN unsigned UTF8String::NextUTF8Char(unsigned& byteOffset) const { const char* buffer = c_str(); if (!buffer) return 0; const char* src = buffer + byteOffset; unsigned ret = DecodeUTF8(src); auto bytesDiff = src - buffer; CHECK_ASSERT(bytesDiff < std::numeric_limits<unsigned>::max()); byteOffset = (unsigned)(src - buffer); return ret; }
void Buffer::SetBufferSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) { CHECK_ASSERT(offset + size <= bufferSize_); #if !defined(ANDROID) && !defined(EMSCRIPTEN) if (Graphics::GetPtr()->HasMapBufferRange()) { void* old_data = glMapBufferRange(type_, offset, size, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_UNSYNCHRONIZED_BIT); CHECK_ASSERT(old_data); memcpy(old_data, data, size); glFlushMappedBufferRange(type_, offset, size); CHECK_CONDITION(glUnmapBuffer(type_)); } else #endif { glBufferSubData(type_, offset, size, data); } }
void Node::Load(const pugi::xml_node& node) { CHECK_ASSERT(name_ == node.attribute("name").as_string()); Vertex3 position(VECTOR3_ZERO); auto posAtt = node.attribute("position"); if (posAtt) position = ToVertex3(posAtt.as_string()); SetPosition(position); Quaternion orientation(QUATERNION_IDENTITY); auto rotAtt = node.attribute("orientation"); if (rotAtt) orientation = ToQuaternion(rotAtt.as_string()); SetOrientation(orientation); Vertex3 scale(VECTOR3_ONE); auto scaAtt = node.attribute("scale"); if (scaAtt) scale = ToVertex3(scaAtt.as_string()); SetScale(scale); }
void Camera::UpdateProjection() const { if (isOrtho_) { if (!hasUserOrthoProjection_) orthoProjection_ = CalculateOrthoProjection(zNear_, zFar_); matProjection_ = Ortho(orthoProjection_.left_, orthoProjection_.right_, orthoProjection_.bottom_, orthoProjection_.top_, orthoProjection_.near_, orthoProjection_.far_); } else { CHECK_ASSERT(zNear_ > 0); matProjection_ = Perspective(fovy_, aspectRatio_, zNear_, zFar_); } SetUniformsNeedUpdate(); }
void Octree::InsertUpdate(SceneNode* obj) { Octant* octant = obj->GetOctant(); const BoundingBox& box = obj->GetWorldBoundingBox(); // Skip if still fits the current octant if (octant && octant->GetCullingBox().IsInside(box) == Intersection::INSIDE && octant->CheckFit(box)) return; Insert(obj); // Verify that the obj will be culled correctly CHECK_ASSERT(obj->GetOctant() == this || obj->GetOctant()->GetCullingBox().IsInside(box) == Intersection::INSIDE); if (allDrawablesSet_.end() == allDrawablesSet_.find(obj)) { allDrawablesSet_.insert(obj); allDrawables_.push_back(obj); } }
void Graphics::SetCullFace(CullFaceMode mode) { if (mode != cullFaceMode_) { cullFaceMode_ = mode; switch (mode) { case CullFaceMode::BACK: glCullFace(GL_BACK); break; case CullFaceMode::FRONT: glCullFace(GL_FRONT); break; case CullFaceMode::FRONT_AND_BACK: glCullFace(GL_FRONT_AND_BACK); break; default: CHECK_ASSERT(!"Unknown CullFaceMode!!!"); break; } } }
PFrustum Camera::GetFrustumSplit(float nearSplit, float farSplit) const { Update(); Matrix4 matProjection; if (isOrtho_) { OrthoProjection orthoProjection = CalculateOrthoProjection(nearSplit, farSplit); matProjection = Ortho(orthoProjection.left_, orthoProjection.right_, orthoProjection.bottom_, orthoProjection.top_, orthoProjection.near_, orthoProjection.far_); } else { CHECK_ASSERT(nearSplit > 0); matProjection = Perspective(fovy_, aspectRatio_, nearSplit, farSplit); } return std::make_shared<Frustum>(matProjection * matView_); }
void Graphics::SetDepthFunc(DepthFunc depthFunc) { if (depthFunc_ != depthFunc) { switch (depthFunc) { case DepthFunc::NEVER: glDepthFunc(GL_NEVER); break; case DepthFunc::LESS: glDepthFunc(GL_LESS); break; case DepthFunc::EQUAL: glDepthFunc(GL_EQUAL); break; case DepthFunc::LEQUAL: glDepthFunc(GL_LEQUAL); break; case DepthFunc::GREATER: glDepthFunc(GL_GREATER); break; case DepthFunc::NOTEQUAL: glDepthFunc(GL_NOTEQUAL); break; case DepthFunc::GEQUAL: glDepthFunc(GL_GEQUAL); break; case DepthFunc::ALWAYS: glDepthFunc(GL_ALWAYS); break; default: CHECK_ASSERT(false && "Invalid depth function"); break; } } }
bool ResourceFile::IsValid() { if (!get_ && !isLocal_) { if (path_.IsPathRelative()) { #if defined(EMSCRIPTEN) std::string url = emscripten_run_script_string("window.location.href"); #else std::string url; //@@@ TO DO CHECK_ASSERT(false); #endif auto filename = path_.GetFilePath(); get_ = std::make_shared<HTTPRequest>(Path(url).GetPath() + "/" + filename, onLoad_, onError_, onProgress_); } else { get_ = std::make_shared<HTTPRequest>(path_.GetFullAbsoluteFilePath(), onLoad_, onError_, onProgress_); } get_->StartRequest(); } return isLocal_; }
void Octant::DeleteChild(unsigned index) { CHECK_ASSERT(index < NUM_OCTANTS); delete children_[index]; children_[index] = nullptr; }
Texture* D3DRenderFactory::MakeTexture2D(void* TextureData) { CHECK_ASSERT(TextureData != nullptr); ID3D11Texture2D* ptr = static_cast<ID3D11Texture2D*>(TextureData); return new D3DTexture2D(ptr); }
void MaterialPointParticle::Reset() { CHECK_ASSERT(false); }
int main (int argc, char **argv) { GpImage *img; gunichar2 *unis; GpBitmap *bitmap; GpStatus status; int original_palette_size; int reloaded_palette_size; ColorPalette *original_palette; ColorPalette *reloaded_palette; GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; PixelFormat pixel_format; ARGB color; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); // PNG resave should preserve the palette transparency. Let's test it // by loading a PNG file and its palette, then resaving it and loading // it again for comparison. unis = g_utf8_to_utf16 ("test-trns.png", -1, NULL, NULL, NULL); status = GdipLoadImageFromFile (unis, &img); CHECK_STATUS(1); g_free (unis); status = GdipGetImagePaletteSize (img, &original_palette_size); CHECK_STATUS(1); CHECK_ASSERT(original_palette_size > 0); original_palette = malloc (original_palette_size); GdipGetImagePalette (img, original_palette, original_palette_size); CHECK_STATUS(1); unis = g_utf8_to_utf16 ("test-trns-resave.png", -1, NULL, NULL, NULL); status = GdipSaveImageToFile (img, unis, &png_clsid, NULL); CHECK_STATUS(1); GdipDisposeImage (img); status = GdipLoadImageFromFile (unis, &img); CHECK_STATUS(1); g_free (unis); status = GdipGetImagePaletteSize (img, &reloaded_palette_size); CHECK_STATUS(1); CHECK_ASSERT(reloaded_palette_size > 0); CHECK_ASSERT(reloaded_palette_size == original_palette_size); reloaded_palette = malloc (reloaded_palette_size); GdipGetImagePalette (img, reloaded_palette, reloaded_palette_size); CHECK_STATUS(1); CHECK_ASSERT(memcmp (original_palette, reloaded_palette, original_palette_size) == 0); GdipDisposeImage (img); img = NULL; unlink ("test-trns-resave.png"); free (original_palette); free (reloaded_palette); // Test grayscale image with alpha channel. The image should be converted // into 32-bit ARGB format and the alpha channel should be preserved. unis = g_utf8_to_utf16 ("test-gsa.png", -1, NULL, NULL, NULL); status = GdipCreateBitmapFromFile (unis, &bitmap); CHECK_STATUS(1); g_free (unis); status = GdipGetImagePixelFormat (bitmap, &pixel_format); CHECK_STATUS(1); CHECK_ASSERT(pixel_format == PixelFormat32bppARGB); status = GdipBitmapGetPixel (bitmap, 0, 0, &color); CHECK_STATUS(1); CHECK_ASSERT(color == 0xffffff); status = GdipBitmapGetPixel (bitmap, 1, 7, &color); CHECK_STATUS(1); CHECK_ASSERT(color == 0xe8b3b3b3); GdipDisposeImage (bitmap); return 0; }
void ShaderObject::LoadBinaryFile(std::string file_name) { CHECK_ASSERT(false); }
void MaterialPointParticle::ComputeEnergyDensity() { //------------------------ /*float Je = Math::determinant(this->Fe); float Jp = Math::determinant(this->Fp); float harden = Math::Pow(Math::E, EPSILON*(1 - Jp)); float2x2 U; float2 D; float2x2 Vt; Math::GetSVD2D(Fe, U, D, Vt); float2x2 temp = (this->Fe - (U * Math::Transpose(Vt))) * 2 * MU * Math::Transpose(this->Fe); float D_lambdaFp = LAMBDA * Jp * (1 - Jp); float2x2 lambda_mat; lambda_mat[0][0] = D_lambdaFp; lambda_mat[1][1] = D_lambdaFp; temp = temp + lambda_mat; this->force_ = temp * -volume_ * harden; */ //----------------------------------------- float Je = Math::determinant(this->Fe); float Jp = Math::determinant(this->Fp); //CHECK_ASSERT(Math::IsNAN(Jp) == false); if (Math::IsNAN(Jp)) { PRINT_WARNING("NAN Jp"); Jp = 1; } // if (Jp == 0) Jp = 1; // if (Math::IsINF(Jp)) // { // Math::Identity(this->Fp); // Jp = 1; // } float ClampedJpParameter = Math::Clamp(EPSILON*(1 - Jp), -5.0f, 5.0f); float muFp = MU * Math::Pow(Math::E, ClampedJpParameter); float lambdaFp = LAMBDA * Math::Pow(Math::E, ClampedJpParameter); //if (Math::IsINF(muFp)) muFp = std::numeric_limits<float>::max(); //if (Math::IsINF(lambdaFp)) lambdaFp = std::numeric_limits<float>::max(); CHECK_ASSERT(Math::IsINF(muFp) == false); CHECK_ASSERT(Math::IsINF(lambdaFp) == false); /*float2x2 U; float2 D; float2x2 Vt; Math::GetSVD2D(Fe, U, D, Vt); CHECK_ASSERT(Math::Abs(Math::determinant(D) - Je) < 1e-5f);*/ float2x2 R;// = Math::Multiply(U, Vt); float2x2 S; Math::GetPolarDecomposition2D(Fe, R, S); //PRINT_VAR(R); float2x2 temp = 2 * muFp * (Fe - R) * Math::Transpose(Fe); //PRINT_VAR(temp); float2x2 lambda_mat; lambda_mat[0][0] = lambdaFp * (Je - 1) * Je; lambda_mat[1][1] = lambdaFp * (Je - 1) * Je; //PRINT_VAR(lambda_mat); temp = temp + lambda_mat; this->force_ = temp * (-this->volume_); //PRINT_VAR(force_); CHECK_ASSERT(Math::IsNAN(force_[0][0]) == false); CHECK_ASSERT(Math::IsNAN(force_[0][1]) == false); CHECK_ASSERT(Math::IsNAN(force_[1][0]) == false); CHECK_ASSERT(Math::IsNAN(force_[1][1]) == false); //equation: //P(F) = Y(F)/dF = ( 2 * mu * (Fe - R ) * FeT + (lambda * (Je - 1) * Je) ) * -V }
virtual void RunTest (TestResult& result_) { CHECK_ASSERT( MyFunction() ); }